Small bug-fix that's been on my mind:

Modified the two Fractals* demos so that they only clear (for the random
one) or redraw (for the non-random one) if there is need to do so.  (E.g.,
pressing the space bar should not clear and redraw the random fractal since
no parameters are altered.)


git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@231 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
rkrolib 2003-10-13 22:54:10 +00:00
parent 6e00dab2da
commit fd81891b21
2 changed files with 32 additions and 11 deletions

View File

@ -120,6 +120,8 @@ Reshape(int width, int height)
static void static void
Key(unsigned char key, int x, int y) Key(unsigned char key, int x, int y)
{ {
int need_redisplay = 1;
switch (key) { switch (key) {
case 27: /* Escape key */ case 27: /* Escape key */
glutLeaveMainLoop () ; glutLeaveMainLoop () ;
@ -140,16 +142,21 @@ Key(unsigned char key, int x, int y)
xwin = -1.0 ; xwin = -1.0 ;
ywin = 0.0 ; ywin = 0.0 ;
glTranslated ( xwin, ywin, -5.0 ) ; glTranslated ( xwin, ywin, -5.0 ) ;
break ;
default:
need_redisplay = 0;
break; break;
} }
if (need_redisplay)
glutPostRedisplay(); glutPostRedisplay();
} }
static void static void
Special(int key, int x, int y) Special(int key, int x, int y)
{ {
int need_redisplay = 1;
switch (key) { switch (key) {
case GLUT_KEY_UP : case GLUT_KEY_UP :
glMatrixMode ( GL_MODELVIEW ) ; glMatrixMode ( GL_MODELVIEW ) ;
@ -190,8 +197,12 @@ Special(int key, int x, int y)
glTranslated ( xwin, ywin, 0.0 ) ; glTranslated ( xwin, ywin, 0.0 ) ;
scale_factor *= 1.25 ; scale_factor *= 1.25 ;
break ; break ;
}
default:
need_redisplay = 0;
break;
}
if (need_redisplay)
glutPostRedisplay(); glutPostRedisplay();
} }

View File

@ -116,6 +116,8 @@ Reshape(int width, int height)
static void static void
Key(unsigned char key, int x, int y) Key(unsigned char key, int x, int y)
{ {
int changed_settings = 1;
switch (key) { switch (key) {
case 27: /* Escape key */ case 27: /* Escape key */
glutLeaveMainLoop (); glutLeaveMainLoop ();
@ -127,18 +129,22 @@ Key(unsigned char key, int x, int y)
xwin = -1.0 ; xwin = -1.0 ;
ywin = 0.0 ; ywin = 0.0 ;
glTranslatef(xwin, ywin, -5.0); glTranslatef(xwin, ywin, -5.0);
break ;
default:
changed_settings = 0;
break; break;
} }
if (changed_settings)
needClear = GL_TRUE; needClear = GL_TRUE;
glutPostRedisplay(); glutPostRedisplay();
} }
static void static void
Special(int key, int x, int y) Special(int key, int x, int y)
{ {
int changed_settings = 1;
switch (key) { switch (key) {
case GLUT_KEY_UP : case GLUT_KEY_UP :
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
@ -179,8 +185,12 @@ Special(int key, int x, int y)
glTranslatef ( xwin, ywin, 0.0 ) ; glTranslatef ( xwin, ywin, 0.0 ) ;
scale_factor *= 1.25 ; scale_factor *= 1.25 ;
break ; break ;
}
default:
changed_settings = 0;
break;
}
if (changed_settings)
needClear = GL_TRUE; needClear = GL_TRUE;
glutPostRedisplay(); glutPostRedisplay();