some cleanup of one demo. added menu back in gamemode
Now proper animation whose speed does not depend on the number of windows currently open Got some flicker in gamemode when other windows (that weren't visible) were also updated (only occurs when child windows present). Simply no drawing to these windows fixes things - one shouldn't draw anyway as they aren't visible. git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@1366 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
parent
c2266aa027
commit
b5664b39e7
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
int g_LeaveGameMode = 0;
|
int g_LeaveGameMode = 0;
|
||||||
int g_InGameMode = 0;
|
int g_InGameMode = 0;
|
||||||
int g_mainwin, g_sw1, g_sw2;
|
int g_mainwin, 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 )
|
void SampleDisplay( void )
|
||||||
{
|
{
|
||||||
int win = glutGetWindow();
|
int win = glutGetWindow();
|
||||||
|
|
||||||
|
if (g_InGameMode && win!=g_gamemodewin)
|
||||||
|
/* Dont draw other windows when in gamemode, those aren't visible
|
||||||
|
* anyway. Drawing them continuously anyway can cause flicker trouble
|
||||||
|
* on my machine. This only seems to occur when there are child windows
|
||||||
|
* among the non-visible windows
|
||||||
|
*/
|
||||||
|
return;
|
||||||
|
|
||||||
if (win==g_sw1)
|
if (win==g_sw1)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@ -120,6 +126,8 @@ void SampleDisplay( void )
|
|||||||
}
|
}
|
||||||
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 );
|
glMatrixMode( GL_MODELVIEW );
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
|
||||||
glRotatef( g_fTime, 0, 0, 1 );
|
glRotatef( time, 0, 0, 1 );
|
||||||
glRotatef( g_fTime, 0, 1, 0 );
|
glRotatef( time, 0, 1, 0 );
|
||||||
glRotatef( g_fTime, 1, 0, 0 );
|
glRotatef( time, 1, 0, 0 );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* And then drawn...
|
* And then drawn...
|
||||||
@ -142,7 +150,7 @@ void SampleDisplay( void )
|
|||||||
glColor3f( 1, 1, 0 );
|
glColor3f( 1, 1, 0 );
|
||||||
/* glutWireCube( 20.0 ); */
|
/* glutWireCube( 20.0 ); */
|
||||||
glutWireTeapot( 20.0 );
|
glutWireTeapot( 20.0 );
|
||||||
/* glutWireSpher( 15.0, 15, 15 ); */
|
/* glutWireSphere( 15.0, 15, 15 ); */
|
||||||
/* glColor3f( 0, 1, 0 ); */
|
/* glColor3f( 0, 1, 0 ); */
|
||||||
/* glutWireCube( 30.0 ); */
|
/* glutWireCube( 30.0 ); */
|
||||||
/* glutSolidCone( 10, 20, 10, 2 ); */
|
/* glutSolidCone( 10, 20, 10, 2 ); */
|
||||||
@ -173,10 +181,9 @@ 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... */
|
||||||
glutLeaveGameMode( );
|
glutLeaveGameMode( );
|
||||||
g_LeaveGameMode = 0;
|
g_LeaveGameMode = 0;
|
||||||
g_InGameMode = 0;
|
g_InGameMode = 0;
|
||||||
@ -334,7 +341,7 @@ int main( int argc, char** argv )
|
|||||||
g_sw1=glutCreateSubWindow(g_mainwin,200,0,100,100);
|
g_sw1=glutCreateSubWindow(g_mainwin,200,0,100,100);
|
||||||
glutDisplayFunc( SampleDisplay );
|
glutDisplayFunc( SampleDisplay );
|
||||||
glutSetMenu(subMenuB);
|
glutSetMenu(subMenuB);
|
||||||
glutAttachMenu( GLUT_LEFT_BUTTON);
|
glutAttachMenu( GLUT_LEFT_BUTTON );
|
||||||
|
|
||||||
g_sw2=glutCreateSubWindow(g_sw1,50,0,50,50);
|
g_sw2=glutCreateSubWindow(g_sw1,50,0,50,50);
|
||||||
glutDisplayFunc( SampleDisplay );
|
glutDisplayFunc( SampleDisplay );
|
||||||
@ -352,7 +359,7 @@ int main( int argc, char** argv )
|
|||||||
glutEnterGameMode();
|
glutEnterGameMode();
|
||||||
|
|
||||||
glutGameModeString( "800x600" ); /* this one is likely to succeed */
|
glutGameModeString( "800x600" ); /* this one is likely to succeed */
|
||||||
glutEnterGameMode();
|
g_gamemodewin = glutEnterGameMode();
|
||||||
|
|
||||||
if (glutGameModeGet(GLUT_GAME_MODE_ACTIVE))
|
if (glutGameModeGet(GLUT_GAME_MODE_ACTIVE))
|
||||||
g_InGameMode = 1;
|
g_InGameMode = 1;
|
||||||
@ -360,6 +367,8 @@ int main( int argc, char** argv )
|
|||||||
glutReshapeFunc( SampleReshape );
|
glutReshapeFunc( SampleReshape );
|
||||||
glutKeyboardFunc( SampleGameModeKeyboard );
|
glutKeyboardFunc( SampleGameModeKeyboard );
|
||||||
glutIdleFunc( SampleIdle );
|
glutIdleFunc( SampleIdle );
|
||||||
|
glutSetMenu(menuID);
|
||||||
|
glutAttachMenu( GLUT_LEFT_BUTTON );
|
||||||
|
|
||||||
printf( "current window is %ix%i at (%i,%i)\n",
|
printf( "current window is %ix%i at (%i,%i)\n",
|
||||||
glutGet( GLUT_WINDOW_WIDTH ), glutGet( GLUT_WINDOW_HEIGHT ),
|
glutGet( GLUT_WINDOW_WIDTH ), glutGet( GLUT_WINDOW_HEIGHT ),
|
||||||
@ -371,11 +380,12 @@ int main( int argc, char** argv )
|
|||||||
*/
|
*/
|
||||||
glutMainLoop();
|
glutMainLoop();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* returned from mainloop after window closed
|
||||||
|
* see glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,GLUT_ACTION_GLUTMAINLOOP_RETURNS); above
|
||||||
|
*/
|
||||||
printf( "glutMainLoop() termination works fine!\n" );
|
printf( "glutMainLoop() termination works fine!\n" );
|
||||||
|
|
||||||
/*
|
|
||||||
* This is never reached in FreeGLUT. Is that good?
|
|
||||||
*/
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,7 +240,7 @@ LRESULT CALLBACK fgPlatformWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
|
|||||||
uMsg, wParam, lParam ); */
|
uMsg, wParam, lParam ); */
|
||||||
|
|
||||||
/* Some events only sent to main window. Check if the current window that
|
/* Some events only sent to main window. Check if the current window that
|
||||||
* the mouse is over is a child window. Below whn handling some messages,
|
* the mouse is over is a child window. Below when handling some messages,
|
||||||
* we make sure that we process callbacks on the child window instead.
|
* we make sure that we process callbacks on the child window instead.
|
||||||
* This mirrors how GLUT does things.
|
* This mirrors how GLUT does things.
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user