File: softshadow2.c

package info (click to toggle)
glut 3.7-14
  • links: PTS
  • area: main
  • in suites: woody
  • size: 12,556 kB
  • ctags: 45,170
  • sloc: ansic: 148,716; makefile: 35,208; ada: 2,062; yacc: 473; fortran: 290; lex: 131; csh: 51; sed: 49; sh: 33
file content (632 lines) | stat: -rw-r--r-- 18,039 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632

/* softshadow2.c - by Simon Hui, 3Dfx Interactive */

/* Soft shadows using a shadow texture per polygon.  Based on an algorithm   */
/* described by Paul Heckbert and Michael Herf of CMU; see their web site    */
/* http://www.cs.cmu.edu/ph/shadow.html for details.                         */
/*                                                                           */
/* This program shows two methods of using precomputed, per-polygon textures */
/* to display soft shadows.  The first method is a simplified version of     */
/* Heckbert and Herf's algorithm: for each polygon a texture is created that */
/* encodes the full radiance, including illumination and shadows, of the     */
/* polygon. The texture is created in a preprocessing step by rendering the  */
/* entire scene onto the polygon from the point of view of the light. The    */
/* advantage of this method is that the scene can be rerendered quickly (if  */
/* only the eye moves and the scene is static), since all lighting effects   */
/* have been precomputed and encoded in the texture. This method requires    */
/* GL_RGB textures.                                                          */
/*                                                                           */
/* The second method uses the texture as an occlusion map: the texels        */
/* encode only the amount of occlusion by shadowing objects, not the full    */
/* radiance.  The texture is then used to modulate the lighting of the       */
/* polygon during the rendering pass.  This has the disadvantage of          */
/* requiring OpenGL lighting during scene rendering, but it does retain some */
/* of the benefit of the first method in that all shadow effects are         */
/* precomputed. This method requires GL_LUMINANCE textures.                  */
/*                                                                           */
/* The reason for including the occlusion map method is that some OpenGL     */
/* implementations support GL_RGB textures with low color resolution,        */
/* resulting in noticeable banding when using radiance maps.  However, these */
/* implementations may support a higher color resolution for GL_LUMINANCE    */
/* textures.                                                                 */
/*                                                                           */
/* To use occlusion maps instead of rediance maps, run this program with     */
/* "-o" on the command line.                                                 */

#include <GL/glut.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#if !defined(GL_VERSION_1_1) && !defined(GL_VERSION_1_2)
#define glBindTexture glBindTextureEXT
#define glCopyTexImage2D glCopyTexImage2DEXT
#endif

/* whether to use radiance maps or occlusion maps */
static GLboolean radianceMap = GL_TRUE;

static GLint winxsize = 480, winysize = 480;
static GLint texxsize = 128, texysize = 128;

/* texture object names */
const GLuint floorTexture = 1;
const GLuint shadowTextures = 2;

static GLfloat lightpos[4] = { 70.f, 70.f, -320.f, 1.f };

/* number of shadow textures to make and use */
static GLint numShadowTex;

/* list of polygons that have shadow textures */
GLfloat pts[][4][3] = {
  /* floor */
  -100.f, -100.f, -320.f,
  -100.f, -100.f, -520.f,
   100.f, -100.f, -320.f,
   100.f, -100.f, -520.f,

  /* left wall */
  -100.f, -100.f, -320.f,
  -100.f,  100.f, -320.f,
  -100.f, -100.f, -520.f,
  -100.f,  100.f, -520.f,

  /* back wall */
  -100.f, -100.f, -520.f,
  -100.f,  100.f, -520.f,
   100.f, -100.f, -520.f,
   100.f,  100.f, -520.f,

  /* right wall */
   100.f, -100.f, -520.f,
   100.f,  100.f, -520.f,
   100.f, -100.f, -320.f,
   100.f,  100.f, -320.f,

  /* ceiling */
  -100.f,  100.f, -520.f,
  -100.f,  100.f, -320.f,
   100.f,  100.f, -520.f,
   100.f,  100.f, -320.f,

  /* blue panel */
   -60.f,  -40.f, -400.f,
   -60.f,   70.f, -400.f,
   -30.f,  -40.f, -480.f,
   -30.f,   70.f, -480.f,

  /* yellow panel */
   -40.f,  -50.f, -400.f,
   -40.f,   50.f, -400.f,
   -10.f,  -50.f, -450.f,
   -10.f,   50.f, -450.f,

  /* red panel */
   -20.f,  -60.f, -400.f,
   -20.f,   30.f, -400.f,
    10.f,  -60.f, -420.f,
    10.f,   30.f, -420.f,

  /* green panel */
     0.f,  -70.f, -400.f,
     0.f,   10.f, -400.f,
    30.f,  -70.f, -395.f,
    30.f,   10.f, -395.f,
};

