-/* $Id: isosurf.c,v 1.7 2000/12/24 22:53:54 pesco Exp $ */
+/* $Id: isosurf.c,v 1.8 2001/01/06 20:38:03 gareth Exp $ */
/*
- * Display an isosurface of 3-D wind speed volume.
+ * Display an isosurface of 3-D wind speed volume.
*
* Command line options:
* -info print GL implementation information
#include "readtex.c" /* I know, this is a hack. KW: me too. */
#define TEXTURE_FILE "../images/reflect.rgb"
-#define LIT 0x1
-#define UNLIT 0x2
-#define TEXTURE 0x4
-#define NO_TEXTURE 0x8
-#define REFLECT 0x10
-#define NO_REFLECT 0x20
-#define POINT_FILTER 0x40
-#define LINEAR_FILTER 0x80
-#define GLVERTEX 0x100
-#define DRAW_ARRAYS 0x200 /* or draw_elts, if compiled */
-#define ARRAY_ELT 0x400
-#define COMPILED 0x800
-#define IMMEDIATE 0x1000
-#define SHADE_SMOOTH 0x2000
-#define SHADE_FLAT 0x4000
-#define TRIANGLES 0x8000
-#define STRIPS 0x10000
-#define USER_CLIP 0x20000
-#define NO_USER_CLIP 0x40000
-#define MATERIALS 0x80000
-#define NO_MATERIALS 0x100000
-#define FOG 0x200000
-#define NO_FOG 0x400000
-#define QUIT 0x800000
-#define DISPLAYLIST 0x1000000
-#define GLINFO 0x2000000
-#define STIPPLE 0x4000000
-#define NO_STIPPLE 0x8000000
-
-#define LIGHT_MASK (LIT|UNLIT)
-#define TEXTURE_MASK (TEXTURE|NO_TEXTURE)
-#define REFLECT_MASK (REFLECT|NO_REFLECT)
-#define FILTER_MASK (POINT_FILTER|LINEAR_FILTER)
-#define RENDER_STYLE_MASK (GLVERTEX|DRAW_ARRAYS|ARRAY_ELT)
-#define COMPILED_MASK (COMPILED|IMMEDIATE|DISPLAYLIST)
-#define MATERIAL_MASK (MATERIALS|NO_MATERIALS)
-#define PRIMITIVE_MASK (TRIANGLES|STRIPS)
-#define CLIP_MASK (USER_CLIP|NO_USER_CLIP)
-#define SHADE_MASK (SHADE_SMOOTH|SHADE_FLAT)
-#define FOG_MASK (FOG|NO_FOG)
-#define STIPPLE_MASK (STIPPLE|NO_STIPPLE)
+#define LIT 0x1
+#define UNLIT 0x2
+#define TEXTURE 0x4
+#define NO_TEXTURE 0x8
+#define REFLECT 0x10
+#define NO_REFLECT 0x20
+#define POINT_FILTER 0x40
+#define LINEAR_FILTER 0x80
+#define GLVERTEX 0x100
+#define DRAW_ARRAYS 0x200 /* or draw_elts, if compiled */
+#define ARRAY_ELT 0x400
+#define COMPILED 0x800
+#define IMMEDIATE 0x1000
+#define SHADE_SMOOTH 0x2000
+#define SHADE_FLAT 0x4000
+#define TRIANGLES 0x8000
+#define STRIPS 0x10000
+#define POINTS 0x20000
+#define USER_CLIP 0x40000
+#define NO_USER_CLIP 0x80000
+#define MATERIALS 0x100000
+#define NO_MATERIALS 0x200000
+#define FOG 0x400000
+#define NO_FOG 0x800000
+#define QUIT 0x1000000
+#define DISPLAYLIST 0x2000000
+#define GLINFO 0x4000000
+#define STIPPLE 0x8000000
+#define NO_STIPPLE 0x10000000
+
+#define LIGHT_MASK (LIT|UNLIT)
+#define TEXTURE_MASK (TEXTURE|NO_TEXTURE)
+#define REFLECT_MASK (REFLECT|NO_REFLECT)
+#define FILTER_MASK (POINT_FILTER|LINEAR_FILTER)
+#define RENDER_STYLE_MASK (GLVERTEX|DRAW_ARRAYS|ARRAY_ELT)
+#define COMPILED_MASK (COMPILED|IMMEDIATE|DISPLAYLIST)
+#define MATERIAL_MASK (MATERIALS|NO_MATERIALS)
+#define PRIMITIVE_MASK (TRIANGLES|STRIPS|POINTS)
+#define CLIP_MASK (USER_CLIP|NO_USER_CLIP)
+#define SHADE_MASK (SHADE_SMOOTH|SHADE_FLAT)
+#define FOG_MASK (FOG|NO_FOG)
+#define STIPPLE_MASK (STIPPLE|NO_STIPPLE)
#define MAXVERTS 10000
static float data[MAXVERTS][6];
#define VEC_ELT(f, s, i) (float *)(((char *)f) + s * i)
-static int sort_axis( int axis,
+static int sort_axis( int axis,
int vec_size,
int vec_stride,
struct data_idx *indices,
{
int i;
- if (finish-start > 2)
+ if (finish-start > 2)
{
qsort( indices+start, finish-start, sizeof(*indices), compare[axis] );
- }
- else if (indices[start].data[axis] > indices[start+1].data[axis])
+ }
+ else if (indices[start].data[axis] > indices[start+1].data[axis])
{
struct data_idx tmp = indices[start];
indices[start] = indices[start+1];
indices[start+1] = tmp;
}
-
+
if (axis == vec_size-1) {
for (i = start ; i < finish ; ) {
float max = indices[i].data[axis] + fudge;
float *dest = VEC_ELT(out, vec_stride, uniq);
int j;
-
+
for (j = 0 ; j < vec_size ; j++)
dest[j] = indices[i].data[j];
- for ( ; i < finish && max >= indices[i].data[axis]; i++)
+ for ( ; i < finish && max >= indices[i].data[axis]; i++)
indices[i].uniq_idx = uniq;
uniq++;
int k;
indices[i].uniq_idx = uniq;
-
+
for (k = 0 ; k < vec_size ; k++)
dest[k] = indices[i].data[k];
}
-static void extract_indices1( const struct data_idx *in, unsigned int *out,
+static void extract_indices1( const struct data_idx *in, unsigned int *out,
int n )
{
int i;
ind[i].data = data[i];
}
- numuniq = sort_axis(0,
- sizeof(compressed_data[0])/sizeof(float),
+ numuniq = sort_axis(0,
+ sizeof(compressed_data[0])/sizeof(float),
sizeof(compressed_data[0]),
- ind,
- 0,
- numverts,
- (float *)compressed_data,
+ ind,
+ 0,
+ numverts,
+ (float *)compressed_data,
0,
1e-6);
for (j=2;j<numverts;j++,parity^=1) {
if (parity) {
*v++ = indices[j-1];
- *v++ = indices[j-2];
+ *v++ = indices[j-2];
*v++ = indices[j];
} else {
*v++ = indices[j-2];
*v++ = indices[j];
}
}
-
+
num_tri_verts = v - tri_indices;
printf("num_tri_verts: %d\n", num_tri_verts);
switch (with_state & (COMPILED_MASK|RENDER_STYLE_MASK|PRIMITIVE_MASK)) {
#ifdef GL_EXT_vertex_array
- case (COMPILED|DRAW_ARRAYS|STRIPS):
- glDrawElements( GL_TRIANGLE_STRIP, numverts, GL_UNSIGNED_INT, indices );
- break;
-
-
- case (COMPILED|ARRAY_ELT|STRIPS):
- glBegin( GL_TRIANGLE_STRIP );
- for (i = 0 ; i < numverts ; i++)
- glArrayElement( indices[i] );
- glEnd();
- break;
-
- case (COMPILED|DRAW_ARRAYS|TRIANGLES):
case (IMMEDIATE|DRAW_ARRAYS|TRIANGLES):
+ case (COMPILED|DRAW_ARRAYS|TRIANGLES):
if (with_state & MATERIALS) {
for (j = i = 0 ; i < num_tri_verts ; i += 600, j++) {
GLuint nr = MIN(num_tri_verts-i, 600);
glDrawElements( GL_TRIANGLES, nr, GL_UNSIGNED_INT, tri_indices+i );
}
} else {
- glDrawElements( GL_TRIANGLES, num_tri_verts, GL_UNSIGNED_INT,
+ glDrawElements( GL_TRIANGLES, num_tri_verts, GL_UNSIGNED_INT,
tri_indices );
}
-
- break;
-
- /* Uses the original arrays (including duplicate elements):
- */
- case (IMMEDIATE|DRAW_ARRAYS|STRIPS):
- glDrawArraysEXT( GL_TRIANGLE_STRIP, 0, numverts );
- break;
-
- /* Uses the original arrays (including duplicate elements):
- */
- case (IMMEDIATE|ARRAY_ELT|STRIPS):
- glBegin( GL_TRIANGLE_STRIP );
- for (i = 0 ; i < numverts ; i++)
- glArrayElement( i );
- glEnd();
break;
case (IMMEDIATE|ARRAY_ELT|TRIANGLES):
glBegin( GL_TRIANGLES );
for (i = 0 ; i < num_tri_verts ; i++)
glArrayElement( tri_indices[i] );
-
+
glEnd();
- }
+ }
+ break;
+
+
+ /* Uses the original arrays (including duplicate elements):
+ */
+ case (IMMEDIATE|DRAW_ARRAYS|STRIPS):
+ glDrawArraysEXT( GL_TRIANGLE_STRIP, 0, numverts );
+ break;
+ case (COMPILED|DRAW_ARRAYS|STRIPS):
+ glDrawElements( GL_TRIANGLE_STRIP, numverts, GL_UNSIGNED_INT, indices );
break;
+ /* Uses the original arrays (including duplicate elements):
+ */
+ case (IMMEDIATE|ARRAY_ELT|STRIPS):
+ glBegin( GL_TRIANGLE_STRIP );
+ for (i = 0 ; i < numverts ; i++)
+ glArrayElement( i );
+ glEnd();
+ break;
+
+ case (COMPILED|ARRAY_ELT|STRIPS):
+ glBegin( GL_TRIANGLE_STRIP );
+ for (i = 0 ; i < numverts ; i++)
+ glArrayElement( indices[i] );
+ glEnd();
+ break;
+
+ case (DISPLAYLIST|GLVERTEX|STRIPS):
+ if (!surf1)
+ surf1 = BuildList( GL_COMPILE_AND_EXECUTE );
+ else
+ glCallList(surf1);
+ break;
+
+
+ case (IMMEDIATE|DRAW_ARRAYS|POINTS):
+ glDrawArraysEXT( GL_POINTS, 0, numverts );
+ break;
+ case (COMPILED|DRAW_ARRAYS|POINTS):
+ glDrawElements( GL_POINTS, numverts, GL_UNSIGNED_INT, indices );
+ break;
+ case (IMMEDIATE|ARRAY_ELT|POINTS):
+ case (COMPILED|ARRAY_ELT|POINTS):
+ glBegin( GL_POINTS );
+ for (i = 0 ; i < numverts ; i++)
+ glArrayElement( indices[i] );
+ glEnd();
+ break;
+#endif
+
case (IMMEDIATE|GLVERTEX|TRIANGLES):
if (with_state & MATERIALS) {
for (j = i = 0 ; i < num_tri_verts ; i += 600, j++) {
glVertex3fv( &compressed_data[tri_indices[i]][0] );
}
glEnd();
- }
+ }
break;
- case (DISPLAYLIST|GLVERTEX|STRIPS):
- if (!surf1)
- surf1 = BuildList( GL_COMPILE_AND_EXECUTE );
- else
- glCallList(surf1);
+ case (IMMEDIATE|GLVERTEX|POINTS):
+ glBegin( GL_POINTS );
+ for ( i = 0 ; i < numverts ; i++ ) {
+ glNormal3fv( &data[i][3] );
+ glVertex3fv( &data[i][0] );
+ }
+ glEnd();
break;
-#endif
-
/* Uses the original arrays (including duplicate elements):
*/
default:
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
draw_surface( state );
glFlush();
- if (doubleBuffer) glutSwapBuffers();
+ if (doubleBuffer) glutSwapBuffers();
}
int BuildList( int mode )
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
glLightfv(GL_LIGHT0, GL_POSITION, position0);
glEnable(GL_LIGHT0);
-
+
glLightfv(GL_LIGHT1, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse);
glLightfv(GL_LIGHT1, GL_POSITION, position1);
glEnable(GL_LIGHT1);
-
+
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside);
if (!m) return;
- if (m==QUIT)
+ if (m==QUIT)
exit(0);
if (m==GLINFO) {
if (CHANGED(state, m, TEXTURE_MASK)) {
- if (m & TEXTURE)
+ if (m & TEXTURE)
glEnable(GL_TEXTURE_2D);
else
glDisable(GL_TEXTURE_2D);
}
if (CHANGED(state, m, FOG_MASK)) {
- if (m & FOG)
+ if (m & FOG)
{
glEnable(GL_FOG);
printf("FOG enable\n");
- }
- else
+ }
+ else
{
glDisable(GL_FOG);
printf("FOG disable\n");
}
if (CHANGED(state, m, STIPPLE_MASK)) {
- if (m & STIPPLE)
+ if (m & STIPPLE)
{
glEnable(GL_POLYGON_STIPPLE);
printf("STIPPLE enable\n");
- }
- else
+ }
+ else
{
glDisable(GL_POLYGON_STIPPLE);
printf("STIPPLE disable\n");
}
#ifdef GL_EXT_vertex_array
- if (CHANGED(state, m, (COMPILED_MASK|RENDER_STYLE_MASK|PRIMITIVE_MASK)))
+ if (CHANGED(state, m, (COMPILED_MASK|RENDER_STYLE_MASK|PRIMITIVE_MASK)))
{
if ((m & (COMPILED_MASK|PRIMITIVE_MASK)) == (IMMEDIATE|STRIPS))
{
glVertexPointerEXT( 3, GL_FLOAT, sizeof(data[0]), numverts, data );
glNormalPointerEXT( GL_FLOAT, sizeof(data[0]), numverts, &data[0][3]);
}
- else
+ else
{
- glVertexPointerEXT( 3, GL_FLOAT, sizeof(data[0]), numuniq,
+ glVertexPointerEXT( 3, GL_FLOAT, sizeof(data[0]), numuniq,
compressed_data );
- glNormalPointerEXT( GL_FLOAT, sizeof(data[0]), numuniq,
+ glNormalPointerEXT( GL_FLOAT, sizeof(data[0]), numuniq,
&compressed_data[0][3]);
}
#ifdef GL_EXT_compiled_vertex_array
if (m & (RENDER_STYLE_MASK|PRIMITIVE_MASK)) {
UPDATE(state, m, (RENDER_STYLE_MASK|PRIMITIVE_MASK));
}
-
+
if (m & MATERIAL_MASK) {
UPDATE(state, m, MATERIAL_MASK);
}
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
- glClipPlane(GL_CLIP_PLANE0, plane);
+ glClipPlane(GL_CLIP_PLANE0, plane);
set_matrix();
glutInitWindowPosition(0, 0);
glutInitWindowSize(400, 400);
-
+
type = GLUT_DEPTH;
type |= GLUT_RGB;
type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
/* Make sure server supports the vertex array extension */
extensions = (char *) glGetString( GL_EXTENSIONS );
- if (!strstr( extensions, "GL_EXT_vertex_array" ))
+ if (!strstr( extensions, "GL_EXT_vertex_array" ))
{
printf("Vertex arrays not supported by this renderer\n");
allowed &= ~(COMPILED|DRAW_ARRAYS|ARRAY_ELT);
}
- else if (!strstr( extensions, "GL_EXT_compiled_vertex_array" ))
+ else if (!strstr( extensions, "GL_EXT_compiled_vertex_array" ))
{
printf("Compiled vertex arrays not supported by this renderer\n");
allowed &= ~COMPILED;
Init(argc, argv);
ModeMenu(arg_mode);
-
+
glutCreateMenu(ModeMenu);
- glutAddMenuEntry("GL info", GLINFO);
- glutAddMenuEntry("", 0);
+ glutAddMenuEntry("GL info", GLINFO);
+ glutAddMenuEntry("", 0);
glutAddMenuEntry("Lit", LIT|NO_TEXTURE|NO_REFLECT);
glutAddMenuEntry("Unlit", UNLIT|NO_TEXTURE|NO_REFLECT);
/* glutAddMenuEntry("Textured", TEXTURE); */
glutAddMenuEntry("Reflect", TEXTURE|REFLECT);
- glutAddMenuEntry("", 0);
+ glutAddMenuEntry("", 0);
glutAddMenuEntry("Smooth", SHADE_SMOOTH);
glutAddMenuEntry("Flat", SHADE_FLAT);
- glutAddMenuEntry("", 0);
+ glutAddMenuEntry("", 0);
glutAddMenuEntry("Fog", FOG);
glutAddMenuEntry("No Fog", NO_FOG);
- glutAddMenuEntry("", 0);
+ glutAddMenuEntry("", 0);
glutAddMenuEntry("Stipple", STIPPLE);
glutAddMenuEntry("No Stipple", NO_STIPPLE);
- glutAddMenuEntry("", 0);
+ glutAddMenuEntry("", 0);
glutAddMenuEntry("Point Filtered", POINT_FILTER);
glutAddMenuEntry("Linear Filtered", LINEAR_FILTER);
- glutAddMenuEntry("", 0);
- glutAddMenuEntry("glVertex (STRIPS)", IMMEDIATE|GLVERTEX|STRIPS);
- glutAddMenuEntry("glVertex (TRIANGLES)", IMMEDIATE|GLVERTEX|TRIANGLES);
- glutAddMenuEntry("", 0);
- glutAddMenuEntry("glVertex display list (STRIPS)",
+ glutAddMenuEntry("", 0);
+ glutAddMenuEntry("glVertex (TRIANGLES)", IMMEDIATE|GLVERTEX|TRIANGLES);
+ glutAddMenuEntry("glVertex (STRIPS)", IMMEDIATE|GLVERTEX|STRIPS);
+ glutAddMenuEntry("glVertex (POINTS)", IMMEDIATE|GLVERTEX|POINTS);
+ glutAddMenuEntry("", 0);
+ glutAddMenuEntry("glVertex display list (STRIPS)",
DISPLAYLIST|GLVERTEX|STRIPS);
- glutAddMenuEntry("", 0);
+ glutAddMenuEntry("", 0);
if (allowed & DRAW_ARRAYS) {
+ glutAddMenuEntry("DrawElements (TRIANGLES)",
+ IMMEDIATE|DRAW_ARRAYS|TRIANGLES);
glutAddMenuEntry("DrawArrays (STRIPS)",
IMMEDIATE|DRAW_ARRAYS|STRIPS);
- glutAddMenuEntry("ArrayElement (STRIPS)",
- IMMEDIATE|ARRAY_ELT|STRIPS);
- glutAddMenuEntry("DrawElements (TRIANGLES)",
- IMMEDIATE|DRAW_ARRAYS|TRIANGLES);
- glutAddMenuEntry("ArrayElement (TRIANGLES)",
+ glutAddMenuEntry("DrawArrays (POINTS)",
+ IMMEDIATE|DRAW_ARRAYS|POINTS);
+ glutAddMenuEntry("ArrayElement (TRIANGLES)",
IMMEDIATE|ARRAY_ELT|TRIANGLES);
- glutAddMenuEntry("", 0);
+ glutAddMenuEntry("ArrayElement (STRIPS)",
+ IMMEDIATE|ARRAY_ELT|STRIPS);
+ glutAddMenuEntry("ArrayElement (POINTS)",
+ IMMEDIATE|ARRAY_ELT|POINTS);
+ glutAddMenuEntry("", 0);
}
if (allowed & COMPILED) {
- glutAddMenuEntry("Compiled DrawElements (TRIANGLES)",
+ glutAddMenuEntry("Compiled DrawElements (TRIANGLES)",
COMPILED|DRAW_ARRAYS|TRIANGLES);
- glutAddMenuEntry("Compiled DrawElements (STRIPS)",
+ glutAddMenuEntry("Compiled DrawElements (STRIPS)",
COMPILED|DRAW_ARRAYS|STRIPS);
- glutAddMenuEntry("Compiled ArrayElement (TRIANGLES)",
- COMPILED|ARRAY_ELT|TRIANGLES);
- glutAddMenuEntry("Compiled ArrayElement (STRIPS)",
- COMPILED|ARRAY_ELT|STRIPS);
- glutAddMenuEntry("", 0);
+ glutAddMenuEntry("Compiled DrawElements (POINTS)",
+ COMPILED|DRAW_ARRAYS|POINTS);
+ glutAddMenuEntry("Compiled ArrayElement (TRIANGLES)",
+ COMPILED|ARRAY_ELT|TRIANGLES);
+ glutAddMenuEntry("Compiled ArrayElement (STRIPS)",
+ COMPILED|ARRAY_ELT|STRIPS);
+ glutAddMenuEntry("Compiled ArrayElement (POINTS)",
+ COMPILED|ARRAY_ELT|POINTS);
+ glutAddMenuEntry("", 0);
}
glutAddMenuEntry("Quit", QUIT);
glutAttachMenu(GLUT_RIGHT_BUTTON);