progs/es: Move OpenGL ES demos to subdirectories of progs/egl.
[mesa.git] / progs / trivial / tri-stencil.c
index 5edbef26ced666522cfb302317cf15b7809734f9..d66b68c415aadb8041db98df3efb8739d55e8622 100644 (file)
@@ -49,7 +49,15 @@ static void Key(unsigned char key, int x, int y)
 
     switch (key) {
       case 27:
+        printf("Exiting...\n");
        exit(1);
+      case 'r':
+        printf("Redisplaying...\n");
+        glutPostRedisplay();
+        break;
+      default:
+        printf("No such key '%c'...\n", key);
+        break;
     }
 }
 
@@ -69,6 +77,7 @@ static void Draw(void)
    glStencilFunc(GL_ALWAYS, 1, 1);
    glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
 
+   /* red triangle (setting stencil to 1) */
    glColor3ub(200, 0, 0);
    glBegin(GL_POLYGON);        
    glVertex3i(-4, -4, 0);
@@ -80,6 +89,7 @@ static void Draw(void)
    glStencilFunc(GL_EQUAL, 1, 1);
    glStencilOp(GL_INCR, GL_KEEP, GL_DECR);
 
+   /* green quad (if over red, decr stencil to 0, else incr to 1) */
    glColor3ub(0, 200, 0);
    glBegin(GL_POLYGON);
    glVertex3i(3, 3, 0);
@@ -89,10 +99,11 @@ static void Draw(void)
    glEnd();
 #endif
 
-#if 0
+#if 1
    glStencilFunc(GL_EQUAL, 1, 1);
    glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
 
+   /* blue quad (where stencil == 1) */
    glColor3ub(0, 0, 200);
    glBegin(GL_POLYGON);
    glVertex3f(2.5, 2.5, 0);
@@ -130,12 +141,13 @@ int main(int argc, char **argv)
        exit(1);
     }
 
-    glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300);
+    glutInitWindowPosition(0, 0); 
+    glutInitWindowSize( 300, 300);
 
     type = GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH | GLUT_STENCIL;
     glutInitDisplayMode(type);
 
-    if (glutCreateWindow("Stencil Test") == GL_FALSE) {
+    if (glutCreateWindow(*argv) == GL_FALSE) {
        exit(1);
     }