GLfloat materials[][4] = {
  1.0f, 1.0f, 1.0f, 1.0f, /* floor        */
  1.0f, 1.0f, 1.0f, 1.0f, /* left wall    */
  1.0f, 1.0f, 1.0f, 1.0f, /* back wall    */
  1.0f, 1.0f, 1.0f, 1.0f, /* right wall   */
  1.0f, 1.0f, 1.0f, 1.0f, /* ceiling      */
  0.2f, 0.5f, 1.0f, 1.0f, /* blue panel   */
  1.0f, 0.6f, 0.0f, 1.0f, /* yellow panel */
  1.0f, 0.2f, 0.2f, 1.0f, /* red panel    */
  0.3f, 0.9f, 0.6f, 1.0f, /* green panel  */
};

/* some simple vector utility routines */

void
vcopy(GLfloat a[3], GLfloat b[3])
{
  b[0] = a[0];
  b[1] = a[1];
  b[2] = a[2];
}

void
vnormalize(GLfloat v[3])
{
  float m = sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
  v[0] /= m;
  v[1] /= m;
  v[2] /= m;
}

void
vadd(GLfloat a[3], GLfloat b[3], GLfloat c[3])
{
  c[0] = a[0] + b[0];
  c[1] = a[1] + b[1];
  c[2] = a[2] + b[2];
}

void
vsub(GLfloat a[3], GLfloat b[3], GLfloat c[3])
{
  c[0] = a[0] - b[0];
  c[1] = a[1] - b[1];
  c[2] = a[2] - b[2];
}

void
vcross(GLfloat a[3], GLfloat b[3], GLfloat c[3])
{
  c[0] = a[1] * b[2] - a[2] * b[1];
  c[1] = -(a[0] * b[2] - a[2] * b[0]);
  c[2] = a[0] * b[1] - a[1] * b[0];
}

float
vdot(GLfloat a[3], GLfloat b[3])
{
  return (a[0]*b[0] + a[1]*b[1] + a[2]*b[2]);
}

void
findNormal(GLfloat pts[][3], GLfloat normal[3]) {
  GLfloat a[3], b[3];
  
  vsub(pts[1], pts[0], a);
  vsub(pts[2], pts[0], b);
  vcross(b, a, normal);
  vnormalize(normal);
}

static GLfloat origin[4] = { 0.f, 0.f, 0.f, 1.f };
static GLfloat black[4] = { 0.f, 0.f, 0.f, 1.f };
static GLfloat ambient[4] = { 0.2f, 0.2f, 0.2f, 1.f };

