projects
/
freeglut
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
prevent resize callback (and indeed the whole resizing logic) from getting
[freeglut]
/
progs
/
demos
/
One
/
one.c
diff --git
a/progs/demos/One/one.c
b/progs/demos/One/one.c
index
36f7c79
..
6509c3b
100644
(file)
--- a/
progs/demos/One/one.c
+++ b/
progs/demos/One/one.c
@@
-23,7
+23,7
@@
int g_LeaveGameMode = 0;
int g_InGameMode = 0;
int g_LeaveGameMode = 0;
int g_InGameMode = 0;
-int g_mainwin, g_sw1, g_sw2;
+int g_mainwin1, g_mainwin2, g_sw1, g_sw2, g_gamemodewin;
/*
* Call this function to have some text drawn at given coordinates
/*
* Call this function to have some text drawn at given coordinates
@@
-94,12
+94,18
@@
void PrintText( int nX, int nY, char* pszText )
/*
* This is the display routine for our sample FreeGLUT windows
*/
/*
* This is the display routine for our sample FreeGLUT windows
*/
-static float g_fTime = 0.0f;
-
void SampleDisplay( void )
{
int win = glutGetWindow();
void SampleDisplay( void )
{
int win = glutGetWindow();
+ 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;
+
if (win==g_sw1)
{
/*
if (win==g_sw1)
{
/*
@@
-107,19
+113,21
@@
void SampleDisplay( void )
*/
glClearColor(0.7f,0.7f,0.7f,1);
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
*/
glClearColor(0.7f,0.7f,0.7f,1);
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
- glutPostWindowRedisplay(g_mainwin);
+ glutPostWindowRedisplay(g_mainwin2);
}
else if (win==g_sw2)
{
/*
}
else if (win==g_sw2)
{
/*
- * Clear the screen
- */
+ * Clear the screen
+ */
glClearColor(0.3f,0.3f,0.3f,1);
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glClearColor(0.3f,0.3f,0.3f,1);
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
- glutPostWindowRedisplay(g_mainwin);
+ glutPostWindowRedisplay(g_mainwin2);
}
else
{
}
else
{
+ const GLfloat time = glutGet(GLUT_ELAPSED_TIME) / 1000.f * 40;
+
/*
* Clear the screen
*/
/*
* Clear the screen
*/
@@
-132,9
+140,9
@@
void SampleDisplay( void )
glMatrixMode( GL_MODELVIEW );
glPushMatrix();
glMatrixMode( GL_MODELVIEW );
glPushMatrix();
- glRotatef( g_fTime, 0, 0, 1 );
- glRotatef( g_fTime, 0, 1, 0 );
- glRotatef( g_fTime, 1, 0, 0 );
+ glRotatef( time, 0, 0, 1 );
+ glRotatef( time, 0, 1, 0 );
+ glRotatef( time, 1, 0, 0 );
/*
* And then drawn...
/*
* And then drawn...
@@
-142,7
+150,7
@@
void SampleDisplay( void )
glColor3f( 1, 1, 0 );
/* glutWireCube( 20.0 ); */
glutWireTeapot( 20.0 );
glColor3f( 1, 1, 0 );
/* glutWireCube( 20.0 ); */
glutWireTeapot( 20.0 );
- /* glutWireSpher( 15.0, 15, 15 ); */
+ /* glutWireSphere( 15.0, 15, 15 ); */
/* glColor3f( 0, 1, 0 ); */
/* glutWireCube( 30.0 ); */
/* glutSolidCone( 10, 20, 10, 2 ); */
/* glColor3f( 0, 1, 0 ); */
/* glutWireCube( 30.0 ); */
/* glutSolidCone( 10, 20, 10, 2 ); */
@@
-173,13
+181,17
@@
void SampleDisplay( void )
*/
void SampleIdle( void )
{
*/
void SampleIdle( void )
{
- g_fTime += 0.5f;
-
if( g_LeaveGameMode == 1 )
{
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;
glutLeaveGameMode( );
g_LeaveGameMode = 0;
g_InGameMode = 0;
+ glutPostWindowRedisplay(g_mainwin1);
+ glutPostWindowRedisplay(g_mainwin2);
+ glutPostWindowRedisplay(g_sw1);
+ glutPostWindowRedisplay(g_sw2);
}
}
}
}
@@
-187,7
+199,6
@@
void SampleEntry(int state)
{
int window = glutGetWindow () ;
printf ( "Window %d Entry Callback: %d\n", window, state ) ;
{
int window = glutGetWindow () ;
printf ( "Window %d Entry Callback: %d\n", window, state ) ;
- glutPostRedisplay () ;
}
/*
}
/*
@@
-271,13
+282,18
@@
void SampleSpecial( int nSpecial, int nMouseX, int nMouseY )
*/
void SampleMenu( int menuID )
{
*/
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 );
}
/*
+ * 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 )
* The sample's entry point
*/
int main( int argc, char** argv )
@@
-291,6
+307,8
@@
int main( int argc, char** argv )
glutInit( &argc, argv );
glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,GLUT_ACTION_GLUTMAINLOOP_RETURNS);
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 );
subMenuA = glutCreateMenu( SampleMenu );
glutAddMenuEntry( "Sub menu A1 (01)", 1 );
@@
-312,30
+330,29
@@
int main( int argc, char** argv )
glutAddSubMenu( "Enter sub menu A", subMenuA );
glutAddSubMenu( "Enter sub menu B", subMenuB );
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 );
glutDisplayFunc( SampleDisplay );
glutReshapeFunc( SampleReshape );
glutKeyboardFunc( SampleKeyboard );
glutSpecialFunc( SampleSpecial );
- glutIdleFunc( SampleIdle );
glutEntryFunc( SampleEntry );
glutAttachMenu( GLUT_LEFT_BUTTON );
glutInitWindowPosition( 200, 200 );
glutEntryFunc( SampleEntry );
glutAttachMenu( GLUT_LEFT_BUTTON );
glutInitWindowPosition( 200, 200 );
- g_mainwin = glutCreateWindow( "I am not Jan B." );
+ g_mainwin2 = glutCreateWindow( "I am not Jan B." );
glutDisplayFunc( SampleDisplay );
glutReshapeFunc( SampleReshape );
glutKeyboardFunc( SampleKeyboard );
glutSpecialFunc( SampleSpecial );
glutDisplayFunc( SampleDisplay );
glutReshapeFunc( SampleReshape );
glutKeyboardFunc( SampleKeyboard );
glutSpecialFunc( SampleSpecial );
- glutIdleFunc( SampleIdle );
+ glutEntryFunc( SampleEntry );
glutAttachMenu( GLUT_LEFT_BUTTON );
glutSetMenu(subMenuA);
glutAttachMenu( GLUT_RIGHT_BUTTON );
glutAttachMenu( GLUT_LEFT_BUTTON );
glutSetMenu(subMenuA);
glutAttachMenu( GLUT_RIGHT_BUTTON );
- g_sw1=glutCreateSubWindow(g_mainwin,200,0,100,100);
+ g_sw1=glutCreateSubWindow(g_mainwin2,200,0,100,100);
glutDisplayFunc( SampleDisplay );
glutSetMenu(subMenuB);
glutDisplayFunc( SampleDisplay );
glutSetMenu(subMenuB);
- glutAttachMenu( GLUT_LEFT_BUTTON);
+ glutAttachMenu( GLUT_LEFT_BUTTON );
g_sw2=glutCreateSubWindow(g_sw1,50,0,50,50);
glutDisplayFunc( SampleDisplay );
g_sw2=glutCreateSubWindow(g_sw1,50,0,50,50);
glutDisplayFunc( SampleDisplay );
@@
-353,14
+370,16
@@
int main( int argc, char** argv )
glutEnterGameMode();
glutGameModeString( "800x600" ); /* this one is likely to succeed */
glutEnterGameMode();
glutGameModeString( "800x600" ); /* this one is likely to succeed */
- glutEnterGameMode();
+ g_gamemodewin = glutEnterGameMode();
if (glutGameModeGet(GLUT_GAME_MODE_ACTIVE))
g_InGameMode = 1;
glutDisplayFunc( SampleDisplay );
glutReshapeFunc( SampleReshape );
glutKeyboardFunc( SampleGameModeKeyboard );
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 at (%i,%i)\n",
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 ),
@@
-372,12
+391,13
@@
int main( int argc, char** argv )
*/
glutMainLoop();
*/
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;
}
return EXIT_SUCCESS;
}
-/*** END OF FILE ***/
\ No newline at end of file
+/*** END OF FILE ***/