summaryrefslogtreecommitdiff
path: root/progs
diff options
context:
space:
mode:
authorBrian Paul <brian.paul@tungstengraphics.com>2000-10-31 20:41:06 +0000
committerBrian Paul <brian.paul@tungstengraphics.com>2000-10-31 20:41:06 +0000
commitfda3b1a4b18c917f15fe9aa2b83f166a2fa9d24b (patch)
treee9274c9de6d4ea2b87ed66b9292d4b48aebf4e2d /progs
parent724abeb058ca9372c5a9b9e38ee43dde1accaa41 (diff)
added comment explaining why the demo is flawed
Diffstat (limited to 'progs')
-rw-r--r--progs/redbook/stencil.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/progs/redbook/stencil.c b/progs/redbook/stencil.c
index 5626d55be6..b33e40a030 100644
--- a/progs/redbook/stencil.c
+++ b/progs/redbook/stencil.c
@@ -43,6 +43,21 @@
* of the scene. Within this mask, a different model
* (a sphere) is drawn in a different color.
*/
+
+/*
+ * !!! NOTE !!!
+ *
+ * This demo is poorly written. The stencil buffer should be
+ * redrawn in display(), not in the myReshape() function.
+ * The reason is if the window gets "damaged" then the stencil buffer
+ * contents will be in an undefined state (myReshape is not called when
+ * a window is damaged and needs to be redrawn). If the stencil buffer
+ * contents are undefined, the results of display() are unpredictable.
+ *
+ * -Brian
+ */
+
+
#include <stdlib.h>
#include <GL/glut.h>
@@ -90,6 +105,8 @@ void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP);
+
/* draw blue sphere where the stencil is 1 */
glStencilFunc (GL_EQUAL, 0x1, 0x1);
glCallList (BLUEMAT);
@@ -97,7 +114,6 @@ void display(void)
/* draw the tori where the stencil is not 1 */
glStencilFunc (GL_NOTEQUAL, 0x1, 0x1);
- glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP);
glPushMatrix();
glRotatef (45.0, 0.0, 0.0, 1.0);
glRotatef (45.0, 0.0, 1.0, 0.0);
@@ -110,6 +126,7 @@ void display(void)
glPopMatrix();
glFlush();
+ glutSwapBuffers();
}
/* Whenever the window is reshaped, redefine the
@@ -164,7 +181,7 @@ key(unsigned char k, int x, int y)
int main(int argc, char** argv)
{
glutInit(&argc, argv);
- glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH | GLUT_STENCIL);
+ glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_STENCIL);
glutInitWindowSize (400, 400);
glutCreateWindow (argv[0]);
myinit ();