void
make_shadow_texture(int index, GLfloat eyept[3], GLfloat dx, GLfloat dy)
{
  GLfloat xaxis[3], yaxis[3], zaxis[3];
  GLfloat cov[3]; /* center of view */
  GLfloat pte[3]; /* plane to eye */
  GLfloat eye[3];
  GLfloat tmp[3], normal[3], dist;
  GLfloat (*qpts)[3] = pts[index];
  GLfloat left, right, bottom, top;
  GLfloat znear = 10.f, zfar = 600.f;
  GLint n;

  /* For simplicity, we don't compute the transformation matrix described */
  /* in Heckbert and Herf's paper.  The transformation and frustum used   */
  /* here is much simpler.                                                */

  vcopy(eyept, eye);
  vsub(qpts[1], qpts[0], yaxis);
  vsub(qpts[2], qpts[0], xaxis);
  vcross(yaxis, xaxis, zaxis);

  vnormalize(zaxis);
  vnormalize(xaxis); /* x-axis of eye coord system, in object space */
  vnormalize(yaxis); /* y-axis of eye coord system, in object space */

  /* jitter the eyepoint */
  eye[0] += xaxis[0] * dx;
  eye[1] += xaxis[1] * dx;
  eye[2] += xaxis[2] * dx;
  eye[0] += yaxis[0] * dy;
  eye[1] += yaxis[1] * dy;
  eye[2] += yaxis[2] * dy;

  /* center of view is just eyepoint offset in direction of normal */ 
  vadd(eye, zaxis, cov);

  /* set up viewing matrix */
  glPushMatrix();
  glLoadIdentity();
  gluLookAt(eye[0], eye[1], eye[2],
	    cov[0], cov[1], cov[2],
	    yaxis[0], yaxis[1], yaxis[2]);

  /* compute a frustum that just encloses the polygon */
  vsub(qpts[0], eye, tmp); /* from eye to 0th vertex */
  left = vdot(tmp, xaxis);
  vsub(qpts[2], eye, tmp); /* from eye to 2nd vertex */
  right = vdot(tmp, xaxis);
  vsub(qpts[0], eye, tmp); /* from eye to 0th vertex */
  bottom = vdot(tmp, yaxis);
  vsub(qpts[1], eye, tmp); /* from eye to 1st vertex */
  top = vdot(tmp, yaxis);

  /* scale the frustum values based on the distance to the polygon */
  vsub(qpts[0], eye, pte);
  dist = fabs(vdot(zaxis, pte));
  left *= (znear/dist);
  right *= (znear/dist);
  bottom *= (znear/dist);
  top *= (znear/dist);

  glMatrixMode(GL_PROJECTION);
  glPushMatrix();
  glLoadIdentity();
  glFrustum(left, right, bottom, top, znear, zfar);
  glMatrixMode(GL_MODELVIEW);

  if (radianceMap) {
    glEnable(GL_LIGHTING);
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, materials[index]);
  } else {
    glDisable(GL_LIGHTING);
  }
  glDisable(GL_TEXTURE_2D);

  for (n=0; n < numShadowTex; n++) {
    qpts = pts[n];

    if (radianceMap) {
      glColor3f(1.f, 1.f, 1.f);
      findNormal(qpts, normal);
      glNormal3fv(normal);
      if (n == index) {
	/* draw this poly with ambient and diffuse lighting */
	glEnable(GL_LIGHT0);
      } else {
	/* draw other polys with ambient lighting only */
	glDisable(GL_LIGHT0);
      }
    } else {
      if (n == index) {
	/* this poly has full intensity, no occlusion */
	glColor3f(1.f, 1.f, 1.f);
      } else {
	/* all other polys just occlude the light */
	glColor3f(0.f, 0.f, 0.f);
      }
    }
    glBegin(GL_TRIANGLE_STRIP);
    glVertex3fv(qpts[0]);
    glVertex3fv(qpts[1]);
    glVertex3fv(qpts[2]);
    glVertex3fv(qpts[3]);
    glEnd();
  }
  glPopMatrix();
  glMatrixMode(GL_PROJECTION);
  glPopMatrix();
  glMatrixMode(GL_MODELVIEW);
}

void make_all_shadow_textures(float eye[3], float dx, float dy) {
  GLint texPerRow;
  GLint n;
  GLfloat x, y;

  texPerRow = (winxsize / texxsize);
  for (n=0; n < numShadowTex; n++) {
    y = (n / texPerRow) * texysize;
    x = (n % texPerRow) * texxsize;
    glViewport(x, y, texxsize, texysize);
    make_shadow_texture(n, eye, dx, dy);
  }
  glViewport(0, 0, winxsize, winysize);
}

void store_all_shadow_textures(void) {
  GLint texPerRow;
  GLint n, x, y;
  GLubyte *texbuf;
  
  texbuf = (GLubyte *) malloc(texxsize * texysize * sizeof(int));

  /* how many shadow textures can fit in the window */
  texPerRow = (winxsize / texxsize);

  for (n=0; n < numShadowTex; n++) {
    GLenum format;

    x = (n % texPerRow) * texxsize;
    y = (n / texPerRow) * texysize;

    glBindTexture(GL_TEXTURE_2D, shadowTextures + n);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

    if (radianceMap) {
      format = GL_RGB;
    } else {
      format = GL_LUMINANCE;
    }
    glCopyTexImage2D(GL_TEXTURE_2D, 0, format, x, y, texxsize, texysize, 0);
  }
  free(texbuf);
}

/* menu choices */
enum {
  NOSHADOWS, SOFTSHADOWS, HARDSHADOWS, VIEWTEXTURE, VIEWSCENE, QUIT
};

GLint shadowMode = HARDSHADOWS;
GLboolean viewTextures = GL_FALSE;

