X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=progs%2Fdemos%2FOne%2Fone.c;h=cf2cb1483fd017e9c7aea5e4e7e80fcebde16ab2;hb=d9b0989056a1c2267b68f01317d4641c70e48719;hp=627630e637dd143540f04b7706c22bb0e93681c0;hpb=757a3da51cbb39e52f71bf25ac16a9f9a40dab9a;p=freeglut diff --git a/progs/demos/One/one.c b/progs/demos/One/one.c index 627630e..cf2cb14 100644 --- a/progs/demos/One/one.c +++ b/progs/demos/One/one.c @@ -1,7 +1,7 @@ /* * one.c * - * Hey! This was the original file where freeglut development started. Just + * Hey! This was the original file where freeglut development started. Just * note what I have written here at the time. And see the creation date :) * * : This is a wrapper. I still have to figure out @@ -22,7 +22,8 @@ #include int g_LeaveGameMode = 0; -int g_InGameMode = 1; +int g_InGameMode = 0; +int g_mainwin, g_sw1, g_sw2; /* * Call this function to have some text drawn at given coordinates @@ -31,16 +32,16 @@ void PrintText( int nX, int nY, char* pszText ) { int lines; char *p; - + /* * Prepare the OpenGL state */ glDisable( GL_LIGHTING ); - glDisable( GL_DEPTH_TEST ); + glDisable( GL_DEPTH_TEST ); glMatrixMode( GL_PROJECTION ); glPushMatrix(); glLoadIdentity(); - + /* * Have an orthogonal projection matrix set */ @@ -55,12 +56,12 @@ void PrintText( int nX, int nY, char* pszText ) glMatrixMode( GL_MODELVIEW ); glPushMatrix(); glLoadIdentity(); - + /* - * Now the main text + * Now the main text */ - glColor3ub( 0, 0, 0 ); - glRasterPos2i( nX, nY ); + glColor3ub( 0, 0, 0 ); + glRasterPos2i( nX, nY ); for( p=pszText, lines=0; *p; p++ ) { @@ -69,26 +70,26 @@ void PrintText( int nX, int nY, char* pszText ) lines++; glRasterPos2i( nX, nY-(lines*18) ); } - + glutBitmapCharacter( GLUT_BITMAP_HELVETICA_18, *p ); } - + /* * Revert to the old matrix modes - */ + */ glMatrixMode( GL_PROJECTION ); glPopMatrix(); - + glMatrixMode( GL_MODELVIEW ); glPopMatrix(); - + /* * Restore the old OpenGL states */ glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); glEnable( GL_DEPTH_TEST ); glEnable( GL_LIGHTING ); -} +} /* * This is the display routine for our sample FreeGLUT windows @@ -97,50 +98,74 @@ 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( ); - - /* - * 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_mainwin); + } + 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_mainwin); + } else - PrintText( 20, 20, "Press ESC to leave the game mode!" ); + { + /* + * 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( 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( ); + + /* + * 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); } /* @@ -156,7 +181,13 @@ void SampleIdle( void ) g_LeaveGameMode = 0; g_InGameMode = 0; } -} +} + +void SampleEntry(int state) +{ + int window = glutGetWindow () ; + printf ( "Window %d Entry Callback: %d\n", window, state ) ; +} /* * The reshape function @@ -242,7 +273,7 @@ void SampleMenu( int menuID ) /* * Just print something funny */ - printf( "SampleMenu() callback executed, menuID is %i\n", menuID ); + printf( "SampleMenu() callback executed, menuID is %i\n", menuID ); } /* @@ -258,11 +289,13 @@ int main( int argc, char** argv ) glutInit( &argc, argv ); + glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,GLUT_ACTION_GLUTMAINLOOP_RETURNS); + subMenuA = glutCreateMenu( SampleMenu ); glutAddMenuEntry( "Sub menu A1 (01)", 1 ); glutAddMenuEntry( "Sub menu A2 (02)", 2 ); glutAddMenuEntry( "Sub menu A3 (03)", 3 ); - + subMenuB = glutCreateMenu( SampleMenu ); glutAddMenuEntry( "Sub menu B1 (04)", 4 ); glutAddMenuEntry( "Sub menu B2 (05)", 5 ); @@ -284,36 +317,54 @@ int main( int argc, char** argv ) glutKeyboardFunc( SampleKeyboard ); glutSpecialFunc( SampleSpecial ); glutIdleFunc( SampleIdle ); + glutEntryFunc( SampleEntry ); glutAttachMenu( GLUT_LEFT_BUTTON ); glutInitWindowPosition( 200, 200 ); - glutCreateWindow( "I am not Jan B." ); + g_mainwin = glutCreateWindow( "I am not Jan B." ); glutDisplayFunc( SampleDisplay ); glutReshapeFunc( SampleReshape ); glutKeyboardFunc( SampleKeyboard ); glutSpecialFunc( SampleSpecial ); glutIdleFunc( SampleIdle ); glutAttachMenu( GLUT_LEFT_BUTTON ); + glutSetMenu(subMenuA); + glutAttachMenu( GLUT_RIGHT_BUTTON ); + + g_sw1=glutCreateSubWindow(g_mainwin,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" ); glutGameModeString( "640x480:16@72" ); glutGameModeString( "1024x768" ); glutGameModeString( ":32@120" ); - glutGameModeString( "Toudi glupcze, Danwin bedzie moj!" ); - glutGameModeString( "640x480:16@72" ); + glutGameModeString( "Toudi glupcze, Danwin bedzie moj!" ); + + glutGameModeString( "640x480:37@300" ); /* this one should fail */ + glutEnterGameMode(); + glutGameModeString( "800x600" ); /* this one is likely to succeed */ glutEnterGameMode(); + + if (glutGameModeGet(GLUT_GAME_MODE_ACTIVE)) + g_InGameMode = 1; glutDisplayFunc( SampleDisplay ); glutReshapeFunc( SampleReshape ); glutKeyboardFunc( SampleGameModeKeyboard ); glutIdleFunc( SampleIdle ); - 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 ) + ); /* * Enter the main FreeGLUT processing loop @@ -328,4 +379,4 @@ int main( int argc, char** argv ) return EXIT_SUCCESS; } -/*** END OF FILE ***/ +/*** END OF FILE ***/ \ No newline at end of file