X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=progs%2Fdemos%2FOne%2Fone.c;h=24ce7a7f5c57e15ee89ad255cfbb215a96df8c54;hb=9ee80026494495ca338aa5b0658e48ec2c3a6811;hp=93e51447030ea62fb548a26a69b3311154e11dd6;hpb=0a2aab2b7a6b7551c718922876d89db1c23520e0;p=freeglut diff --git a/progs/demos/One/one.c b/progs/demos/One/one.c index 93e5144..24ce7a7 100644 --- a/progs/demos/One/one.c +++ b/progs/demos/One/one.c @@ -12,17 +12,14 @@ * Creation date: czw gru 2 11:58:41 CET 1999 */ -#ifdef HAVE_CONFIG_H -#include -#endif - #include #include #include int g_LeaveGameMode = 0; -int g_InGameMode = 1; +int g_InGameMode = 0; +int g_mainwin1, g_mainwin2, g_sw1, g_sw2, g_gamemodewin; /* * Call this function to have some text drawn at given coordinates @@ -93,54 +90,86 @@ void PrintText( int nX, int nY, char* pszText ) /* * This is the display routine for our sample FreeGLUT windows */ -static float g_fTime = 0.0f; - void SampleDisplay( void ) { - /* - * Clear the screen - */ - glClearColor( 0, 0.5, 1, 1 ); - glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); - - /* - * Have the cube rotated - */ - glMatrixMode( GL_MODELVIEW ); - glPushMatrix(); + int win = glutGetWindow(); - glRotatef( g_fTime, 0, 0, 1 ); - glRotatef( g_fTime, 0, 1, 0 ); - glRotatef( g_fTime, 1, 0, 0 ); - - /* - * And then drawn... - */ - glColor3f( 1, 1, 0 ); - //glutWireCube( 20.0 ); - glutWireTeapot( 20.0 ); - //glutWireSpher( 15.0, 15, 15 ); - //glColor3f( 0, 1, 0 ); - //glutWireCube( 30.0 ); - //glutSolidCone( 10, 20, 10, 2 ); - - /* - * Don't forget about the model-view matrix - */ - glPopMatrix( ); + if (g_InGameMode && win!=g_gamemodewin) + /* Don't draw other windows when in gamemode, those aren't visible + * anyway. Drawing them continuously nonetheless can cause flicker trouble + * on my machine. This only seems to occur only when there are child windows + * among the non-visible windows + */ + return; - /* - * Draw a silly text - */ - if( g_InGameMode == 0 ) - PrintText( 20, 20, "Hello there cruel world!" ); + if (win==g_sw1) + { + /* + * Clear the screen + */ + glClearColor(0.7f,0.7f,0.7f,1); + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + glutPostWindowRedisplay(g_mainwin2); + } + else if (win==g_sw2) + { + /* + * Clear the screen + */ + glClearColor(0.3f,0.3f,0.3f,1); + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + glutPostWindowRedisplay(g_mainwin2); + } else - PrintText( 20, 20, "Press ESC to leave the game mode!" ); + { + const GLfloat time = glutGet(GLUT_ELAPSED_TIME) / 1000.f * 40; + + /* + * Clear the screen + */ + glClearColor( 0, 0.5, 1, 1 ); + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + /* + * Have the cube rotated + */ + glMatrixMode( GL_MODELVIEW ); + glPushMatrix(); + + glRotatef( time, 0, 0, 1 ); + glRotatef( time, 0, 1, 0 ); + glRotatef( time, 1, 0, 0 ); + + /* + * And then drawn... + */ + glColor3f( 1, 1, 0 ); + /* glutWireCube( 20.0 ); */ + glutWireTeapot( 20.0 ); + /* glutWireSphere( 15.0, 15, 15 ); */ + /* glColor3f( 0, 1, 0 ); */ + /* glutWireCube( 30.0 ); */ + /* glutSolidCone( 10, 20, 10, 2 ); */ + + /* + * Don't forget about the model-view matrix + */ + glPopMatrix( ); + + /* + * Draw a silly text + */ + if( g_InGameMode == 0 ) + PrintText( 20, 20, "Hello there cruel world!" ); + else + PrintText( 20, 20, "Press ESC to leave the game mode!" ); + } /* * And swap this context's buffers */ glutSwapBuffers( ); + glutPostWindowRedisplay(win); } /* @@ -148,16 +177,26 @@ void SampleDisplay( void ) */ void SampleIdle( void ) { - g_fTime += 0.5f; - if( g_LeaveGameMode == 1 ) { + /* One could do all this just as well in SampleGameModeKeyboard... */ + printf("leaving gamemode...\n"); glutLeaveGameMode( ); g_LeaveGameMode = 0; g_InGameMode = 0; + glutPostWindowRedisplay(g_mainwin1); + glutPostWindowRedisplay(g_mainwin2); + glutPostWindowRedisplay(g_sw1); + glutPostWindowRedisplay(g_sw2); } } +void SampleEntry(int state) +{ + int window = glutGetWindow () ; + printf ( "Window %d Entry Callback: %d\n", window, state ) ; +} + /* * The reshape function */ @@ -239,13 +278,18 @@ void SampleSpecial( int nSpecial, int nMouseX, int nMouseY ) */ void SampleMenu( int menuID ) { - /* - * Just print something funny - */ printf( "SampleMenu() callback executed, menuID is %i\n", menuID ); } /* + * A sample menu status callback + */ +void SampleMenuStatus( int status, int x, int y ) +{ + printf ( "SampleMenu() callback executed, MenuStatus is %i at (%i,%i)\n", status, x, y ); +} + +/* * The sample's entry point */ int main( int argc, char** argv ) @@ -258,6 +302,10 @@ int main( int argc, char** argv ) glutInit( &argc, argv ); + glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,GLUT_ACTION_GLUTMAINLOOP_RETURNS); + glutMenuStatusFunc( SampleMenuStatus ); + glutIdleFunc( SampleIdle ); + subMenuA = glutCreateMenu( SampleMenu ); glutAddMenuEntry( "Sub menu A1 (01)", 1 ); glutAddMenuEntry( "Sub menu A2 (02)", 2 ); @@ -278,22 +326,34 @@ int main( int argc, char** argv ) glutAddSubMenu( "Enter sub menu A", subMenuA ); glutAddSubMenu( "Enter sub menu B", subMenuB ); - glutCreateWindow( "Hello world!" ); + g_mainwin1 = glutCreateWindow( "Hello world!" ); glutDisplayFunc( SampleDisplay ); glutReshapeFunc( SampleReshape ); glutKeyboardFunc( SampleKeyboard ); glutSpecialFunc( SampleSpecial ); - glutIdleFunc( SampleIdle ); + glutEntryFunc( SampleEntry ); glutAttachMenu( GLUT_LEFT_BUTTON ); glutInitWindowPosition( 200, 200 ); - glutCreateWindow( "I am not Jan B." ); + g_mainwin2 = glutCreateWindow( "I am not Jan B." ); glutDisplayFunc( SampleDisplay ); glutReshapeFunc( SampleReshape ); glutKeyboardFunc( SampleKeyboard ); glutSpecialFunc( SampleSpecial ); - glutIdleFunc( SampleIdle ); + glutEntryFunc( SampleEntry ); glutAttachMenu( GLUT_LEFT_BUTTON ); + glutSetMenu(subMenuA); + glutAttachMenu( GLUT_RIGHT_BUTTON ); + + g_sw1=glutCreateSubWindow(g_mainwin2,200,0,100,100); + glutDisplayFunc( SampleDisplay ); + glutSetMenu(subMenuB); + glutAttachMenu( GLUT_LEFT_BUTTON ); + + g_sw2=glutCreateSubWindow(g_sw1,50,0,50,50); + glutDisplayFunc( SampleDisplay ); + glutSetMenu(menuID); + glutAttachMenu( GLUT_RIGHT_BUTTON ); printf( "Testing game mode string parsing, don't panic!\n" ); glutGameModeString( "320x240:32@100" ); @@ -301,30 +361,44 @@ int main( int argc, char** argv ) glutGameModeString( "1024x768" ); glutGameModeString( ":32@120" ); glutGameModeString( "Toudi glupcze, Danwin bedzie moj!" ); - glutGameModeString( "640x480:16@72" ); - + + glutGameModeString( "640x480:37@300" ); /* this one should fail */ glutEnterGameMode(); + + glutGameModeString( "800x600" ); /* this one is likely to succeed */ + g_gamemodewin = glutEnterGameMode(); + + if (glutGameModeGet(GLUT_GAME_MODE_ACTIVE)) + g_InGameMode = 1; glutDisplayFunc( SampleDisplay ); glutReshapeFunc( SampleReshape ); glutKeyboardFunc( SampleGameModeKeyboard ); - glutIdleFunc( SampleIdle ); + glutEntryFunc( SampleEntry ); + glutSetMenu(menuID); glutAttachMenu( GLUT_LEFT_BUTTON ); - printf( "current window is %ix%i+%i+%i", - glutGet( GLUT_WINDOW_X ), glutGet( GLUT_WINDOW_Y ), - glutGet( GLUT_WINDOW_WIDTH ), glutGet( GLUT_WINDOW_HEIGHT ) + printf( "current window is %ix%i at (%i,%i)\n", + glutGet( GLUT_WINDOW_WIDTH ), glutGet( GLUT_WINDOW_HEIGHT ), + glutGet( GLUT_WINDOW_X ), glutGet( GLUT_WINDOW_Y ) ); /* + * Describe pixel format + */ + printf("The current window has %i red bits, %i green bits, %i blue bits and %i alpha bits for a total buffer size of %i bits\n",glutGet(GLUT_WINDOW_RED_SIZE),glutGet(GLUT_WINDOW_GREEN_SIZE),glutGet(GLUT_WINDOW_BLUE_SIZE),glutGet(GLUT_WINDOW_ALPHA_SIZE),glutGet(GLUT_WINDOW_BUFFER_SIZE)); + printf("It furthermore has %i depth bits and %i stencil bits\n",glutGet(GLUT_WINDOW_DEPTH_SIZE),glutGet(GLUT_WINDOW_STENCIL_SIZE)); + + /* * Enter the main FreeGLUT processing loop */ glutMainLoop(); - printf( "glutMainLoop() termination works fine!\n" ); - /* - * This is never reached in FreeGLUT. Is that good? + * returned from mainloop after window closed + * see glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,GLUT_ACTION_GLUTMAINLOOP_RETURNS); above */ + printf( "glutMainLoop() termination works fine!\n" ); + return EXIT_SUCCESS; }