void
redraw(void)
{
  GLint n;
  GLfloat normal[3];
  GLfloat (*qpts)[3];

  glPushMatrix();
  glLoadIdentity();
  if (radianceMap && (shadowMode != NOSHADOWS)) {
    glLightfv(GL_LIGHT0, GL_POSITION, origin);
  } else {
    glLightfv(GL_LIGHT0, GL_POSITION, lightpos);
  }
  glPopMatrix();

  if (shadowMode == SOFTSHADOWS) {
    GLfloat jitterSize;
    GLfloat dx, dy;
    GLint numSteps, i, j;

    /* size of the area to jitter the light in */
    jitterSize = 15.0;

    /* number of times along x and y to jitter */
    numSteps = 5;

    glClear(GL_ACCUM_BUFFER_BIT);
    for (j=0; j < numSteps; j++) {
      for (i=0; i < numSteps; i++) {

	/* compute jitter amount, centering the jitter steps around zero */
	dx = (i - (numSteps - 1.0) / 2.0) / (numSteps - 1.0) * jitterSize;
	dy = (j - (numSteps - 1.0) / 2.0) / (numSteps - 1.0) * jitterSize;

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	make_all_shadow_textures(lightpos, dx, dy);
	glAccum(GL_ACCUM, 1.0 / (numSteps * numSteps));
	if (viewTextures) {
	  glutSwapBuffers();
	}
      }
    }
    glAccum(GL_RETURN, 1.0);
    store_all_shadow_textures();

  } else if (shadowMode == HARDSHADOWS) {

    /* make shadow textures from just one frame */
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ACCUM_BUFFER_BIT);
    make_all_shadow_textures(lightpos, 0, 0);
    store_all_shadow_textures();
    if (viewTextures) {
      glutSwapBuffers();
    }
  }
  if (viewTextures) {
    glutSwapBuffers();
    return;
  }

  glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
  glLoadIdentity();

  glColor3f(1.f, 1.f, 1.f);
  if (shadowMode == NOSHADOWS) {
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0); 
    glDisable(GL_TEXTURE_2D);
    for (n=0; n < numShadowTex; n++) {
      qpts = pts[n];
      findNormal(qpts, normal);
      glNormal3fv(normal);
      glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, materials[n]);
      glBegin(GL_TRIANGLE_STRIP);
      glTexCoord2f(0,0); glVertex3fv(qpts[0]);
      glTexCoord2f(0,1); glVertex3fv(qpts[1]);
      glTexCoord2f(1,0); glVertex3fv(qpts[2]);
      glTexCoord2f(1,1); glVertex3fv(qpts[3]);
      glEnd();
    }
  } else {
    glEnable(GL_TEXTURE_2D);

    if (radianceMap) {
      glDisable(GL_LIGHTING);
      for (n=0; n < numShadowTex; n++) {
	qpts = pts[n];
	glBindTexture(GL_TEXTURE_2D, shadowTextures + n);
	glBegin(GL_TRIANGLE_STRIP);
	glTexCoord2f(0,0); glVertex3fv(qpts[0]);
	glTexCoord2f(0,1); glVertex3fv(qpts[1]);
	glTexCoord2f(1,0); glVertex3fv(qpts[2]);
	glTexCoord2f(1,1); glVertex3fv(qpts[3]);
	glEnd();
      }
    } else {

      /* Unfortunately, using the texture as an occlusion map requires two */
      /* passes: one in which the occlusion map modulates the diffuse      */
      /* lighting, and one in which the ambient lighting is added in. It's */
      /* incorrect to modulate the ambient lighting, but if the result is  */
      /* acceptable to you, you can include it in the first pass and       */
      /* omit the second pass. */

      /* draw only with diffuse light, modulating it with the texture */
      glEnable(GL_LIGHTING);
      glEnable(GL_LIGHT0); 
      glLightModelfv(GL_LIGHT_MODEL_AMBIENT, black);
      for (n=0; n < numShadowTex; n++) {
	qpts = pts[n];
	findNormal(qpts, normal);
	glNormal3fv(normal);
	glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, materials[n]);
	glBindTexture(GL_TEXTURE_2D, shadowTextures + n);
	glBegin(GL_TRIANGLE_STRIP);
	glTexCoord2f(0,0); glVertex3fv(qpts[0]);
	glTexCoord2f(0,1); glVertex3fv(qpts[1]);
	glTexCoord2f(1,0); glVertex3fv(qpts[2]);
	glTexCoord2f(1,1); glVertex3fv(qpts[3]);
	glEnd();
      }

      /* add in the ambient lighting */
      glDisable(GL_LIGHTING);
      glDisable(GL_TEXTURE_2D);
      glEnable(GL_BLEND);
      glBlendFunc(GL_ONE, GL_ONE);
      glDepthFunc(GL_LEQUAL);
      for (n=0; n < numShadowTex; n++) {
	qpts = pts[n];
	glColor4f(ambient[0] * materials[n][0],
		  ambient[1] * materials[n][1],
		  ambient[2] * materials[n][2],
		  ambient[3] * materials[n][3]);
	glBegin(GL_TRIANGLE_STRIP);
	glTexCoord2f(0,0); glVertex3fv(qpts[0]);
	glTexCoord2f(0,1); glVertex3fv(qpts[1]);
	glTexCoord2f(1,0); glVertex3fv(qpts[2]);
	glTexCoord2f(1,1); glVertex3fv(qpts[3]);
	glEnd();
      }
      /* restore the ambient colors to their defaults */
      glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);
    }
  }

  /* blend in the checkerboard floor */
  glEnable(GL_BLEND);
  glBlendFunc(GL_ZERO, GL_SRC_COLOR);
  glDepthFunc(GL_LEQUAL);
  glEnable(GL_TEXTURE_2D);
  glBindTexture(GL_TEXTURE_2D, floorTexture);
  glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, materials[0]);
  glTranslatef(0.0f, 0.05f, 0.0f);
  glColor3f(1.f, 1.f, 1.f);
  glBegin(GL_TRIANGLE_STRIP);
  glNormal3f(0.f, 1.f, 0.f);
  glTexCoord2f(0.f, 0.f); glVertex3fv(pts[0][0]);
  glTexCoord2f(0.f, 1.f); glVertex3fv(pts[0][1]);
  glTexCoord2f(1.f, 0.f); glVertex3fv(pts[0][2]);
  glTexCoord2f(1.f, 1.f); glVertex3fv(pts[0][3]);
  glEnd();

  /* undo some state settings that we did above */
  glDisable(GL_BLEND);
  glDisable(GL_TEXTURE_2D);
  glDepthFunc(GL_LESS);
  glTranslatef(0.0f, -0.05f, 0.0f);

  glutSwapBuffers();
}

