jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 3 | * Display an isosurface of 3-D wind speed volume. |
Keith Whitwell | 44c7393 | 1999-09-03 14:56:40 +0000 | [diff] [blame] | 4 | * |
Brian Paul | ac12609 | 1999-10-21 16:39:06 +0000 | [diff] [blame] | 5 | * Command line options: |
| 6 | * -info print GL implementation information |
| 7 | * |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 8 | * Brian Paul This file in public domain. |
| 9 | */ |
| 10 | |
Keith Whitwell | 44c7393 | 1999-09-03 14:56:40 +0000 | [diff] [blame] | 11 | |
| 12 | /* Keys: |
| 13 | * ===== |
| 14 | * |
| 15 | * - Arrow keys to rotate |
| 16 | * - 's' toggles smooth shading |
| 17 | * - 'l' toggles lighting |
| 18 | * - 'f' toggles fog |
| 19 | * - 'I' and 'i' zoom in and out |
| 20 | * - 'c' toggles a user clip plane |
| 21 | * - 'm' toggles colorful materials in GL_TRIANGLES modes. |
| 22 | * - '+' and '-' move the user clip plane |
| 23 | * |
| 24 | * Other options are available via the popup menu. |
| 25 | */ |
| 26 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 27 | #include <stdio.h> |
| 28 | #include <string.h> |
| 29 | #include <stdlib.h> |
Brian Paul | ac12609 | 1999-10-21 16:39:06 +0000 | [diff] [blame] | 30 | #include <string.h> |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 31 | #include <math.h> |
Karl Schultz | bffae58 | 2001-10-04 19:14:26 +0000 | [diff] [blame] | 32 | #ifdef _WIN32 |
| 33 | #include <windows.h> |
Karl Schultz | 53d30c5 | 2002-10-18 17:47:35 +0000 | [diff] [blame] | 34 | #undef CLIP_MASK |
Karl Schultz | bffae58 | 2001-10-04 19:14:26 +0000 | [diff] [blame] | 35 | #endif |
José Fonseca | 2e61d13 | 2009-01-24 16:39:49 +0000 | [diff] [blame] | 36 | #include <GL/glew.h> |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 37 | #include "GL/glut.h" |
| 38 | |
Brian Paul | 575d24a | 2005-01-09 17:15:41 +0000 | [diff] [blame] | 39 | #include "readtex.h" |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 40 | #define TEXTURE_FILE "../images/reflect.rgb" |
| 41 | |
Gareth Hughes | 735d920 | 2002-01-04 09:47:17 +0000 | [diff] [blame] | 42 | #define LIT 0x00000001 |
| 43 | #define UNLIT 0x00000002 |
| 44 | #define REFLECT 0x00000004 |
| 45 | #define POINT_FILTER 0x00000008 |
| 46 | #define LINEAR_FILTER 0x00000010 |
| 47 | #define GLVERTEX 0x00000020 |
| 48 | #define DRAW_ELTS 0x00000040 |
| 49 | #define DRAW_ARRAYS 0x00000080 |
| 50 | #define ARRAY_ELT 0x00000100 |
| 51 | #define LOCKED 0x00000200 |
| 52 | #define UNLOCKED 0x00000400 |
| 53 | #define IMMEDIATE 0x00000800 |
| 54 | #define DISPLAYLIST 0x00001000 |
| 55 | #define SHADE_SMOOTH 0x00002000 |
| 56 | #define SHADE_FLAT 0x00004000 |
| 57 | #define TRIANGLES 0x00008000 |
| 58 | #define STRIPS 0x00010000 |
| 59 | #define POINTS 0x00020000 |
| 60 | #define USER_CLIP 0x00040000 |
| 61 | #define NO_USER_CLIP 0x00080000 |
| 62 | #define MATERIALS 0x00100000 |
| 63 | #define NO_MATERIALS 0x00200000 |
| 64 | #define FOG 0x00400000 |
| 65 | #define NO_FOG 0x00800000 |
| 66 | #define QUIT 0x01000000 |
| 67 | #define GLINFO 0x02000000 |
| 68 | #define STIPPLE 0x04000000 |
| 69 | #define NO_STIPPLE 0x08000000 |
| 70 | #define POLYGON_FILL 0x10000000 |
| 71 | #define POLYGON_LINE 0x20000000 |
Jakob Bornecrantz | 54e2082 | 2009-02-13 17:53:49 +0100 | [diff] [blame] | 72 | #define POLYGON_POINT 0x40000000 |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 73 | |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 74 | #define LIGHT_MASK (LIT|UNLIT|REFLECT) |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 75 | #define FILTER_MASK (POINT_FILTER|LINEAR_FILTER) |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 76 | #define RENDER_STYLE_MASK (GLVERTEX|DRAW_ARRAYS|DRAW_ELTS|ARRAY_ELT) |
| 77 | #define DLIST_MASK (IMMEDIATE|DISPLAYLIST) |
| 78 | #define LOCK_MASK (LOCKED|UNLOCKED) |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 79 | #define MATERIAL_MASK (MATERIALS|NO_MATERIALS) |
| 80 | #define PRIMITIVE_MASK (TRIANGLES|STRIPS|POINTS) |
| 81 | #define CLIP_MASK (USER_CLIP|NO_USER_CLIP) |
| 82 | #define SHADE_MASK (SHADE_SMOOTH|SHADE_FLAT) |
| 83 | #define FOG_MASK (FOG|NO_FOG) |
| 84 | #define STIPPLE_MASK (STIPPLE|NO_STIPPLE) |
Jakob Bornecrantz | 54e2082 | 2009-02-13 17:53:49 +0100 | [diff] [blame] | 85 | #define POLYGON_MASK (POLYGON_FILL|POLYGON_LINE|POLYGON_POINT) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 86 | |
| 87 | #define MAXVERTS 10000 |
Karl Schultz | 53d30c5 | 2002-10-18 17:47:35 +0000 | [diff] [blame] | 88 | static GLint maxverts = MAXVERTS; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 89 | static float data[MAXVERTS][6]; |
| 90 | static float compressed_data[MAXVERTS][6]; |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 91 | static float expanded_data[MAXVERTS*3][6]; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 92 | static GLuint indices[MAXVERTS]; |
| 93 | static GLuint tri_indices[MAXVERTS*3]; |
Keith Whitwell | b8f9980 | 2001-05-11 15:47:02 +0000 | [diff] [blame] | 94 | static GLuint strip_indices[MAXVERTS]; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 95 | static GLfloat col[100][4]; |
| 96 | static GLint numverts, num_tri_verts, numuniq; |
| 97 | |
| 98 | static GLfloat xrot; |
| 99 | static GLfloat yrot; |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 100 | static GLfloat dist; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 101 | static GLint state, allowed = ~0; |
| 102 | static GLboolean doubleBuffer = GL_TRUE; |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 103 | static GLdouble plane[4]; |
| 104 | static GLuint surf1, dlist_state; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 105 | |
Brian Paul | ac12609 | 1999-10-21 16:39:06 +0000 | [diff] [blame] | 106 | static GLboolean PrintInfo = GL_FALSE; |
| 107 | |
Keith Whitwell | 03b7aee | 2000-03-30 17:58:56 +0000 | [diff] [blame] | 108 | |
| 109 | static GLubyte halftone[] = { |
| 110 | 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, |
| 111 | 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, |
| 112 | 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, |
| 113 | 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, |
| 114 | 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, |
| 115 | 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, |
| 116 | 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, |
| 117 | 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, |
| 118 | 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, |
| 119 | 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, |
| 120 | 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55}; |
| 121 | |
Brian Paul | 36ca6bd | 1999-09-08 22:14:31 +0000 | [diff] [blame] | 122 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 123 | static void read_surface( char *filename ) |
| 124 | { |
| 125 | FILE *f; |
| 126 | |
| 127 | f = fopen(filename,"r"); |
| 128 | if (!f) { |
| 129 | printf("couldn't read %s\n", filename); |
| 130 | exit(1); |
| 131 | } |
| 132 | |
| 133 | numverts = 0; |
Keith Whitwell | 18acf6e | 2001-04-19 13:12:40 +0000 | [diff] [blame] | 134 | while (!feof(f) && numverts<maxverts) { |
Vinson Lee | e81fe08 | 2009-12-26 01:08:26 -0800 | [diff] [blame] | 135 | int result; |
| 136 | result = fscanf( f, "%f %f %f %f %f %f", |
| 137 | &data[numverts][0], &data[numverts][1], &data[numverts][2], |
| 138 | &data[numverts][3], &data[numverts][4], &data[numverts][5] ); |
| 139 | (void) result; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 140 | numverts++; |
| 141 | } |
| 142 | numverts--; |
| 143 | |
| 144 | printf("%d vertices, %d triangles\n", numverts, numverts-2); |
| 145 | fclose(f); |
| 146 | } |
| 147 | |
| 148 | |
| 149 | |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 150 | static void print_flags( const char *msg, GLuint flags ) |
| 151 | { |
| 152 | fprintf(stderr, |
Jakob Bornecrantz | 54e2082 | 2009-02-13 17:53:49 +0100 | [diff] [blame] | 153 | "%s (0x%x): %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 154 | msg, flags, |
| 155 | (flags & GLVERTEX) ? "glVertex, " : "", |
| 156 | (flags & DRAW_ARRAYS) ? "glDrawArrays, " : "", |
| 157 | (flags & DRAW_ELTS) ? "glDrawElements, " : "", |
| 158 | (flags & ARRAY_ELT) ? "glArrayElement, " : "", |
| 159 | (flags & LOCKED) ? "locked arrays, " : "", |
| 160 | (flags & TRIANGLES) ? "GL_TRIANGLES, " : "", |
| 161 | (flags & STRIPS) ? "GL_TRIANGLE_STRIP, " : "", |
| 162 | (flags & POINTS) ? "GL_POINTS, " : "", |
| 163 | (flags & DISPLAYLIST) ? "as a displaylist, " : "", |
| 164 | (flags & LIT) ? "lit, " : "", |
| 165 | (flags & UNLIT) ? "unlit, " : "", |
| 166 | (flags & REFLECT) ? "reflect, " : "", |
| 167 | (flags & SHADE_FLAT) ? "flat-shaded, " : "", |
| 168 | (flags & USER_CLIP) ? "user_clip, " : "", |
| 169 | (flags & MATERIALS) ? "materials, " : "", |
| 170 | (flags & FOG) ? "fog, " : "", |
Gareth Hughes | 735d920 | 2002-01-04 09:47:17 +0000 | [diff] [blame] | 171 | (flags & STIPPLE) ? "stipple, " : "", |
Jakob Bornecrantz | 54e2082 | 2009-02-13 17:53:49 +0100 | [diff] [blame] | 172 | (flags & POLYGON_LINE) ? "polygon mode line, " : "", |
| 173 | (flags & POLYGON_POINT) ? "polygon mode point, " : ""); |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 177 | |
| 178 | struct data_idx { |
| 179 | float *data; |
| 180 | int idx; |
| 181 | int uniq_idx; |
| 182 | }; |
| 183 | |
| 184 | |
| 185 | #define COMPARE_FUNC( AXIS ) \ |
Brian Paul | ac12609 | 1999-10-21 16:39:06 +0000 | [diff] [blame] | 186 | static int compare_axis_##AXIS( const void *a, const void *b ) \ |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 187 | { \ |
| 188 | float t = ( (*(struct data_idx *)a).data[AXIS] - \ |
| 189 | (*(struct data_idx *)b).data[AXIS] ); \ |
| 190 | \ |
| 191 | if (t < 0) return -1; \ |
| 192 | if (t > 0) return 1; \ |
| 193 | return 0; \ |
| 194 | } |
| 195 | |
| 196 | COMPARE_FUNC(0) |
| 197 | COMPARE_FUNC(1) |
| 198 | COMPARE_FUNC(2) |
| 199 | COMPARE_FUNC(3) |
| 200 | COMPARE_FUNC(4) |
| 201 | COMPARE_FUNC(5) |
| 202 | COMPARE_FUNC(6) |
| 203 | |
| 204 | int (*(compare[7]))( const void *a, const void *b ) = |
| 205 | { |
| 206 | compare_axis_0, |
| 207 | compare_axis_1, |
| 208 | compare_axis_2, |
| 209 | compare_axis_3, |
| 210 | compare_axis_4, |
| 211 | compare_axis_5, |
| 212 | compare_axis_6, |
| 213 | }; |
| 214 | |
| 215 | |
| 216 | #define VEC_ELT(f, s, i) (float *)(((char *)f) + s * i) |
| 217 | |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 218 | static int sort_axis( int axis, |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 219 | int vec_size, |
| 220 | int vec_stride, |
| 221 | struct data_idx *indices, |
| 222 | int start, |
| 223 | int finish, |
| 224 | float *out, |
| 225 | int uniq, |
| 226 | const float fudge ) |
| 227 | { |
| 228 | int i; |
| 229 | |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 230 | if (finish-start > 2) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 231 | { |
| 232 | qsort( indices+start, finish-start, sizeof(*indices), compare[axis] ); |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 233 | } |
| 234 | else if (indices[start].data[axis] > indices[start+1].data[axis]) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 235 | { |
| 236 | struct data_idx tmp = indices[start]; |
| 237 | indices[start] = indices[start+1]; |
| 238 | indices[start+1] = tmp; |
| 239 | } |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 240 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 241 | if (axis == vec_size-1) { |
| 242 | for (i = start ; i < finish ; ) { |
| 243 | float max = indices[i].data[axis] + fudge; |
| 244 | float *dest = VEC_ELT(out, vec_stride, uniq); |
| 245 | int j; |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 246 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 247 | for (j = 0 ; j < vec_size ; j++) |
| 248 | dest[j] = indices[i].data[j]; |
| 249 | |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 250 | for ( ; i < finish && max >= indices[i].data[axis]; i++) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 251 | indices[i].uniq_idx = uniq; |
| 252 | |
| 253 | uniq++; |
| 254 | } |
| 255 | } else { |
| 256 | for (i = start ; i < finish ; ) { |
| 257 | int j = i + 1; |
| 258 | float max = indices[i].data[axis] + fudge; |
| 259 | while (j < finish && max >= indices[j].data[axis]) j++; |
| 260 | if (j == i+1) { |
| 261 | float *dest = VEC_ELT(out, vec_stride, uniq); |
| 262 | int k; |
| 263 | |
| 264 | indices[i].uniq_idx = uniq; |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 265 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 266 | for (k = 0 ; k < vec_size ; k++) |
| 267 | dest[k] = indices[i].data[k]; |
| 268 | |
| 269 | uniq++; |
| 270 | } else { |
| 271 | uniq = sort_axis( axis+1, vec_size, vec_stride, |
| 272 | indices, i, j, out, uniq, fudge ); |
| 273 | } |
| 274 | i = j; |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | return uniq; |
| 279 | } |
| 280 | |
| 281 | |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 282 | static void extract_indices1( const struct data_idx *in, unsigned int *out, |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 283 | int n ) |
| 284 | { |
| 285 | int i; |
| 286 | for ( i = 0 ; i < n ; i++ ) { |
| 287 | out[in[i].idx] = in[i].uniq_idx; |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | |
Brian Paul | 36ca6bd | 1999-09-08 22:14:31 +0000 | [diff] [blame] | 292 | static void compactify_arrays(void) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 293 | { |
| 294 | int i; |
| 295 | struct data_idx *ind; |
| 296 | |
| 297 | ind = (struct data_idx *) malloc( sizeof(struct data_idx) * numverts ); |
| 298 | |
| 299 | for (i = 0 ; i < numverts ; i++) { |
| 300 | ind[i].idx = i; |
| 301 | ind[i].data = data[i]; |
| 302 | } |
| 303 | |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 304 | numuniq = sort_axis(0, |
| 305 | sizeof(compressed_data[0])/sizeof(float), |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 306 | sizeof(compressed_data[0]), |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 307 | ind, |
| 308 | 0, |
| 309 | numverts, |
| 310 | (float *)compressed_data, |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 311 | 0, |
| 312 | 1e-6); |
| 313 | |
| 314 | printf("Nr unique vertex/normal pairs: %d\n", numuniq); |
| 315 | |
| 316 | extract_indices1( ind, indices, numverts ); |
| 317 | free( ind ); |
| 318 | } |
| 319 | |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 320 | static void expand_arrays(void) |
| 321 | { |
| 322 | int i; |
| 323 | int parity = 0; |
| 324 | for (i = 2 ; i < numverts ; i++, parity ^= 1) { |
| 325 | int v0 = i-2+parity; |
| 326 | int v1 = i-1-parity; |
| 327 | int v2 = i; |
| 328 | memcpy( expanded_data[(i-2)*3+0], data[v0], sizeof(data[0]) ); |
| 329 | memcpy( expanded_data[(i-2)*3+1], data[v1], sizeof(data[0]) ); |
| 330 | memcpy( expanded_data[(i-2)*3+2], data[v2], sizeof(data[0]) ); |
| 331 | } |
| 332 | } |
| 333 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 334 | static float myrand( float max ) |
| 335 | { |
| 336 | return max*rand()/(RAND_MAX+1.0); |
| 337 | } |
| 338 | |
| 339 | |
| 340 | static void make_tri_indices( void ) |
| 341 | { |
| 342 | unsigned int *v = tri_indices; |
| 343 | unsigned int parity = 0; |
Karl Schultz | 53d30c5 | 2002-10-18 17:47:35 +0000 | [diff] [blame] | 344 | int i, j; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 345 | |
| 346 | for (j=2;j<numverts;j++,parity^=1) { |
| 347 | if (parity) { |
| 348 | *v++ = indices[j-1]; |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 349 | *v++ = indices[j-2]; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 350 | *v++ = indices[j]; |
| 351 | } else { |
| 352 | *v++ = indices[j-2]; |
| 353 | *v++ = indices[j-1]; |
| 354 | *v++ = indices[j]; |
| 355 | } |
| 356 | } |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 357 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 358 | num_tri_verts = v - tri_indices; |
| 359 | printf("num_tri_verts: %d\n", num_tri_verts); |
| 360 | |
| 361 | for (i = j = 0 ; i < num_tri_verts ; i += 600, j++) { |
| 362 | col[j][3] = 1; |
| 363 | col[j][2] = myrand(1); |
| 364 | col[j][1] = myrand(1); |
| 365 | col[j][0] = myrand(1); |
| 366 | } |
Keith Whitwell | b8f9980 | 2001-05-11 15:47:02 +0000 | [diff] [blame] | 367 | |
| 368 | for (i = 0; i < numverts ; i++) |
| 369 | strip_indices[i] = i; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | #define MIN(x,y) (x < y) ? x : y |
| 373 | |
Karl Schultz | 53d30c5 | 2002-10-18 17:47:35 +0000 | [diff] [blame] | 374 | static void draw_surface( unsigned int with_state ) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 375 | { |
Karl Schultz | 53d30c5 | 2002-10-18 17:47:35 +0000 | [diff] [blame] | 376 | GLint i, j; |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 377 | |
| 378 | if (with_state & DISPLAYLIST) { |
| 379 | if ((with_state & (RENDER_STYLE_MASK|PRIMITIVE_MASK|MATERIAL_MASK)) != |
| 380 | dlist_state) { |
| 381 | /* |
| 382 | */ |
| 383 | fprintf(stderr, "rebuilding displaylist\n"); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 384 | |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 385 | if (dlist_state) |
| 386 | glDeleteLists( surf1, 1 ); |
| 387 | |
| 388 | dlist_state = with_state & (RENDER_STYLE_MASK|PRIMITIVE_MASK| |
| 389 | MATERIAL_MASK); |
| 390 | surf1 = glGenLists(1); |
| 391 | glNewList(surf1, GL_COMPILE); |
| 392 | draw_surface( dlist_state ); |
| 393 | glEndList(); |
| 394 | } |
| 395 | |
| 396 | glCallList( surf1 ); |
| 397 | return; |
| 398 | } |
| 399 | |
| 400 | switch (with_state & (RENDER_STYLE_MASK|PRIMITIVE_MASK)) { |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 401 | #ifdef GL_EXT_vertex_array |
| 402 | |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 403 | case (DRAW_ELTS|TRIANGLES): |
Keith Whitwell | 44c7393 | 1999-09-03 14:56:40 +0000 | [diff] [blame] | 404 | if (with_state & MATERIALS) { |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 405 | for (j = i = 0 ; i < num_tri_verts ; i += 600, j++) { |
| 406 | GLuint nr = MIN(num_tri_verts-i, 600); |
| 407 | glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, col[j]); |
| 408 | glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, col[j]); |
| 409 | glDrawElements( GL_TRIANGLES, nr, GL_UNSIGNED_INT, tri_indices+i ); |
| 410 | } |
| 411 | } else { |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 412 | glDrawElements( GL_TRIANGLES, num_tri_verts, GL_UNSIGNED_INT, |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 413 | tri_indices ); |
| 414 | } |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 415 | break; |
| 416 | |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 417 | case (DRAW_ARRAYS|TRIANGLES): |
| 418 | glDrawArraysEXT( GL_TRIANGLES, 0, (numverts-2)*3 ); |
| 419 | break; |
| 420 | |
| 421 | case (ARRAY_ELT|TRIANGLES): |
Keith Whitwell | 44c7393 | 1999-09-03 14:56:40 +0000 | [diff] [blame] | 422 | if (with_state & MATERIALS) { |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 423 | for (j = i = 0 ; i < num_tri_verts ; i += 600, j++) { |
| 424 | GLuint nr = MIN(num_tri_verts-i, 600); |
| 425 | GLuint k; |
| 426 | glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, col[j]); |
| 427 | glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, col[j]); |
| 428 | glBegin( GL_TRIANGLES ); |
| 429 | for (k = 0 ; k < nr ; k++) |
| 430 | glArrayElement( tri_indices[i+k] ); |
| 431 | glEnd(); |
| 432 | } |
| 433 | } else { |
| 434 | glBegin( GL_TRIANGLES ); |
| 435 | for (i = 0 ; i < num_tri_verts ; i++) |
| 436 | glArrayElement( tri_indices[i] ); |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 437 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 438 | glEnd(); |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 439 | } |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 440 | break; |
| 441 | |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 442 | |
| 443 | /* Uses the original arrays (including duplicate elements): |
| 444 | */ |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 445 | case (DRAW_ARRAYS|STRIPS): |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 446 | glDrawArraysEXT( GL_TRIANGLE_STRIP, 0, numverts ); |
| 447 | break; |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 448 | case (DRAW_ELTS|STRIPS): |
Keith Whitwell | b8f9980 | 2001-05-11 15:47:02 +0000 | [diff] [blame] | 449 | glDrawElements( GL_TRIANGLE_STRIP, numverts, |
| 450 | GL_UNSIGNED_INT, strip_indices ); |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 451 | break; |
| 452 | |
| 453 | /* Uses the original arrays (including duplicate elements): |
| 454 | */ |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 455 | case (ARRAY_ELT|STRIPS): |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 456 | glBegin( GL_TRIANGLE_STRIP ); |
| 457 | for (i = 0 ; i < numverts ; i++) |
| 458 | glArrayElement( i ); |
| 459 | glEnd(); |
| 460 | break; |
| 461 | |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 462 | case (DRAW_ARRAYS|POINTS): |
Keith Whitwell | abd5134 | 2001-06-04 15:34:31 +0000 | [diff] [blame] | 463 | glDrawArraysEXT( GL_POINTS, 0, numuniq ); |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 464 | break; |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 465 | case (DRAW_ELTS|POINTS): |
Keith Whitwell | abd5134 | 2001-06-04 15:34:31 +0000 | [diff] [blame] | 466 | /* can use numuniq with strip_indices as strip_indices[i] == i. |
| 467 | */ |
| 468 | glDrawElements( GL_POINTS, numuniq, |
| 469 | GL_UNSIGNED_INT, strip_indices ); |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 470 | break; |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 471 | case (ARRAY_ELT|POINTS): |
Keith Whitwell | abd5134 | 2001-06-04 15:34:31 +0000 | [diff] [blame] | 472 | /* just emit each unique element once: |
| 473 | */ |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 474 | glBegin( GL_POINTS ); |
Keith Whitwell | abd5134 | 2001-06-04 15:34:31 +0000 | [diff] [blame] | 475 | for (i = 0 ; i < numuniq ; i++) |
| 476 | glArrayElement( i ); |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 477 | glEnd(); |
| 478 | break; |
| 479 | #endif |
| 480 | |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 481 | case (GLVERTEX|TRIANGLES): |
Keith Whitwell | 44c7393 | 1999-09-03 14:56:40 +0000 | [diff] [blame] | 482 | if (with_state & MATERIALS) { |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 483 | for (j = i = 0 ; i < num_tri_verts ; i += 600, j++) { |
| 484 | GLuint nr = MIN(num_tri_verts-i, 600); |
| 485 | GLuint k; |
| 486 | glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, col[j]); |
| 487 | glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, col[j]); |
| 488 | glBegin( GL_TRIANGLES ); |
| 489 | for (k = 0 ; k < nr ; k++) { |
| 490 | glNormal3fv( &compressed_data[tri_indices[i+k]][3] ); |
| 491 | glVertex3fv( &compressed_data[tri_indices[i+k]][0] ); |
| 492 | } |
| 493 | glEnd(); |
| 494 | } |
| 495 | } else { |
| 496 | glBegin( GL_TRIANGLES ); |
| 497 | for (i = 0 ; i < num_tri_verts ; i++) { |
| 498 | glNormal3fv( &compressed_data[tri_indices[i]][3] ); |
| 499 | glVertex3fv( &compressed_data[tri_indices[i]][0] ); |
| 500 | } |
| 501 | glEnd(); |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 502 | } |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 503 | break; |
| 504 | |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 505 | case (GLVERTEX|POINTS): |
Keith Whitwell | abd5134 | 2001-06-04 15:34:31 +0000 | [diff] [blame] | 506 | /* Renders all points, but not in strip order... Shouldn't be a |
| 507 | * problem, but people may be confused as to why points are so |
| 508 | * much faster in this demo... And why cva doesn't help them... |
| 509 | */ |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 510 | glBegin( GL_POINTS ); |
Keith Whitwell | abd5134 | 2001-06-04 15:34:31 +0000 | [diff] [blame] | 511 | for ( i = 0 ; i < numuniq ; i++ ) { |
| 512 | glNormal3fv( &compressed_data[i][3] ); |
| 513 | glVertex3fv( &compressed_data[i][0] ); |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 514 | } |
| 515 | glEnd(); |
Keith Whitwell | 44c7393 | 1999-09-03 14:56:40 +0000 | [diff] [blame] | 516 | break; |
| 517 | |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 518 | case (GLVERTEX|STRIPS): |
Keith Whitwell | a9ae89d | 2009-05-31 19:07:21 -0700 | [diff] [blame] | 519 | if (with_state & MATERIALS) { |
| 520 | glBegin( GL_TRIANGLE_STRIP ); |
| 521 | for (i=0;i<numverts;i++) { |
| 522 | if (i % 600 == 0 && i != 0) { |
| 523 | unsigned j = i / 600; |
| 524 | glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, col[j]); |
| 525 | glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, col[j]); |
| 526 | } |
| 527 | glNormal3fv( &data[i][3] ); |
| 528 | glVertex3fv( &data[i][0] ); |
| 529 | } |
| 530 | glEnd(); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 531 | } |
Keith Whitwell | a9ae89d | 2009-05-31 19:07:21 -0700 | [diff] [blame] | 532 | else { |
| 533 | glBegin( GL_TRIANGLE_STRIP ); |
| 534 | for (i=0;i<numverts;i++) { |
| 535 | glNormal3fv( &data[i][3] ); |
| 536 | glVertex3fv( &data[i][0] ); |
| 537 | } |
| 538 | glEnd(); |
| 539 | } |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 540 | break; |
| 541 | |
| 542 | default: |
| 543 | fprintf(stderr, "unimplemented mode %x...\n", |
| 544 | (with_state & (RENDER_STYLE_MASK|PRIMITIVE_MASK))); |
| 545 | break; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 546 | } |
| 547 | } |
| 548 | |
| 549 | |
| 550 | |
| 551 | static void Display(void) |
| 552 | { |
| 553 | glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); |
Keith Whitwell | 44c7393 | 1999-09-03 14:56:40 +0000 | [diff] [blame] | 554 | draw_surface( state ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 555 | glFlush(); |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 556 | if (doubleBuffer) glutSwapBuffers(); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 557 | } |
| 558 | |
Keith Whitwell | 18acf6e | 2001-04-19 13:12:40 +0000 | [diff] [blame] | 559 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 560 | /* KW: only do this when necessary, so CVA can re-use results. |
| 561 | */ |
| 562 | static void set_matrix( void ) |
| 563 | { |
| 564 | glMatrixMode(GL_MODELVIEW); |
| 565 | glLoadIdentity(); |
Keith Whitwell | 44c7393 | 1999-09-03 14:56:40 +0000 | [diff] [blame] | 566 | glTranslatef( 0.0, 0.0, dist ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 567 | glRotatef( yrot, 0.0, 1.0, 0.0 ); |
| 568 | glRotatef( xrot, 1.0, 0.0, 0.0 ); |
| 569 | } |
| 570 | |
| 571 | static void Benchmark( float xdiff, float ydiff ) |
| 572 | { |
| 573 | int startTime, endTime; |
| 574 | int draws; |
| 575 | double seconds, fps, triPerSecond; |
| 576 | |
| 577 | printf("Benchmarking...\n"); |
| 578 | |
| 579 | draws = 0; |
| 580 | startTime = glutGet(GLUT_ELAPSED_TIME); |
| 581 | xrot = 0.0; |
| 582 | do { |
| 583 | xrot += xdiff; |
| 584 | yrot += ydiff; |
| 585 | set_matrix(); |
| 586 | Display(); |
| 587 | draws++; |
| 588 | endTime = glutGet(GLUT_ELAPSED_TIME); |
| 589 | } while (endTime - startTime < 5000); /* 5 seconds */ |
| 590 | |
| 591 | /* Results */ |
| 592 | seconds = (double) (endTime - startTime) / 1000.0; |
| 593 | triPerSecond = (numverts - 2) * draws / seconds; |
| 594 | fps = draws / seconds; |
| 595 | printf("Result: triangles/sec: %g fps: %g\n", triPerSecond, fps); |
| 596 | } |
| 597 | |
| 598 | |
| 599 | static void InitMaterials(void) |
| 600 | { |
| 601 | static float ambient[] = {0.1, 0.1, 0.1, 1.0}; |
| 602 | static float diffuse[] = {0.5, 1.0, 1.0, 1.0}; |
| 603 | static float position0[] = {0.0, 0.0, 20.0, 0.0}; |
| 604 | static float position1[] = {0.0, 0.0, -20.0, 0.0}; |
| 605 | static float front_mat_shininess[] = {60.0}; |
| 606 | static float front_mat_specular[] = {0.2, 0.2, 0.2, 1.0}; |
| 607 | static float front_mat_diffuse[] = {0.5, 0.28, 0.38, 1.0}; |
| 608 | /* |
| 609 | static float back_mat_shininess[] = {60.0}; |
| 610 | static float back_mat_specular[] = {0.5, 0.5, 0.2, 1.0}; |
| 611 | static float back_mat_diffuse[] = {1.0, 1.0, 0.2, 1.0}; |
| 612 | */ |
| 613 | static float lmodel_ambient[] = {1.0, 1.0, 1.0, 1.0}; |
| 614 | static float lmodel_twoside[] = {GL_FALSE}; |
| 615 | |
| 616 | glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); |
| 617 | glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); |
| 618 | glLightfv(GL_LIGHT0, GL_POSITION, position0); |
| 619 | glEnable(GL_LIGHT0); |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 620 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 621 | glLightfv(GL_LIGHT1, GL_AMBIENT, ambient); |
| 622 | glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse); |
| 623 | glLightfv(GL_LIGHT1, GL_POSITION, position1); |
| 624 | glEnable(GL_LIGHT1); |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 625 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 626 | glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); |
| 627 | glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside); |
| 628 | |
| 629 | glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, front_mat_shininess); |
| 630 | glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_mat_specular); |
| 631 | glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, front_mat_diffuse); |
Keith Whitwell | 03b7aee | 2000-03-30 17:58:56 +0000 | [diff] [blame] | 632 | |
| 633 | glPolygonStipple (halftone); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | |
| 637 | |
| 638 | #define UPDATE(o,n,mask) (o&=~mask, o|=n&mask) |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 639 | #define CHANGED(o,n,mask) ((n&mask) && (n&mask) != (o&mask) ) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 640 | |
| 641 | static void ModeMenu(int m) |
| 642 | { |
| 643 | m &= allowed; |
| 644 | |
| 645 | if (!m) return; |
| 646 | |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 647 | if (m==QUIT) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 648 | exit(0); |
| 649 | |
Keith Whitwell | 03b7aee | 2000-03-30 17:58:56 +0000 | [diff] [blame] | 650 | if (m==GLINFO) { |
| 651 | printf("GL_VERSION: %s\n", (char *) glGetString(GL_VERSION)); |
| 652 | printf("GL_EXTENSIONS: %s\n", (char *) glGetString(GL_EXTENSIONS)); |
| 653 | printf("GL_RENDERER: %s\n", (char *) glGetString(GL_RENDERER)); |
| 654 | return; |
| 655 | } |
| 656 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 657 | if (CHANGED(state, m, FILTER_MASK)) { |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 658 | UPDATE(state, m, FILTER_MASK); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 659 | if (m & LINEAR_FILTER) { |
| 660 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 661 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 662 | } else { |
| 663 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 664 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 665 | } |
| 666 | } |
| 667 | |
| 668 | if (CHANGED(state, m, LIGHT_MASK)) { |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 669 | UPDATE(state, m, LIGHT_MASK); |
| 670 | if (m & LIT) { |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 671 | glEnable(GL_LIGHTING); |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 672 | glDisable(GL_TEXTURE_GEN_S); |
| 673 | glDisable(GL_TEXTURE_GEN_T); |
| 674 | glDisable(GL_TEXTURE_2D); |
| 675 | } |
| 676 | else if (m & UNLIT) { |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 677 | glDisable(GL_LIGHTING); |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 678 | glDisable(GL_TEXTURE_GEN_S); |
| 679 | glDisable(GL_TEXTURE_GEN_T); |
| 680 | glDisable(GL_TEXTURE_2D); |
| 681 | } |
| 682 | else if (m & REFLECT) { |
| 683 | glDisable(GL_LIGHTING); |
| 684 | glEnable(GL_TEXTURE_GEN_S); |
| 685 | glEnable(GL_TEXTURE_GEN_T); |
| 686 | glEnable(GL_TEXTURE_2D); |
| 687 | } |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | if (CHANGED(state, m, SHADE_MASK)) { |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 691 | UPDATE(state, m, SHADE_MASK); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 692 | if (m & SHADE_SMOOTH) |
| 693 | glShadeModel(GL_SMOOTH); |
| 694 | else |
| 695 | glShadeModel(GL_FLAT); |
| 696 | } |
| 697 | |
| 698 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 699 | if (CHANGED(state, m, CLIP_MASK)) { |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 700 | UPDATE(state, m, CLIP_MASK); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 701 | if (m & USER_CLIP) { |
| 702 | glEnable(GL_CLIP_PLANE0); |
| 703 | } else { |
| 704 | glDisable(GL_CLIP_PLANE0); |
| 705 | } |
| 706 | } |
| 707 | |
Keith Whitwell | 44c7393 | 1999-09-03 14:56:40 +0000 | [diff] [blame] | 708 | if (CHANGED(state, m, FOG_MASK)) { |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 709 | UPDATE(state, m, FOG_MASK); |
Gareth Hughes | 735d920 | 2002-01-04 09:47:17 +0000 | [diff] [blame] | 710 | if (m & FOG) { |
Keith Whitwell | 44c7393 | 1999-09-03 14:56:40 +0000 | [diff] [blame] | 711 | glEnable(GL_FOG); |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 712 | } |
Gareth Hughes | 735d920 | 2002-01-04 09:47:17 +0000 | [diff] [blame] | 713 | else { |
Keith Whitwell | 44c7393 | 1999-09-03 14:56:40 +0000 | [diff] [blame] | 714 | glDisable(GL_FOG); |
Keith Whitwell | 44c7393 | 1999-09-03 14:56:40 +0000 | [diff] [blame] | 715 | } |
| 716 | } |
| 717 | |
Keith Whitwell | 03b7aee | 2000-03-30 17:58:56 +0000 | [diff] [blame] | 718 | if (CHANGED(state, m, STIPPLE_MASK)) { |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 719 | UPDATE(state, m, STIPPLE_MASK); |
Gareth Hughes | 735d920 | 2002-01-04 09:47:17 +0000 | [diff] [blame] | 720 | if (m & STIPPLE) { |
Keith Whitwell | 03b7aee | 2000-03-30 17:58:56 +0000 | [diff] [blame] | 721 | glEnable(GL_POLYGON_STIPPLE); |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 722 | } |
Gareth Hughes | 735d920 | 2002-01-04 09:47:17 +0000 | [diff] [blame] | 723 | else { |
Keith Whitwell | 03b7aee | 2000-03-30 17:58:56 +0000 | [diff] [blame] | 724 | glDisable(GL_POLYGON_STIPPLE); |
Keith Whitwell | 03b7aee | 2000-03-30 17:58:56 +0000 | [diff] [blame] | 725 | } |
| 726 | } |
| 727 | |
Gareth Hughes | 735d920 | 2002-01-04 09:47:17 +0000 | [diff] [blame] | 728 | if (CHANGED(state, m, POLYGON_MASK)) { |
| 729 | UPDATE(state, m, POLYGON_MASK); |
| 730 | if (m & POLYGON_FILL) { |
| 731 | glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); |
| 732 | } |
Jakob Bornecrantz | 54e2082 | 2009-02-13 17:53:49 +0100 | [diff] [blame] | 733 | else if (m & POLYGON_LINE) { |
Gareth Hughes | 735d920 | 2002-01-04 09:47:17 +0000 | [diff] [blame] | 734 | glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); |
| 735 | } |
Jakob Bornecrantz | 54e2082 | 2009-02-13 17:53:49 +0100 | [diff] [blame] | 736 | else { |
| 737 | glPolygonMode(GL_FRONT_AND_BACK, GL_POINT); |
| 738 | } |
Gareth Hughes | 735d920 | 2002-01-04 09:47:17 +0000 | [diff] [blame] | 739 | } |
| 740 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 741 | #ifdef GL_EXT_vertex_array |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 742 | if (CHANGED(state, m, (LOCK_MASK|RENDER_STYLE_MASK|PRIMITIVE_MASK))) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 743 | { |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 744 | if (m & (PRIMITIVE_MASK)) { |
| 745 | UPDATE(state, m, (PRIMITIVE_MASK)); |
| 746 | } |
| 747 | |
| 748 | if (m & (RENDER_STYLE_MASK)) { |
| 749 | UPDATE(state, m, (RENDER_STYLE_MASK)); |
| 750 | } |
| 751 | |
| 752 | if (m & LOCK_MASK) { |
| 753 | UPDATE(state, m, (LOCK_MASK)); |
| 754 | } |
| 755 | |
| 756 | |
| 757 | print_flags("primitive", state & PRIMITIVE_MASK); |
| 758 | print_flags("render style", state & RENDER_STYLE_MASK); |
| 759 | |
Keith Whitwell | abd5134 | 2001-06-04 15:34:31 +0000 | [diff] [blame] | 760 | if ((state & PRIMITIVE_MASK) != STRIPS && |
| 761 | ((state & RENDER_STYLE_MASK) == DRAW_ELTS || |
| 762 | (state & RENDER_STYLE_MASK) == ARRAY_ELT || |
| 763 | (state & PRIMITIVE_MASK) == POINTS)) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 764 | { |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 765 | fprintf(stderr, "enabling small arrays\n"); |
Keith Whitwell | abd5134 | 2001-06-04 15:34:31 +0000 | [diff] [blame] | 766 | /* Rendering any primitive with draw-element/array-element |
| 767 | * --> Can't do strips here as ordering has been lost in |
| 768 | * compaction process... |
| 769 | */ |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 770 | glVertexPointerEXT( 3, GL_FLOAT, sizeof(data[0]), numuniq, |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 771 | compressed_data ); |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 772 | glNormalPointerEXT( GL_FLOAT, sizeof(data[0]), numuniq, |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 773 | &compressed_data[0][3]); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 774 | #ifdef GL_EXT_compiled_vertex_array |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 775 | if (allowed & LOCKED) { |
| 776 | if (state & LOCKED) { |
| 777 | glLockArraysEXT( 0, numuniq ); |
| 778 | } else { |
| 779 | glUnlockArraysEXT(); |
| 780 | } |
Keith Whitwell | 03b7aee | 2000-03-30 17:58:56 +0000 | [diff] [blame] | 781 | } |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 782 | #endif |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 783 | } |
Keith Whitwell | abd5134 | 2001-06-04 15:34:31 +0000 | [diff] [blame] | 784 | else if ((state & PRIMITIVE_MASK) == TRIANGLES && |
| 785 | (state & RENDER_STYLE_MASK) == DRAW_ARRAYS) { |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 786 | fprintf(stderr, "enabling big arrays\n"); |
Keith Whitwell | abd5134 | 2001-06-04 15:34:31 +0000 | [diff] [blame] | 787 | /* Only get here for TRIANGLES and drawarrays |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 788 | */ |
| 789 | glVertexPointerEXT( 3, GL_FLOAT, sizeof(data[0]), (numverts-2) * 3, |
| 790 | expanded_data ); |
| 791 | glNormalPointerEXT( GL_FLOAT, sizeof(data[0]), (numverts-2) * 3, |
| 792 | &expanded_data[0][3]); |
| 793 | |
| 794 | #ifdef GL_EXT_compiled_vertex_array |
| 795 | if (allowed & LOCKED) { |
| 796 | if (state & LOCKED) { |
| 797 | glLockArraysEXT( 0, (numverts-2)*3 ); |
| 798 | } else { |
| 799 | glUnlockArraysEXT(); |
| 800 | } |
| 801 | } |
| 802 | #endif |
| 803 | } |
Keith Whitwell | abd5134 | 2001-06-04 15:34:31 +0000 | [diff] [blame] | 804 | else { |
| 805 | fprintf(stderr, "enabling normal arrays\n"); |
| 806 | glVertexPointerEXT( 3, GL_FLOAT, sizeof(data[0]), numverts, data ); |
| 807 | glNormalPointerEXT( GL_FLOAT, sizeof(data[0]), numverts, &data[0][3]); |
| 808 | #ifdef GL_EXT_compiled_vertex_array |
| 809 | if (allowed & LOCKED) { |
| 810 | if (state & LOCKED) { |
| 811 | glLockArraysEXT( 0, numverts ); |
| 812 | } else { |
| 813 | glUnlockArraysEXT(); |
| 814 | } |
| 815 | } |
| 816 | #endif |
| 817 | } |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 818 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 819 | } |
| 820 | #endif |
| 821 | |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 822 | |
| 823 | if (m & DLIST_MASK) { |
| 824 | UPDATE(state, m, DLIST_MASK); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 825 | } |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 826 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 827 | if (m & MATERIAL_MASK) { |
| 828 | UPDATE(state, m, MATERIAL_MASK); |
| 829 | } |
| 830 | |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 831 | print_flags("new flags", state); |
| 832 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 833 | glutPostRedisplay(); |
| 834 | } |
| 835 | |
| 836 | |
| 837 | |
Brian Paul | ac12609 | 1999-10-21 16:39:06 +0000 | [diff] [blame] | 838 | static void Init(int argc, char *argv[]) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 839 | { |
Keith Whitwell | 44c7393 | 1999-09-03 14:56:40 +0000 | [diff] [blame] | 840 | GLfloat fogColor[4] = {0.5,1.0,0.5,1.0}; |
| 841 | |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 842 | xrot = 0; |
| 843 | yrot = 0; |
| 844 | dist = -6; |
| 845 | plane[0] = 1.0; |
| 846 | plane[1] = 0.0; |
| 847 | plane[2] = -1.0; |
| 848 | plane[3] = 0.0; |
| 849 | |
Keith Whitwell | 03b7aee | 2000-03-30 17:58:56 +0000 | [diff] [blame] | 850 | glClearColor(0.0, 0.0, 1.0, 0.0); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 851 | glEnable( GL_DEPTH_TEST ); |
Brian Paul | 820436f | 2009-07-08 13:58:30 -0600 | [diff] [blame] | 852 | glEnableClientState( GL_VERTEX_ARRAY ); |
| 853 | glEnableClientState( GL_NORMAL_ARRAY ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 854 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 855 | glMatrixMode(GL_PROJECTION); |
| 856 | glLoadIdentity(); |
| 857 | glFrustum( -1.0, 1.0, -1.0, 1.0, 5, 25 ); |
| 858 | |
| 859 | glMatrixMode(GL_MODELVIEW); |
| 860 | glLoadIdentity(); |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 861 | glClipPlane(GL_CLIP_PLANE0, plane); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 862 | |
Keith Whitwell | b8f9980 | 2001-05-11 15:47:02 +0000 | [diff] [blame] | 863 | InitMaterials(); |
| 864 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 865 | set_matrix(); |
| 866 | |
Keith Whitwell | 03b7aee | 2000-03-30 17:58:56 +0000 | [diff] [blame] | 867 | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 868 | glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); |
| 869 | |
| 870 | glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); |
| 871 | glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); |
| 872 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 873 | |
Keith Whitwell | 44c7393 | 1999-09-03 14:56:40 +0000 | [diff] [blame] | 874 | /* Green fog is easy to see */ |
| 875 | glFogi(GL_FOG_MODE,GL_EXP2); |
| 876 | glFogfv(GL_FOG_COLOR,fogColor); |
| 877 | glFogf(GL_FOG_DENSITY,0.15); |
| 878 | glHint(GL_FOG_HINT,GL_DONT_CARE); |
| 879 | |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 880 | { |
| 881 | static int firsttime = 1; |
| 882 | if (firsttime) { |
| 883 | firsttime = 0; |
| 884 | compactify_arrays(); |
| 885 | expand_arrays(); |
| 886 | make_tri_indices(); |
Keith Whitwell | 44c7393 | 1999-09-03 14:56:40 +0000 | [diff] [blame] | 887 | |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 888 | if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) { |
| 889 | printf("Error: couldn't load texture image\n"); |
| 890 | exit(1); |
| 891 | } |
| 892 | } |
| 893 | } |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 894 | |
| 895 | ModeMenu(SHADE_SMOOTH| |
| 896 | LIT| |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 897 | POINT_FILTER| |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 898 | NO_USER_CLIP| |
| 899 | NO_MATERIALS| |
Keith Whitwell | 44c7393 | 1999-09-03 14:56:40 +0000 | [diff] [blame] | 900 | NO_FOG| |
Keith Whitwell | 03b7aee | 2000-03-30 17:58:56 +0000 | [diff] [blame] | 901 | NO_STIPPLE| |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 902 | IMMEDIATE| |
| 903 | STRIPS| |
| 904 | UNLOCKED| |
Keith Whitwell | 44c7393 | 1999-09-03 14:56:40 +0000 | [diff] [blame] | 905 | GLVERTEX); |
Brian Paul | ac12609 | 1999-10-21 16:39:06 +0000 | [diff] [blame] | 906 | |
| 907 | if (PrintInfo) { |
| 908 | printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); |
| 909 | printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); |
| 910 | printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); |
| 911 | printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); |
| 912 | } |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | |
| 916 | |
| 917 | static void Reshape(int width, int height) |
| 918 | { |
| 919 | glViewport(0, 0, (GLint)width, (GLint)height); |
| 920 | } |
| 921 | |
| 922 | |
| 923 | |
| 924 | static void Key( unsigned char key, int x, int y ) |
| 925 | { |
Brian Paul | 36ca6bd | 1999-09-08 22:14:31 +0000 | [diff] [blame] | 926 | (void) x; |
| 927 | (void) y; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 928 | switch (key) { |
Keith Whitwell | 44c7393 | 1999-09-03 14:56:40 +0000 | [diff] [blame] | 929 | case 27: |
| 930 | exit(0); |
| 931 | case 'f': |
| 932 | ModeMenu((state ^ FOG_MASK) & FOG_MASK); |
| 933 | break; |
| 934 | case 's': |
| 935 | ModeMenu((state ^ SHADE_MASK) & SHADE_MASK); |
| 936 | break; |
Keith Whitwell | 03b7aee | 2000-03-30 17:58:56 +0000 | [diff] [blame] | 937 | case 't': |
| 938 | ModeMenu((state ^ STIPPLE_MASK) & STIPPLE_MASK); |
| 939 | break; |
Keith Whitwell | 44c7393 | 1999-09-03 14:56:40 +0000 | [diff] [blame] | 940 | case 'l': |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 941 | ModeMenu((state ^ LIGHT_MASK) & (LIT|UNLIT)); |
Keith Whitwell | 44c7393 | 1999-09-03 14:56:40 +0000 | [diff] [blame] | 942 | break; |
| 943 | case 'm': |
| 944 | ModeMenu((state ^ MATERIAL_MASK) & MATERIAL_MASK); |
| 945 | break; |
| 946 | case 'c': |
| 947 | ModeMenu((state ^ CLIP_MASK) & CLIP_MASK); |
| 948 | break; |
Keith Whitwell | 03b7aee | 2000-03-30 17:58:56 +0000 | [diff] [blame] | 949 | case 'v': |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 950 | ModeMenu((LOCKED|IMMEDIATE|DRAW_ELTS|TRIANGLES) & allowed); |
Keith Whitwell | 03b7aee | 2000-03-30 17:58:56 +0000 | [diff] [blame] | 951 | break; |
| 952 | case 'V': |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 953 | ModeMenu(UNLOCKED|IMMEDIATE|GLVERTEX|STRIPS); |
Keith Whitwell | 03b7aee | 2000-03-30 17:58:56 +0000 | [diff] [blame] | 954 | break; |
Keith Whitwell | 44c7393 | 1999-09-03 14:56:40 +0000 | [diff] [blame] | 955 | case 'b': |
| 956 | Benchmark(5.0, 0); |
| 957 | break; |
| 958 | case 'B': |
| 959 | Benchmark(0, 5.0); |
| 960 | break; |
| 961 | case 'i': |
| 962 | dist += .25; |
| 963 | set_matrix(); |
| 964 | glutPostRedisplay(); |
| 965 | break; |
| 966 | case 'I': |
| 967 | dist -= .25; |
| 968 | set_matrix(); |
| 969 | glutPostRedisplay(); |
| 970 | break; |
| 971 | case '-': |
| 972 | case '_': |
| 973 | plane[3] += 2.0; |
| 974 | glMatrixMode(GL_MODELVIEW); |
| 975 | glLoadIdentity(); |
| 976 | glClipPlane(GL_CLIP_PLANE0, plane); |
| 977 | set_matrix(); |
| 978 | glutPostRedisplay(); |
| 979 | break; |
| 980 | case '+': |
| 981 | case '=': |
| 982 | plane[3] -= 2.0; |
| 983 | glMatrixMode(GL_MODELVIEW); |
| 984 | glLoadIdentity(); |
| 985 | glClipPlane(GL_CLIP_PLANE0, plane); |
| 986 | set_matrix(); |
| 987 | glutPostRedisplay(); |
| 988 | break; |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 989 | case ' ': |
| 990 | Init(0,0); |
| 991 | break; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 992 | } |
| 993 | } |
| 994 | |
| 995 | |
| 996 | static void SpecialKey( int key, int x, int y ) |
| 997 | { |
Brian Paul | 36ca6bd | 1999-09-08 22:14:31 +0000 | [diff] [blame] | 998 | (void) x; |
| 999 | (void) y; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1000 | switch (key) { |
| 1001 | case GLUT_KEY_LEFT: |
| 1002 | yrot -= 15.0; |
| 1003 | break; |
| 1004 | case GLUT_KEY_RIGHT: |
| 1005 | yrot += 15.0; |
| 1006 | break; |
| 1007 | case GLUT_KEY_UP: |
| 1008 | xrot += 15.0; |
| 1009 | break; |
| 1010 | case GLUT_KEY_DOWN: |
| 1011 | xrot -= 15.0; |
| 1012 | break; |
| 1013 | default: |
| 1014 | return; |
| 1015 | } |
| 1016 | set_matrix(); |
| 1017 | glutPostRedisplay(); |
| 1018 | } |
| 1019 | |
| 1020 | |
| 1021 | |
| 1022 | static GLint Args(int argc, char **argv) |
| 1023 | { |
| 1024 | GLint i; |
| 1025 | GLint mode = 0; |
| 1026 | |
| 1027 | for (i = 1; i < argc; i++) { |
| 1028 | if (strcmp(argv[i], "-sb") == 0) { |
| 1029 | doubleBuffer = GL_FALSE; |
| 1030 | } |
| 1031 | else if (strcmp(argv[i], "-db") == 0) { |
| 1032 | doubleBuffer = GL_TRUE; |
| 1033 | } |
Brian Paul | ac12609 | 1999-10-21 16:39:06 +0000 | [diff] [blame] | 1034 | else if (strcmp(argv[i], "-info") == 0) { |
| 1035 | PrintInfo = GL_TRUE; |
| 1036 | } |
Keith Whitwell | 18acf6e | 2001-04-19 13:12:40 +0000 | [diff] [blame] | 1037 | else if (strcmp(argv[i], "-10") == 0) { |
| 1038 | maxverts = 10; |
| 1039 | } |
| 1040 | else if (strcmp(argv[i], "-100") == 0) { |
| 1041 | maxverts = 100; |
| 1042 | } |
| 1043 | else if (strcmp(argv[i], "-1000") == 0) { |
| 1044 | maxverts = 1000; |
| 1045 | } |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1046 | else { |
| 1047 | printf("%s (Bad option).\n", argv[i]); |
| 1048 | return QUIT; |
| 1049 | } |
| 1050 | } |
| 1051 | |
| 1052 | return mode; |
| 1053 | } |
| 1054 | |
| 1055 | int main(int argc, char **argv) |
| 1056 | { |
| 1057 | GLenum type; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1058 | |
| 1059 | GLuint arg_mode = Args(argc, argv); |
| 1060 | |
| 1061 | if (arg_mode & QUIT) |
| 1062 | exit(0); |
| 1063 | |
| 1064 | read_surface( "isosurf.dat" ); |
| 1065 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1066 | glutInitWindowSize(400, 400); |
Brian Paul | 263f432 | 2009-12-18 08:12:55 -0700 | [diff] [blame] | 1067 | glutInit( &argc, argv); |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 1068 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1069 | type = GLUT_DEPTH; |
| 1070 | type |= GLUT_RGB; |
| 1071 | type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; |
| 1072 | glutInitDisplayMode(type); |
| 1073 | |
| 1074 | if (glutCreateWindow("Isosurface") <= 0) { |
| 1075 | exit(0); |
| 1076 | } |
| 1077 | |
José Fonseca | efdb779 | 2009-01-24 16:47:50 +0000 | [diff] [blame] | 1078 | glewInit(); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1079 | |
José Fonseca | efdb779 | 2009-01-24 16:47:50 +0000 | [diff] [blame] | 1080 | /* Make sure server supports the vertex array extension */ |
| 1081 | if (!GLEW_EXT_vertex_array) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1082 | { |
| 1083 | printf("Vertex arrays not supported by this renderer\n"); |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 1084 | allowed &= ~(LOCKED|DRAW_ARRAYS|DRAW_ELTS|ARRAY_ELT); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1085 | } |
José Fonseca | efdb779 | 2009-01-24 16:47:50 +0000 | [diff] [blame] | 1086 | else if (!GLEW_EXT_compiled_vertex_array) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1087 | { |
| 1088 | printf("Compiled vertex arrays not supported by this renderer\n"); |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 1089 | allowed &= ~LOCKED; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1090 | } |
| 1091 | |
Brian Paul | ac12609 | 1999-10-21 16:39:06 +0000 | [diff] [blame] | 1092 | Init(argc, argv); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1093 | ModeMenu(arg_mode); |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 1094 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1095 | glutCreateMenu(ModeMenu); |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 1096 | glutAddMenuEntry("GL info", GLINFO); |
| 1097 | glutAddMenuEntry("", 0); |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 1098 | glutAddMenuEntry("Lit", LIT); |
| 1099 | glutAddMenuEntry("Unlit", UNLIT); |
| 1100 | glutAddMenuEntry("Reflect", REFLECT); |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 1101 | glutAddMenuEntry("", 0); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1102 | glutAddMenuEntry("Smooth", SHADE_SMOOTH); |
| 1103 | glutAddMenuEntry("Flat", SHADE_FLAT); |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 1104 | glutAddMenuEntry("", 0); |
Keith Whitwell | 44c7393 | 1999-09-03 14:56:40 +0000 | [diff] [blame] | 1105 | glutAddMenuEntry("Fog", FOG); |
| 1106 | glutAddMenuEntry("No Fog", NO_FOG); |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 1107 | glutAddMenuEntry("", 0); |
Keith Whitwell | 03b7aee | 2000-03-30 17:58:56 +0000 | [diff] [blame] | 1108 | glutAddMenuEntry("Stipple", STIPPLE); |
| 1109 | glutAddMenuEntry("No Stipple", NO_STIPPLE); |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 1110 | glutAddMenuEntry("", 0); |
Gareth Hughes | 735d920 | 2002-01-04 09:47:17 +0000 | [diff] [blame] | 1111 | glutAddMenuEntry("Polygon Mode Fill", POLYGON_FILL); |
| 1112 | glutAddMenuEntry("Polygon Mode Line", POLYGON_LINE); |
Jakob Bornecrantz | 54e2082 | 2009-02-13 17:53:49 +0100 | [diff] [blame] | 1113 | glutAddMenuEntry("Polygon Mode Points", POLYGON_POINT); |
Gareth Hughes | 735d920 | 2002-01-04 09:47:17 +0000 | [diff] [blame] | 1114 | glutAddMenuEntry("", 0); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1115 | glutAddMenuEntry("Point Filtered", POINT_FILTER); |
| 1116 | glutAddMenuEntry("Linear Filtered", LINEAR_FILTER); |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 1117 | glutAddMenuEntry("", 0); |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 1118 | glutAddMenuEntry("GL_TRIANGLES", TRIANGLES); |
| 1119 | glutAddMenuEntry("GL_TRIANGLE_STRIPS", STRIPS); |
| 1120 | glutAddMenuEntry("GL_POINTS", POINTS); |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 1121 | glutAddMenuEntry("", 0); |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 1122 | glutAddMenuEntry("Displaylist", DISPLAYLIST); |
| 1123 | glutAddMenuEntry("Immediate", IMMEDIATE); |
Gareth Hughes | c851646 | 2001-01-06 20:38:03 +0000 | [diff] [blame] | 1124 | glutAddMenuEntry("", 0); |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 1125 | if (allowed & LOCKED) { |
| 1126 | glutAddMenuEntry("Locked Arrays (CVA)", LOCKED); |
| 1127 | glutAddMenuEntry("Unlocked Arrays", UNLOCKED); |
| 1128 | glutAddMenuEntry("", 0); |
| 1129 | } |
| 1130 | glutAddMenuEntry("glVertex", GLVERTEX); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1131 | if (allowed & DRAW_ARRAYS) { |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 1132 | glutAddMenuEntry("glDrawElements", DRAW_ELTS); |
| 1133 | glutAddMenuEntry("glDrawArrays", DRAW_ARRAYS); |
| 1134 | glutAddMenuEntry("glArrayElement", ARRAY_ELT); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1135 | } |
Keith Whitwell | 5759f53 | 2001-05-11 12:08:15 +0000 | [diff] [blame] | 1136 | glutAddMenuEntry("", 0); |
| 1137 | glutAddMenuEntry("Quit", QUIT); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1138 | glutAttachMenu(GLUT_RIGHT_BUTTON); |
| 1139 | |
| 1140 | glutReshapeFunc(Reshape); |
| 1141 | glutKeyboardFunc(Key); |
| 1142 | glutSpecialFunc(SpecialKey); |
| 1143 | glutDisplayFunc(Display); |
Keith Whitwell | 03b7aee | 2000-03-30 17:58:56 +0000 | [diff] [blame] | 1144 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1145 | glutMainLoop(); |
| 1146 | return 0; |
| 1147 | } |