static void draw_surface() { GLint i; #ifdef GL_EXT_vertex_array if (use_vertex_arrays) { glDrawArraysEXT( GL_TRIANGLE_STRIP, 0, numverts ); } else #endif { glBegin( GL_TRIANGLE_STRIP ); for (i=0;i<numverts;i++) { glNormal3fv( norms[i] ); glVertex3fv( verts[i] ); } glEnd(); } }
static void draw_surface( unsigned int with_state ) { GLint i, j; if (with_state & DISPLAYLIST) { if ((with_state & (RENDER_STYLE_MASK|PRIMITIVE_MASK|MATERIAL_MASK)) != dlist_state) { /* */ fprintf(stderr, "rebuilding displaylist\n"); if (dlist_state) glDeleteLists( surf1, 1 ); dlist_state = with_state & (RENDER_STYLE_MASK|PRIMITIVE_MASK| MATERIAL_MASK); surf1 = glGenLists(1); glNewList(surf1, GL_COMPILE); draw_surface( dlist_state ); glEndList(); } glCallList( surf1 ); return; } switch (with_state & (RENDER_STYLE_MASK|PRIMITIVE_MASK)) { #ifdef GL_EXT_vertex_array case (DRAW_ELTS|TRIANGLES): if (with_state & MATERIALS) { for (j = i = 0 ; i < num_tri_verts ; i += 600, j++) { GLuint nr = MIN(num_tri_verts-i, 600); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, col[j]); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, col[j]); glDrawElements( GL_TRIANGLES, nr, GL_UNSIGNED_INT, tri_indices+i ); } } else { glDrawElements( GL_TRIANGLES, num_tri_verts, GL_UNSIGNED_INT, tri_indices ); } break; case (DRAW_ARRAYS|TRIANGLES): glDrawArraysEXT( GL_TRIANGLES, 0, (numverts-2)*3 ); break; case (ARRAY_ELT|TRIANGLES): if (with_state & MATERIALS) { for (j = i = 0 ; i < num_tri_verts ; i += 600, j++) { GLuint nr = MIN(num_tri_verts-i, 600); GLuint k; glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, col[j]); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, col[j]); glBegin( GL_TRIANGLES ); for (k = 0 ; k < nr ; k++) glArrayElement( tri_indices[i+k] ); glEnd(); } } else { 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 (DRAW_ARRAYS|STRIPS): glDrawArraysEXT( GL_TRIANGLE_STRIP, 0, numverts ); break; case (DRAW_ELTS|STRIPS): glDrawElements( GL_TRIANGLE_STRIP, numverts, GL_UNSIGNED_INT, strip_indices ); break; /* Uses the original arrays (including duplicate elements): */ case (ARRAY_ELT|STRIPS): glBegin( GL_TRIANGLE_STRIP ); for (i = 0 ; i < numverts ; i++) glArrayElement( i ); glEnd(); break; case (DRAW_ARRAYS|POINTS): glDrawArraysEXT( GL_POINTS, 0, numuniq ); break; case (DRAW_ELTS|POINTS): /* can use numuniq with strip_indices as strip_indices[i] == i. */ glDrawElements( GL_POINTS, numuniq, GL_UNSIGNED_INT, strip_indices ); break; case (ARRAY_ELT|POINTS): /* just emit each unique element once: */ glBegin( GL_POINTS ); for (i = 0 ; i < numuniq ; i++) glArrayElement( i ); glEnd(); break; #endif case (GLVERTEX|TRIANGLES): if (with_state & MATERIALS) { for (j = i = 0 ; i < num_tri_verts ; i += 600, j++) { GLuint nr = MIN(num_tri_verts-i, 600); GLuint k; glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, col[j]); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, col[j]); glBegin( GL_TRIANGLES ); for (k = 0 ; k < nr ; k++) { glNormal3fv( &compressed_data[tri_indices[i+k]][3] ); glVertex3fv( &compressed_data[tri_indices[i+k]][0] ); } glEnd(); } } else { glBegin( GL_TRIANGLES ); for (i = 0 ; i < num_tri_verts ; i++) { glNormal3fv( &compressed_data[tri_indices[i]][3] ); glVertex3fv( &compressed_data[tri_indices[i]][0] ); } glEnd(); } break; case (GLVERTEX|POINTS): /* Renders all points, but not in strip order... Shouldn't be a * problem, but people may be confused as to why points are so * much faster in this demo... And why cva doesn't help them... */ glBegin( GL_POINTS ); for ( i = 0 ; i < numuniq ; i++ ) { glNormal3fv( &compressed_data[i][3] ); glVertex3fv( &compressed_data[i][0] ); } glEnd(); break; case (GLVERTEX|STRIPS): glBegin( GL_TRIANGLE_STRIP ); for (i=0;i<numverts;i++) { glNormal3fv( &data[i][3] ); glVertex3fv( &data[i][0] ); } glEnd(); break; default: fprintf(stderr, "unimplemented mode %x...\n", (with_state & (RENDER_STYLE_MASK|PRIMITIVE_MASK))); break; } }