void
menu(int mode)
{
  switch (mode) {
  case NOSHADOWS:
  case SOFTSHADOWS:
  case HARDSHADOWS:
    shadowMode = mode;
    break;
  case VIEWTEXTURE:
    viewTextures = GL_TRUE;
    break;
  case VIEWSCENE:
    viewTextures = GL_FALSE;
    break;
  case QUIT:
    exit(0);
  }
  glutPostRedisplay();
}

/* Make a checkerboard texture for the floor. */
GLfloat *
make_texture(int maxs, int maxt)
{
  GLint s, t;
  static GLfloat *texture;

  texture = (GLfloat *) malloc(maxs * maxt * sizeof(GLfloat));
  for (t = 0; t < maxt; t++) {
    for (s = 0; s < maxs; s++) {
      texture[s + maxs * t] = ((s >> 4) & 0x1) ^ ((t >> 4) & 0x1);
    }
  }
  return texture;
}

/* ARGSUSED1 */
void
keyboard(unsigned char key, int x, int y)
{
  if (key == 27)  /* ESC */
    exit(0);
}

int
main(int argc, char *argv[])
{
  GLfloat *tex;
  GLint i;

  for (i = 1; i < argc; ++i) {
    if (!strcmp("-o", argv[i])) {
      /* use textures as occlusion maps rather than radiance maps */
      radianceMap = GL_FALSE;
    }
  }

  glutInit(&argc, argv);
  glutInitWindowSize(winxsize, winysize);
  glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_ACCUM | GLUT_SINGLE);
  (void) glutCreateWindow("soft shadows");
  glutDisplayFunc(redraw);
  glutKeyboardFunc(keyboard);

  glutCreateMenu(menu);
  glutAddMenuEntry("No Shadows", NOSHADOWS);
  glutAddMenuEntry("Soft Shadows", SOFTSHADOWS);
  glutAddMenuEntry("Hard Shadows", HARDSHADOWS);
  glutAddMenuEntry("View Textures", VIEWTEXTURE);
  glutAddMenuEntry("View Scene", VIEWSCENE);
  glutAddMenuEntry("Quit", QUIT);
  glutAttachMenu(GLUT_RIGHT_BUTTON);

  /* set up perspective projection */
  glMatrixMode(GL_PROJECTION);
  glFrustum(-30., 30., -30., 30., 100., 640.);
  glMatrixMode(GL_MODELVIEW);

  /* turn on features */
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_LIGHTING);
  glEnable(GL_LIGHT0);
  glCullFace(GL_BACK);
  glLightfv(GL_LIGHT0, GL_AMBIENT, black);

  /* number of shadow textures to make */
  numShadowTex = sizeof(pts) / sizeof(pts[0]);

  tex = make_texture(texxsize, texysize);
  glBindTexture(GL_TEXTURE_2D, floorTexture);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexImage2D(GL_TEXTURE_2D, 0, 1, texxsize, texysize, 0, GL_RED, GL_FLOAT, 
	       tex);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
  free(tex);

  glutMainLoop();
  return 0;             /* ANSI C requires main to return int. */
}