#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
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 )
}
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);
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 );
}
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);
}
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");
if (glutCreateWindow("Isosurface") <= 0) {
exit(0);
}
+ glewInit();
glutReshapeFunc(Reshape);
glutKeyboardFunc(Key);
glutSpecialFunc(SpecialKey);