From 9e332eb5efc1e53bb935df9060f55340fc53f57f Mon Sep 17 00:00:00 2001 From: Philippe Houdoin Date: Thu, 29 Jul 2010 14:33:22 +0000 Subject: [PATCH] Add a quick and dirty GLUT game mode testbed git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37808 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/tests/kits/opengl/Jamfile | 1 + src/tests/kits/opengl/glut/Jamfile | 3 + src/tests/kits/opengl/glut/game_mode/Jamfile | 15 ++ .../kits/opengl/glut/game_mode/game_mode.c | 148 ++++++++++++++++++ 4 files changed, 167 insertions(+) create mode 100644 src/tests/kits/opengl/glut/Jamfile create mode 100644 src/tests/kits/opengl/glut/game_mode/Jamfile create mode 100644 src/tests/kits/opengl/glut/game_mode/game_mode.c diff --git a/src/tests/kits/opengl/Jamfile b/src/tests/kits/opengl/Jamfile index 3a70808ad9..035c8feede 100644 --- a/src/tests/kits/opengl/Jamfile +++ b/src/tests/kits/opengl/Jamfile @@ -2,3 +2,4 @@ SubDir HAIKU_TOP src tests kits opengl ; SubInclude HAIKU_TOP src tests kits opengl direct_mode ; SubInclude HAIKU_TOP src tests kits opengl demos ; +SubInclude HAIKU_TOP src tests kits opengl glut ; diff --git a/src/tests/kits/opengl/glut/Jamfile b/src/tests/kits/opengl/glut/Jamfile new file mode 100644 index 0000000000..d60ee56ec2 --- /dev/null +++ b/src/tests/kits/opengl/glut/Jamfile @@ -0,0 +1,3 @@ +SubDir HAIKU_TOP src tests kits opengl glut ; + +SubInclude HAIKU_TOP src tests kits opengl glut game_mode ; diff --git a/src/tests/kits/opengl/glut/game_mode/Jamfile b/src/tests/kits/opengl/glut/game_mode/Jamfile new file mode 100644 index 0000000000..799f4fef72 --- /dev/null +++ b/src/tests/kits/opengl/glut/game_mode/Jamfile @@ -0,0 +1,15 @@ +SubDir HAIKU_TOP src tests kits opengl glut game_mode ; + +SetSubDirSupportedPlatformsBeOSCompatible ; + +if $(TARGET_PLATFORM) != haiku { + # Needed for , not present in R5. + # Unfortunately we also get the other headers there, + # that we don't really want. + UsePublicHeaders opengl ; +} + +SimpleTest GLUTGameMode : + game_mode.c + : be libGL.so $(TARGET_LIBSUPC++) +; diff --git a/src/tests/kits/opengl/glut/game_mode/game_mode.c b/src/tests/kits/opengl/glut/game_mode/game_mode.c new file mode 100644 index 0000000000..8c4c1168cf --- /dev/null +++ b/src/tests/kits/opengl/glut/game_mode/game_mode.c @@ -0,0 +1,148 @@ + +#include +#include + +float spin = 0; + +static void +draw_cube(void) +{ + glLoadIdentity(); + + /* A step backward, then spin the cube */ + glTranslatef(0, 0, -5); + glRotatef(spin, 0, 0, 1); + glRotatef(spin, 1, 0.6, 0); + + /* We tell we want to draw quads */ + glBegin (GL_QUADS); + + /* Every four calls to glVertex, a quad is drawn */ + glColor3f(0, 0, 0); glVertex3f(-1, -1, -1); + glColor3f(0, 0, 1); glVertex3f(-1, -1, 1); + glColor3f(0, 1, 1); glVertex3f(-1, 1, 1); + glColor3f(0, 1, 0); glVertex3f(-1, 1, -1); + + glColor3f(1, 0, 0); glVertex3f( 1, -1, -1); + glColor3f(1, 0, 1); glVertex3f( 1, -1, 1); + glColor3f(1, 1, 1); glVertex3f( 1, 1, 1); + glColor3f(1, 1, 0); glVertex3f( 1, 1, -1); + + glColor3f(0, 0, 0); glVertex3f(-1, -1, -1); + glColor3f(0, 0, 1); glVertex3f(-1, -1, 1); + glColor3f(1, 0, 1); glVertex3f( 1, -1, 1); + glColor3f(1, 0, 0); glVertex3f( 1, -1, -1); + + glColor3f(0, 1, 0); glVertex3f(-1, 1, -1); + glColor3f(0, 1, 1); glVertex3f(-1, 1, 1); + glColor3f(1, 1, 1); glVertex3f( 1, 1, 1); + glColor3f(1, 1, 0); glVertex3f( 1, 1, -1); + + glColor3f(0, 0, 0); glVertex3f(-1, -1, -1); + glColor3f(0, 1, 0); glVertex3f(-1, 1, -1); + glColor3f(1, 1, 0); glVertex3f( 1, 1, -1); + glColor3f(1, 0, 0); glVertex3f( 1, -1, -1); + + glColor3f(0, 0, 1); glVertex3f(-1, -1, 1); + glColor3f(0, 1, 1); glVertex3f(-1, 1, 1); + glColor3f(1, 1, 1); glVertex3f( 1, 1, 1); + glColor3f(1, 0, 1); glVertex3f( 1, -1, 1); + + glEnd(); +} + + +static void +display(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + draw_cube(); + + glutSwapBuffers(); +} + + +static void +idle(void) +{ + spin += 2.0; + if (spin > 360.0) + spin = 0.0; + + glutPostRedisplay(); +} + + +static void +reshape(int w, int h) +{ + glViewport (0, 0, (GLsizei) w, (GLsizei) h); + // Setup the view of the cube. + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective( /* field of view in degree */ 40.0, + /* aspect ratio */ 1.0, + /* Z near */ 1.0, /* Z far */ 10.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + gluLookAt(0.0, 0.0, 5.0, // eye is at (0,0,5) + 0.0, 0.0, 0.0, // center is at (0,0,0) + 0.0, 1.0, 0.); // up is in positive Y direction + + // Adjust cube position to be asthetic angle. + glTranslatef(0.0, 0.0, -1.0); + glRotatef(60, 1.0, 0.0, 0.0); + glRotatef(-20, 0.0, 0.0, 1.0); +} + + +static void +init(void) +{ + glutIdleFunc(idle); + glutDisplayFunc(display); + glutReshapeFunc(reshape); + + glClearColor(0, 0, 0, 0); +} + + +int +main(int argc, char **argv) +{ + glutInit(&argc, argv); + + if (argc > 1) { + printf("glutGameModeString(\"%s\"): ", argv[1]); + + glutGameModeString(argv[1]); + + if (!glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) + printf("*not* possible: fallback to windowed mode.\n"); + else { + printf("possible!\nglutEnterGameMode()\n"); + glutEnterGameMode(); + + printf("glutGameModeGet(GLUT_GAME_MODE_DISPLAY_CHANGED) = %d\n", + glutGameModeGet(GLUT_GAME_MODE_DISPLAY_CHANGED)); + } + } + + if (!glutGameModeGet(GLUT_GAME_MODE_ACTIVE)) { + glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); + glutCreateWindow(argv[0]); + } + + init(); + + + glutMainLoop(); + + if (glutGameModeGet(GLUT_GAME_MODE_ACTIVE)) { + printf("glutLeaveGameMode()\n"); + glutLeaveGameMode(); + } + + return 0; +}