r300g: fix TFP stride override.
[mesa.git] / progs / demos / reflect.c
index 9a41a86083a8d3ad7ab7442b6da3780cad836a52..b72af12885d24c13643f0d3da30dc9b5431a0f7e 100644 (file)
@@ -42,6 +42,9 @@
 #define INIT_WIDTH 400
 #define INIT_HEIGHT 300
 
+#ifdef _WIN32
+#undef CreateWindowA
+#endif
 
 struct window {
    int id;               /* returned by glutCreateWindow() */
@@ -50,6 +53,7 @@ struct window {
    GLfloat xrot, yrot;
    GLfloat spin;
    GLenum showBuffer;
+   GLenum drawBuffer;
    GLuint table_list;
    GLuint objects_list[MAX_OBJECTS];
    double t0;
@@ -180,6 +184,8 @@ MakeObjects(GLuint *objects_list)
    glMaterialfv( GL_FRONT, GL_EMISSION, black );
    gluCylinder( q, 1.5, 0.0,  2.5, 15, 1 );
    glEndList();
+
+   gluDeleteQuadric(q);
 }
 
 
@@ -296,8 +302,20 @@ DrawWindow(void)
    GLfloat dist = 20.0;
    GLfloat eyex, eyey, eyez;
 
+   if (w->drawBuffer == GL_NONE) {
+      glDrawBuffer(GL_BACK);
+      glReadBuffer(GL_BACK);
+   }
+   else {
+      glDrawBuffer(w->drawBuffer);
+      glReadBuffer(w->drawBuffer);
+   }
+
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
 
+   if (w->drawBuffer == GL_NONE) {
+      glDrawBuffer(GL_NONE);
+   }
 
    eyex = dist  *  cos(w->yrot * DEG2RAD)  *  cos(w->xrot * DEG2RAD);
    eyez = dist  *  sin(w->yrot * DEG2RAD)  *  cos(w->xrot * DEG2RAD);
@@ -368,7 +386,10 @@ DrawWindow(void)
       ShowAlphaBuffer(w->width, w->height);
    }
 
-   glutSwapBuffers();
+   if (w->drawBuffer == GL_FRONT)
+      glFinish();
+   else
+      glutSwapBuffers();
 
    /* calc/show frame rate */
    {
@@ -380,6 +401,7 @@ DrawWindow(void)
          GLfloat seconds = (t - t0) / 1000.0;
          GLfloat fps = frames / seconds;
          printf("%d frames in %g seconds = %g FPS\n", frames, seconds, fps);
+         fflush(stdout);
          t0 = t;
          frames = 0;
       }
@@ -409,6 +431,15 @@ Idle(void)
 }
 
 
+static void
+UpdateIdleFunc(void)
+{
+   if (AnyAnimating())
+      glutIdleFunc(Idle);
+   else
+      glutIdleFunc(NULL);
+}
+
 static void
 Key(unsigned char key, int x, int y)
 {
@@ -433,17 +464,26 @@ Key(unsigned char key, int x, int y)
       w->showBuffer = GL_NONE;
       glutPostRedisplay();
       break;
+   case 'f':
+      if (w->drawBuffer == GL_FRONT)
+         w->drawBuffer = GL_BACK;
+      else
+         w->drawBuffer = GL_FRONT;
+      glutPostRedisplay();
+      break;
+   case '0':
+      w->drawBuffer = GL_NONE;
+      glutPostRedisplay();
+      break;
    case ' ':
       w->anim = !w->anim;
       w->t0 = -1;
-      if (AnyAnimating())
-         glutIdleFunc(Idle);
-      else
-         glutIdleFunc(NULL);
+      UpdateIdleFunc();
       glutPostRedisplay();
       break;
    case 'n':
       CreateWindow();
+      UpdateIdleFunc();
       break;
    case 'k':
       KillWindow(w);
@@ -506,6 +546,7 @@ CreateWindow(void)
    w->yrot = 50.0;
    w->spin = 0.0;
    w->showBuffer = GL_NONE;
+   w->drawBuffer = GL_BACK;
 
    InitWindow(w);
 
@@ -528,6 +569,7 @@ Usage(void)
    printf("  d      - show depth buffer\n");
    printf("  s      - show stencil buffer\n");
    printf("  c      - show color buffer\n");
+   printf("  f      - toggle rendering to front/back color buffer\n");
    printf("  n      - create new window\n");
    printf("  k      - kill window\n");
    printf("  SPACE  - toggle animation\n");