gallium: Support swig "compiler" in p_compiler.h
[mesa.git] / progs / tests / vparray.c
index 65a3bbfefc3754587b6a0ddb8e798e172d7a3819..75160afd463bb15ef28d5a9740d1c28073fb7413 100644 (file)
@@ -8,11 +8,10 @@
 
 #include <assert.h>
 #include <stdio.h>
-#include <string.h>
 #include <stdlib.h>
 #include <string.h>
 #include <math.h>
-#define GL_GLEXT_PROTOTYPES
+#include "GL/glew.h"
 #include "GL/glut.h"
 
 #define MAXVERTS 10000
@@ -21,8 +20,9 @@ static GLint numverts;
 
 static GLfloat xrot;
 static GLfloat yrot;
-static GLboolean useArrays = GL_FALSE;
-static GLboolean useProgram = GL_FALSE;
+static GLboolean useArrays = GL_TRUE;
+static GLboolean useProgram = GL_TRUE;
+static GLboolean useList = GL_FALSE;
 
 
 static void read_surface( char *filename )
@@ -36,13 +36,16 @@ static void read_surface( char *filename )
    }
 
    numverts = 0;
-   while (!feof(f) && numverts < MAXVERTS) {
-      fscanf( f, "%f %f %f  %f %f %f",
-             &data[numverts][0], &data[numverts][1], &data[numverts][2],
-             &data[numverts][3], &data[numverts][4], &data[numverts][5] );
+   while (numverts < MAXVERTS) {
+      int result;
+      result = fscanf( f, "%f %f %f  %f %f %f",
+                      &data[numverts][0], &data[numverts][1], &data[numverts][2],
+                      &data[numverts][3], &data[numverts][4], &data[numverts][5] );
+      if (result == EOF) {
+         break;
+      }
       numverts++;
    }
-   numverts--;
 
    printf("%d vertices, %d triangles\n", numverts, numverts-2);
    printf("data = %p\n", (void *) data);
@@ -71,23 +74,27 @@ static void Display(void)
             glEnableClientState( GL_VERTEX_ATTRIB_ARRAY0_NV );
             glVertexAttribPointerNV( 2, 3, GL_FLOAT, 6 * sizeof(GLfloat), ((GLfloat *) data) + 3);
             glEnableClientState( GL_VERTEX_ATTRIB_ARRAY2_NV);
-
-            glDisableClientState( GL_VERTEX_ARRAY );
-            glDisableClientState( GL_NORMAL_ARRAY );
          }
          else {
             glVertexPointer( 3, GL_FLOAT, 6 * sizeof(GLfloat), data );
             glEnableClientState( GL_VERTEX_ARRAY );
             glNormalPointer( GL_FLOAT, 6 * sizeof(GLfloat), ((GLfloat *) data) + 3);
             glEnableClientState( GL_NORMAL_ARRAY );
-
-            glDisableClientState( GL_VERTEX_ATTRIB_ARRAY0_NV );
-            glDisableClientState( GL_VERTEX_ATTRIB_ARRAY2_NV);
          }
 
-         glDrawArrays(GL_TRIANGLE_STRIP, 0, numverts);
+         if (useList) {
+            /* dumb, but a good test */
+            glNewList(1,GL_COMPILE);
+            glDrawArrays(GL_TRIANGLE_STRIP, 0, numverts);
+            glEndList();
+            glCallList(1);
+         }
+         else {
+            glDrawArrays(GL_TRIANGLE_STRIP, 0, numverts);
+         }
 
          glDisableClientState( GL_VERTEX_ATTRIB_ARRAY0_NV );
+         glDisableClientState( GL_VERTEX_ATTRIB_ARRAY2_NV);
          glDisableClientState( GL_VERTEX_ARRAY );
          glDisableClientState( GL_NORMAL_ARRAY );
       }
@@ -175,7 +182,7 @@ static void init_program(void)
    static const GLfloat bias[4] = {1.0, 1.0, 1.0, 0.0};
 
    if (!glutExtensionSupported("GL_NV_vertex_program")) {
-      printf("Sorry, this program requires GL_NV_vertex_program");
+      printf("Sorry, this program requires GL_NV_vertex_program\n");
       exit(1);
    }
 
@@ -230,6 +237,10 @@ static void Key( unsigned char key, int x, int y )
       useArrays = !useArrays;
       printf("use arrays: %s\n", useArrays ? "yes" : "no");
       break;
+   case 'l':
+      useList = !useList;
+      printf("use list: %s\n", useList ? "yes" : "no");
+      break;
    case 'p':
       useProgram = !useProgram;
       printf("use program: %s\n", useProgram ? "yes" : "no");
@@ -273,6 +284,7 @@ int main(int argc, char **argv)
    if (glutCreateWindow("Isosurface") <= 0) {
       exit(0);
    }
+   glewInit();
    glutReshapeFunc(Reshape);
    glutKeyboardFunc(Key);
    glutSpecialFunc(SpecialKey);