1 |
#ifndef lint |
2 |
static const char RCSid[] = "$Id: rhd_ogl.c,v 3.24 2004/01/01 11:21:55 schorsch Exp $"; |
3 |
#endif |
4 |
/* |
5 |
* OpenGL driver for holodeck display. |
6 |
* Based on GLX driver using T-mesh. |
7 |
* |
8 |
* Define symbol STEREO for stereo viewing. |
9 |
* Define symbol DOBJ for display object viewing. |
10 |
*/ |
11 |
|
12 |
#ifdef NOSTEREO |
13 |
#ifdef STEREO |
14 |
#undef STEREO |
15 |
#else |
16 |
#undef NOSTEREO |
17 |
#endif |
18 |
#endif |
19 |
|
20 |
|
21 |
#include <time.h> |
22 |
#include <GL/glx.h> |
23 |
#include <GL/glu.h> |
24 |
#ifdef STEREO |
25 |
#include <X11/extensions/SGIStereo.h> |
26 |
#endif |
27 |
|
28 |
#include "standard.h" |
29 |
#include "rhd_odraw.h" |
30 |
#include "rhdisp.h" |
31 |
#include "paths.h" |
32 |
#ifdef DOBJ |
33 |
#include "rhdobj.h" |
34 |
#endif |
35 |
|
36 |
#include "x11icon.h" |
37 |
|
38 |
#ifndef RAYQLEN |
39 |
#define RAYQLEN 0 /* max. rays to queue before flush */ |
40 |
#endif |
41 |
#ifndef MINWIDTH |
42 |
#define MINWIDTH 480 /* minimum graphics window width */ |
43 |
#define MINHEIGHT 400 /* minimum graphics window height */ |
44 |
#endif |
45 |
#ifndef VIEWDIST |
46 |
#define VIEWDIST 356 /* assumed viewing distance (mm) */ |
47 |
#endif |
48 |
#ifndef BORWIDTH |
49 |
#define BORWIDTH 5 /* border width */ |
50 |
#endif |
51 |
|
52 |
#ifndef FEQ |
53 |
#define FEQ(a,b) ((a)-(b) <= FTINY && (a)-(b) >= -FTINY) |
54 |
#endif |
55 |
|
56 |
#define VWHEADLOCK 01 /* head position is locked flag */ |
57 |
#define VWPERSP 02 /* perspective view is set */ |
58 |
#define VWORTHO 04 /* orthographic view is set */ |
59 |
#define VWCHANGE 010 /* view has changed */ |
60 |
#define VWSTEADY 020 /* view is now steady */ |
61 |
#define VWMAPPED 040 /* window is mapped */ |
62 |
|
63 |
#define GAMMA 1.4 /* default gamma correction */ |
64 |
|
65 |
#define FRAMESTATE(s) (((s)&(ShiftMask|ControlMask))==(ShiftMask|ControlMask)) |
66 |
|
67 |
#define MOVPCT 7 /* percent distance to move /frame */ |
68 |
#define MOVDIR(b) ((b)==Button1 ? 1 : (b)==Button2 ? 0 : -1) |
69 |
#define MOVDEG (-5) /* degrees to orbit CW/down /frame */ |
70 |
#define MOVORB(s) ((s)&ShiftMask ? 1 : (s)&ControlMask ? -1 : 0) |
71 |
|
72 |
#define setstereobuf(bid) (glXWaitGL(), \ |
73 |
XSGISetStereoBuffer(ourdisplay, gwind, bid), \ |
74 |
glXWaitX()) |
75 |
|
76 |
#define ourscreen DefaultScreen(ourdisplay) |
77 |
#define ourroot RootWindow(ourdisplay,ourscreen) |
78 |
#define ourmask (StructureNotifyMask|ExposureMask|KeyPressMask|\ |
79 |
ButtonPressMask|ButtonReleaseMask) |
80 |
|
81 |
#define levptr(etype) ((etype *)¤tevent) |
82 |
|
83 |
struct driver odev; /* global device driver structure */ |
84 |
|
85 |
char odev_args[64]; /* command arguments */ |
86 |
|
87 |
static GLfloat *depthbuffer = NULL; /* depth buffer */ |
88 |
|
89 |
#ifdef STEREO |
90 |
static VIEW vwright; /* right eye view */ |
91 |
static GLfloat *depthright = NULL; /* right depth buffer */ |
92 |
#endif |
93 |
|
94 |
static int rayqleft = 0; /* rays left to queue before flush */ |
95 |
|
96 |
static XEvent currentevent; /* current event */ |
97 |
|
98 |
static unsigned long ourblack=0, ourwhite=~0; |
99 |
|
100 |
static Display *ourdisplay = NULL; /* our display */ |
101 |
static XVisualInfo *ourvinf; /* our visual information */ |
102 |
static Window gwind = 0; /* our graphics window */ |
103 |
static GLXContext gctx; /* our GLX context */ |
104 |
|
105 |
static double pwidth, pheight; /* pixel dimensions (mm) */ |
106 |
|
107 |
static double dev_zmin, dev_zmax; /* fore and aft clipping plane dist. */ |
108 |
static double dev_zrat; /* (1. - dev_zmin/dev_zmax) */ |
109 |
|
110 |
#define setzrat() (dev_zrat = 1. - dev_zmin/dev_zmax) |
111 |
#define mapdepth(d) ((d)>0.9995 ? FHUGE : dev_zmin/(1.-(d)*dev_zrat)) |
112 |
|
113 |
static int inpresflags; /* input result flags */ |
114 |
|
115 |
static int viewflags; /* what's happening with view */ |
116 |
|
117 |
/* |
118 |
static int resizewindow(), getevent(), getkey(), moveview(), wipeclean(), |
119 |
xferdepth(), freedepth(), setglortho(), |
120 |
setglpersp(), getframe(), getmove(), fixwindow(), mytmflags(); |
121 |
|
122 |
static double getdistance(); |
123 |
*/ |
124 |
static void checkglerr(char *where); |
125 |
static void xferdepth(void); |
126 |
static void freedepth(void); |
127 |
static double getdistance(int dx, int dy, FVECT direc); |
128 |
static int mytmflags(void); |
129 |
static void getevent(void); |
130 |
static void draw3dline(register FVECT wp[2]); |
131 |
static void draw_grids(int fore); |
132 |
static int moveview(int dx, int dy, int mov, int orb); |
133 |
static void getframe(XButtonPressedEvent *ebut); |
134 |
static void getmove(XButtonPressedEvent *ebut); |
135 |
static void getkey(register XKeyPressedEvent *ekey); |
136 |
static void fixwindow(register XExposeEvent *eexp); |
137 |
static void resizewindow(register XConfigureEvent *ersz); |
138 |
static void waitabit(void); |
139 |
static void setglpersp(void); |
140 |
static void setglortho(void); |
141 |
static void wipeclean(void); |
142 |
|
143 |
|
144 |
#ifdef STEREO |
145 |
static void pushright(void); |
146 |
static void popright(void); |
147 |
#endif |
148 |
|
149 |
extern int gmPortals; /* GL portal list id */ |
150 |
|
151 |
extern time_t time(); |
152 |
|
153 |
|
154 |
extern void |
155 |
dev_open(id) /* initialize GLX driver */ |
156 |
char *id; |
157 |
{ |
158 |
extern char *getenv(); |
159 |
static RGBPRIMS myprims = STDPRIMS; |
160 |
static int atlBest[] = {GLX_RGBA, GLX_DOUBLEBUFFER, |
161 |
GLX_RED_SIZE,8, GLX_GREEN_SIZE,8, |
162 |
GLX_BLUE_SIZE,8, GLX_DEPTH_SIZE,15, None}; |
163 |
static int atlOK[] = {GLX_RGBA, GLX_DOUBLEBUFFER, |
164 |
GLX_RED_SIZE,4, GLX_GREEN_SIZE,4, |
165 |
GLX_BLUE_SIZE,4, GLX_DEPTH_SIZE,15, None}; |
166 |
char *ev; |
167 |
double gamval = GAMMA; |
168 |
RGBPRIMP dpri = stdprims; |
169 |
XSetWindowAttributes ourwinattr; |
170 |
XWMHints ourxwmhints; |
171 |
XSizeHints oursizhints; |
172 |
/* check for unsupported stereo */ |
173 |
#ifdef NOSTEREO |
174 |
error(INTERNAL, "stereo display driver unavailable"); |
175 |
#endif |
176 |
/* open display server */ |
177 |
ourdisplay = XOpenDisplay(NULL); |
178 |
CHECK(ourdisplay==NULL, USER, |
179 |
"cannot open X-windows; DISPLAY variable set?"); |
180 |
#ifdef STEREO |
181 |
switch (XSGIQueryStereoMode(ourdisplay, ourroot)) { |
182 |
case STEREO_TOP: |
183 |
case STEREO_BOTTOM: |
184 |
break; |
185 |
case STEREO_OFF: |
186 |
error(USER, |
187 |
"wrong video mode: run \"/usr/gfx/setmon -n STR_TOP\" first"); |
188 |
case X_STEREO_UNSUPPORTED: |
189 |
error(USER, "stereo mode not supported on this screen"); |
190 |
default: |
191 |
error(INTERNAL, "unknown stereo mode"); |
192 |
} |
193 |
#endif |
194 |
/* find a usable visual */ |
195 |
ourvinf = glXChooseVisual(ourdisplay, ourscreen, atlBest); |
196 |
if (ourvinf == NULL) |
197 |
ourvinf = glXChooseVisual(ourdisplay, ourscreen, atlOK); |
198 |
CHECK(ourvinf==NULL, USER, "no suitable visuals available"); |
199 |
/* get a context */ |
200 |
gctx = glXCreateContext(ourdisplay, ourvinf, NULL, GL_TRUE); |
201 |
/* set gamma and tone mapping */ |
202 |
if ((ev = XGetDefault(ourdisplay, "radiance", "gamma")) != NULL |
203 |
|| (ev = getenv("DISPLAY_GAMMA")) != NULL) |
204 |
gamval = atof(ev); |
205 |
if ((ev = getenv("DISPLAY_PRIMARIES")) != NULL && |
206 |
sscanf(ev, "%f %f %f %f %f %f %f %f", |
207 |
&myprims[RED][CIEX],&myprims[RED][CIEY], |
208 |
&myprims[GRN][CIEX],&myprims[GRN][CIEY], |
209 |
&myprims[BLU][CIEX],&myprims[BLU][CIEY], |
210 |
&myprims[WHT][CIEX],&myprims[WHT][CIEY]) >= 6) |
211 |
dpri = myprims; |
212 |
if (tmInit(mytmflags(), dpri, gamval) == NULL) |
213 |
error(SYSTEM, "not enough memory in dev_open"); |
214 |
/* open window */ |
215 |
ourwinattr.background_pixel = ourblack; |
216 |
ourwinattr.border_pixel = ourblack; |
217 |
ourwinattr.event_mask = ourmask; |
218 |
/* this is stupid */ |
219 |
ourwinattr.colormap = XCreateColormap(ourdisplay, ourroot, |
220 |
ourvinf->visual, AllocNone); |
221 |
gwind = XCreateWindow(ourdisplay, ourroot, 0, 0, |
222 |
DisplayWidth(ourdisplay,ourscreen)-2*BORWIDTH, |
223 |
#ifdef STEREO |
224 |
(DisplayHeight(ourdisplay,ourscreen)-2*BORWIDTH)/2, |
225 |
#else |
226 |
DisplayHeight(ourdisplay,ourscreen)-2*BORWIDTH, |
227 |
#endif |
228 |
BORWIDTH, ourvinf->depth, InputOutput, ourvinf->visual, |
229 |
CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &ourwinattr); |
230 |
CHECK(gwind==0, SYSTEM, "cannot create window"); |
231 |
XStoreName(ourdisplay, gwind, id); |
232 |
/* set window manager hints */ |
233 |
ourxwmhints.flags = InputHint|IconPixmapHint; |
234 |
ourxwmhints.input = True; |
235 |
ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay, |
236 |
gwind, x11icon_bits, x11icon_width, x11icon_height); |
237 |
XSetWMHints(ourdisplay, gwind, &ourxwmhints); |
238 |
oursizhints.min_width = MINWIDTH; |
239 |
#ifdef STEREO |
240 |
oursizhints.min_height = MINHEIGHT/2; |
241 |
oursizhints.max_width = DisplayWidth(ourdisplay,ourscreen)-2*BORWIDTH; |
242 |
oursizhints.max_height = (DisplayHeight(ourdisplay,ourscreen) - |
243 |
2*BORWIDTH)/2; |
244 |
oursizhints.flags = PMinSize|PMaxSize; |
245 |
#else |
246 |
oursizhints.min_height = MINHEIGHT; |
247 |
oursizhints.flags = PMinSize; |
248 |
#endif |
249 |
XSetNormalHints(ourdisplay, gwind, &oursizhints); |
250 |
/* set GLX context */ |
251 |
glXMakeCurrent(ourdisplay, gwind, gctx); |
252 |
glEnable(GL_DEPTH_TEST); |
253 |
glDepthFunc(GL_LEQUAL); |
254 |
glClearColor(0, 0, 0, 0); |
255 |
glFrontFace(GL_CCW); |
256 |
glDisable(GL_CULL_FACE); |
257 |
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); |
258 |
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); |
259 |
glPixelStorei(GL_PACK_ALIGNMENT, 1); |
260 |
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
261 |
/* figure out sensible view */ |
262 |
pwidth = (double)DisplayWidthMM(ourdisplay, ourscreen) / |
263 |
DisplayWidth(ourdisplay, ourscreen); |
264 |
pheight = (double)DisplayHeightMM(ourdisplay, ourscreen) / |
265 |
DisplayHeight(ourdisplay, ourscreen); |
266 |
#ifdef STEREO |
267 |
pheight *= 2.; |
268 |
setstereobuf(STEREO_BUFFER_LEFT); |
269 |
#endif |
270 |
checkglerr("setting rendering parameters"); |
271 |
odev.v = stdview; |
272 |
odev.v.type = VT_PER; |
273 |
viewflags = VWSTEADY; /* view starts static */ |
274 |
/* map the window */ |
275 |
XMapWindow(ourdisplay, gwind); |
276 |
dev_input(); /* sets size and view angles */ |
277 |
if (!odInit(DisplayWidth(ourdisplay,ourscreen) * |
278 |
DisplayHeight(ourdisplay,ourscreen) / 3)) |
279 |
error(SYSTEM, "insufficient memory for value storage"); |
280 |
odev.name = id; |
281 |
odev.firstuse = 1; /* can't recycle samples */ |
282 |
odev.ifd = ConnectionNumber(ourdisplay); |
283 |
} |
284 |
|
285 |
|
286 |
extern void |
287 |
dev_close(void) /* close our display and free resources */ |
288 |
{ |
289 |
#ifdef DOBJ |
290 |
dobj_cleanup(); |
291 |
#endif |
292 |
freedepth(); |
293 |
gmEndGeom(); |
294 |
gmEndPortal(); |
295 |
odDone(); |
296 |
glXMakeCurrent(ourdisplay, None, NULL); |
297 |
glXDestroyContext(ourdisplay, gctx); |
298 |
XDestroyWindow(ourdisplay, gwind); |
299 |
gwind = 0; |
300 |
XCloseDisplay(ourdisplay); |
301 |
ourdisplay = NULL; |
302 |
tmDone(NULL); |
303 |
odev.v.type = 0; |
304 |
odev.hres = odev.vres = 0; |
305 |
odev.ifd = -1; |
306 |
} |
307 |
|
308 |
|
309 |
extern void |
310 |
dev_clear(void) /* clear our representation */ |
311 |
{ |
312 |
viewflags |= VWCHANGE; /* pretend our view has changed */ |
313 |
wipeclean(); /* clean off display and samples */ |
314 |
dev_flush(); /* redraw geometry & get depth */ |
315 |
rayqleft = 0; /* hold off update */ |
316 |
} |
317 |
|
318 |
|
319 |
extern int |
320 |
dev_view( /* assign new driver view */ |
321 |
register VIEW *nv |
322 |
) |
323 |
{ |
324 |
if (nv->type != VT_PER || /* check view legality */ |
325 |
nv->horiz > 160. || nv->vert > 160.) { |
326 |
error(COMMAND, "illegal view type/angle"); |
327 |
nv->type = odev.v.type; |
328 |
nv->horiz = odev.v.horiz; |
329 |
nv->vert = odev.v.vert; |
330 |
return(0); |
331 |
} |
332 |
if (nv != &odev.v) { |
333 |
/* resize window? */ |
334 |
if (!FEQ(nv->horiz,odev.v.horiz) || |
335 |
!FEQ(nv->vert,odev.v.vert)) { |
336 |
int dw = DisplayWidth(ourdisplay,ourscreen); |
337 |
int dh = DisplayHeight(ourdisplay,ourscreen); |
338 |
|
339 |
dw -= 25; /* for window frame */ |
340 |
dh -= 50; |
341 |
#ifdef STEREO |
342 |
dh /= 2; |
343 |
#endif |
344 |
odev.hres = 2.*VIEWDIST/pwidth * |
345 |
tan(PI/180./2.*nv->horiz); |
346 |
odev.vres = 2.*VIEWDIST/pheight * |
347 |
tan(PI/180./2.*nv->vert); |
348 |
if (odev.hres > dw) { |
349 |
odev.vres = dw * odev.vres / odev.hres; |
350 |
odev.hres = dw; |
351 |
} |
352 |
if (odev.vres > dh) { |
353 |
odev.hres = dh * odev.hres / odev.vres; |
354 |
odev.vres = dh; |
355 |
} |
356 |
XResizeWindow(ourdisplay, gwind, odev.hres, odev.vres); |
357 |
dev_input(); /* get resize event */ |
358 |
} |
359 |
odev.v = *nv; /* setview() already called */ |
360 |
viewflags |= VWCHANGE; |
361 |
} |
362 |
#ifdef STEREO |
363 |
vwright = *nv; |
364 |
d = eyesepdist / sqrt(nv->hn2); |
365 |
VSUM(vwright.vp, nv->vp, nv->hvec, d); |
366 |
/* setview(&vwright); -- Unnecessary */ |
367 |
#endif |
368 |
wipeclean(); |
369 |
return(1); |
370 |
} |
371 |
|
372 |
|
373 |
extern void |
374 |
dev_section( /* add octree for geometry rendering */ |
375 |
char *gfn, |
376 |
char *pfn |
377 |
) |
378 |
{ |
379 |
if (gfn == NULL) { |
380 |
gmEndGeom(); |
381 |
gmEndPortal(); |
382 |
wipeclean(); /* new geometry, so redraw it */ |
383 |
return; |
384 |
} |
385 |
if (access(gfn, R_OK) == 0) |
386 |
gmNewGeom(gfn); |
387 |
#ifdef DEBUG |
388 |
else { |
389 |
sprintf(errmsg, "cannot load octree \"%s\"", gfn); |
390 |
error(WARNING, errmsg); |
391 |
} |
392 |
#endif |
393 |
if (pfn != NULL) |
394 |
gmNewPortal(pfn); |
395 |
} |
396 |
|
397 |
|
398 |
extern void |
399 |
dev_auxcom( /* process an auxiliary command */ |
400 |
char *cmd, |
401 |
char *args |
402 |
) |
403 |
{ |
404 |
#ifdef DOBJ |
405 |
int vischange; |
406 |
|
407 |
if ((vischange = dobj_command(cmd, args)) >= 0) { |
408 |
if (vischange) { |
409 |
imm_mode = beam_sync(1) > 0; |
410 |
dev_clear(); |
411 |
} |
412 |
return; |
413 |
} |
414 |
#endif |
415 |
sprintf(errmsg, "%s: unknown command", cmd); |
416 |
error(COMMAND, errmsg); |
417 |
} |
418 |
|
419 |
|
420 |
extern VIEW * |
421 |
dev_auxview( /* return nth auxiliary view */ |
422 |
int n, |
423 |
int hvres[2] |
424 |
) |
425 |
{ |
426 |
hvres[0] = odev.hres; hvres[1] = odev.vres; |
427 |
if (n == 0) |
428 |
return(&odev.v); |
429 |
#ifdef STEREO |
430 |
if (n == 1) |
431 |
return(&vwright); |
432 |
#endif |
433 |
return(NULL); |
434 |
} |
435 |
|
436 |
|
437 |
extern int |
438 |
dev_input(void) /* get X11 input */ |
439 |
{ |
440 |
inpresflags = 0; |
441 |
|
442 |
do |
443 |
getevent(); |
444 |
|
445 |
while (XPending(ourdisplay) > 0); |
446 |
|
447 |
odev.inpready = 0; |
448 |
|
449 |
return(inpresflags); |
450 |
} |
451 |
|
452 |
|
453 |
extern void |
454 |
dev_value( /* add a pixel value to our texture */ |
455 |
COLR c, |
456 |
FVECT d, |
457 |
FVECT p |
458 |
) |
459 |
{ |
460 |
#ifdef DOBJ |
461 |
if (dobj_lightsamp != NULL) { /* in light source sampling */ |
462 |
(*dobj_lightsamp)(c, d, p); |
463 |
return; |
464 |
} |
465 |
#endif |
466 |
odSample(c, d, p); /* add to display representation */ |
467 |
if (!--rayqleft) |
468 |
dev_flush(); /* flush output */ |
469 |
} |
470 |
|
471 |
|
472 |
extern int |
473 |
dev_flush(void) /* flush output as appropriate */ |
474 |
{ |
475 |
int ndrawn; |
476 |
|
477 |
if ((viewflags&(VWMAPPED|VWPERSP)) == (VWMAPPED|VWPERSP)) { |
478 |
#ifdef STEREO |
479 |
pushright(); /* draw right eye */ |
480 |
ndrawn = gmDrawGeom(); |
481 |
#ifdef DOBJ |
482 |
ndrawn += dobj_render(); |
483 |
#endif |
484 |
checkglerr("rendering right eye"); |
485 |
popright(); /* draw left eye */ |
486 |
#endif |
487 |
ndrawn = gmDrawGeom(); |
488 |
#ifdef DOBJ |
489 |
ndrawn += dobj_render(); |
490 |
#endif |
491 |
glXSwapBuffers(ourdisplay, gwind); |
492 |
checkglerr("rendering base view"); |
493 |
} |
494 |
if ((viewflags&(VWMAPPED|VWSTEADY|VWPERSP|VWORTHO)) == |
495 |
(VWMAPPED|VWSTEADY|VWPERSP)) { |
496 |
/* first time after steady */ |
497 |
if (ndrawn) |
498 |
xferdepth(); /* transfer and clear depth */ |
499 |
setglortho(); /* set orthographic view */ |
500 |
|
501 |
} |
502 |
if ((viewflags&(VWMAPPED|VWSTEADY|VWPERSP|VWORTHO)) == |
503 |
(VWMAPPED|VWSTEADY|VWORTHO)) { |
504 |
/* else update cones */ |
505 |
#ifdef STEREO |
506 |
pushright(); |
507 |
odUpdate(1); /* draw right eye */ |
508 |
popright(); |
509 |
#endif |
510 |
odUpdate(0); /* draw left eye */ |
511 |
glFlush(); /* flush OpenGL */ |
512 |
} |
513 |
rayqleft = RAYQLEN; |
514 |
/* flush X11 and return # pending */ |
515 |
return(odev.inpready = XPending(ourdisplay)); |
516 |
} |
517 |
|
518 |
|
519 |
static void |
520 |
checkglerr( /* check for GL or GLU error */ |
521 |
char *where |
522 |
) |
523 |
{ |
524 |
register GLenum errcode; |
525 |
|
526 |
while ((errcode = glGetError()) != GL_NO_ERROR) { |
527 |
sprintf(errmsg, "OpenGL error %s: %s", |
528 |
where, gluErrorString(errcode)); |
529 |
error(WARNING, errmsg); |
530 |
} |
531 |
} |
532 |
|
533 |
|
534 |
static void |
535 |
xferdepth(void) /* load and clear depth buffer */ |
536 |
{ |
537 |
register GLfloat *dbp; |
538 |
register GLubyte *pbuf; |
539 |
|
540 |
if (depthbuffer == NULL) { /* allocate private depth buffer */ |
541 |
#ifdef STEREO |
542 |
depthright = (GLfloat *)malloc( |
543 |
odev.hres*odev.vres*sizeof(GLfloat)); |
544 |
#endif |
545 |
depthbuffer = (GLfloat *)malloc( |
546 |
odev.hres*odev.vres*sizeof(GLfloat)); |
547 |
CHECK(depthbuffer==NULL, SYSTEM, "out of memory in xferdepth"); |
548 |
} |
549 |
/* allocate alpha buffer for portals */ |
550 |
if (gmPortals) |
551 |
pbuf = (GLubyte *)malloc(odev.hres*odev.vres*sizeof(GLubyte)); |
552 |
else |
553 |
pbuf = NULL; |
554 |
#ifdef STEREO |
555 |
pushright(); |
556 |
glReadPixels(0, 0, odev.hres, odev.vres, |
557 |
GL_DEPTH_COMPONENT, GL_FLOAT, depthright); |
558 |
if (pbuf != NULL) { |
559 |
glClear(GL_COLOR_BUFFER_BIT); |
560 |
gmDrawPortals(0xff, -1, -1, -1); |
561 |
glReadPixels(0, 0, odev.hres, odev.vres, |
562 |
GL_RED, GL_UNSIGNED_BYTE, pbuf); |
563 |
} |
564 |
for (dbp = depthright + odev.hres*odev.vres; dbp-- > depthright; ) |
565 |
if (pbuf != NULL && pbuf[dbp-depthright]&0x40) |
566 |
*dbp = FHUGE; |
567 |
else |
568 |
*dbp = mapdepth(*dbp); |
569 |
glClear(GL_DEPTH_BUFFER_BIT); |
570 |
odDepthMap(1, depthright); |
571 |
popright(); |
572 |
#endif |
573 |
/* read back depth buffer */ |
574 |
glReadPixels(0, 0, odev.hres, odev.vres, |
575 |
GL_DEPTH_COMPONENT, GL_FLOAT, depthbuffer); |
576 |
if (pbuf != NULL) { |
577 |
glClear(GL_COLOR_BUFFER_BIT); /* find portals */ |
578 |
gmDrawPortals(0xff, -1, -1, -1); |
579 |
glReadPixels(0, 0, odev.hres, odev.vres, |
580 |
GL_RED, GL_UNSIGNED_BYTE, pbuf); |
581 |
#ifdef DEBUG |
582 |
glXSwapBuffers(ourdisplay, gwind); |
583 |
#endif |
584 |
} |
585 |
for (dbp = depthbuffer + odev.hres*odev.vres; dbp-- > depthbuffer; ) |
586 |
if (pbuf != NULL && pbuf[dbp-depthbuffer]&0x40) |
587 |
*dbp = FHUGE; |
588 |
else |
589 |
*dbp = mapdepth(*dbp); |
590 |
glClear(GL_DEPTH_BUFFER_BIT); /* clear system depth buffer */ |
591 |
odDepthMap(0, depthbuffer); /* transfer depth data */ |
592 |
if (pbuf != NULL) |
593 |
free((void *)pbuf); /* free our portal buffer */ |
594 |
} |
595 |
|
596 |
|
597 |
static void |
598 |
freedepth(void) /* free recorded depth buffer */ |
599 |
{ |
600 |
if (depthbuffer == NULL) |
601 |
return; |
602 |
#ifdef STEREO |
603 |
odDepthMap(1, NULL); |
604 |
free((void *)depthright); |
605 |
depthright = NULL; |
606 |
#endif |
607 |
odDepthMap(0, NULL); |
608 |
free((void *)depthbuffer); |
609 |
depthbuffer = NULL; |
610 |
} |
611 |
|
612 |
|
613 |
static double |
614 |
getdistance( /* distance from fore plane along view ray */ |
615 |
int dx, |
616 |
int dy, |
617 |
FVECT direc |
618 |
) |
619 |
{ |
620 |
GLfloat gldepth; |
621 |
double dist; |
622 |
|
623 |
if ((dx<0) | (dx>=odev.hres) | (dy<0) | (dy>=odev.vres)) |
624 |
return(FHUGE); |
625 |
if (depthbuffer != NULL) |
626 |
dist = depthbuffer[dy*odev.hres + dx]; |
627 |
else { |
628 |
glReadPixels(dx,dy, 1,1, GL_DEPTH_COMPONENT, |
629 |
GL_FLOAT, &gldepth); |
630 |
if (gldepth <= FTINY) |
631 |
return (FHUGE); /* call failed */ |
632 |
dist = mapdepth(gldepth); |
633 |
} |
634 |
if (dist >= .99*FHUGE) |
635 |
return(FHUGE); |
636 |
return((dist-odev.v.vfore)/DOT(direc,odev.v.vdir)); |
637 |
} |
638 |
|
639 |
|
640 |
#ifdef STEREO |
641 |
static void |
642 |
pushright(void) /* push on right view & buffer */ |
643 |
{ |
644 |
double d; |
645 |
|
646 |
setstereobuf(STEREO_BUFFER_RIGHT); |
647 |
if (viewflags & VWPERSP) { |
648 |
glMatrixMode(GL_MODELVIEW); |
649 |
glPushMatrix(); |
650 |
d = -eyesepdist / sqrt(odev.v.hn2); |
651 |
glTranslated(d*odev.v.hvec[0], d*odev.v.hvec[1], |
652 |
d*odev.v.hvec[2]); |
653 |
checkglerr("setting right view"); |
654 |
} |
655 |
} |
656 |
|
657 |
|
658 |
static void |
659 |
popright(void) /* pop off right view & buffer */ |
660 |
{ |
661 |
if (viewflags & VWPERSP) { |
662 |
glMatrixMode(GL_MODELVIEW); |
663 |
glPopMatrix(); |
664 |
} |
665 |
setstereobuf(STEREO_BUFFER_LEFT); |
666 |
} |
667 |
#endif |
668 |
|
669 |
|
670 |
static int |
671 |
mytmflags(void) /* figure out tone mapping flags */ |
672 |
{ |
673 |
extern char *progname; |
674 |
register char *cp, *tail; |
675 |
/* find basic name */ |
676 |
for (cp = tail = progname; *cp; cp++) |
677 |
if (*cp == '/') |
678 |
tail = cp+1; |
679 |
for (cp = tail; *cp && *cp != '.'; cp++) |
680 |
; |
681 |
#ifdef DEBUG |
682 |
if (cp > tail && cp[-1] == 'h') |
683 |
return(TM_F_HUMAN); |
684 |
else |
685 |
return(TM_F_CAMERA); |
686 |
#else |
687 |
if (cp > tail && cp[-1] == 'h') |
688 |
return(TM_F_HUMAN|TM_F_NOSTDERR); |
689 |
else |
690 |
return(TM_F_CAMERA|TM_F_NOSTDERR); |
691 |
#endif |
692 |
} |
693 |
|
694 |
|
695 |
static void |
696 |
getevent(void) /* get next event */ |
697 |
{ |
698 |
XNextEvent(ourdisplay, levptr(XEvent)); |
699 |
switch (levptr(XEvent)->type) { |
700 |
case ConfigureNotify: |
701 |
resizewindow(levptr(XConfigureEvent)); |
702 |
break; |
703 |
case UnmapNotify: |
704 |
viewflags &= ~VWMAPPED; |
705 |
break; |
706 |
case MapNotify: |
707 |
odRemap(0); |
708 |
viewflags |= VWMAPPED; |
709 |
break; |
710 |
case Expose: |
711 |
fixwindow(levptr(XExposeEvent)); |
712 |
break; |
713 |
case KeyPress: |
714 |
getkey(levptr(XKeyPressedEvent)); |
715 |
break; |
716 |
case ButtonPress: |
717 |
if (FRAMESTATE(levptr(XButtonPressedEvent)->state)) |
718 |
getframe(levptr(XButtonPressedEvent)); |
719 |
else |
720 |
getmove(levptr(XButtonPressedEvent)); |
721 |
break; |
722 |
} |
723 |
} |
724 |
|
725 |
|
726 |
static void |
727 |
draw3dline( /* draw 3d line in world coordinates */ |
728 |
register FVECT wp[2] |
729 |
) |
730 |
{ |
731 |
glVertex3d(wp[0][0], wp[0][1], wp[0][2]); |
732 |
glVertex3d(wp[1][0], wp[1][1], wp[1][2]); |
733 |
} |
734 |
|
735 |
|
736 |
static void |
737 |
draw_grids( /* draw holodeck section grids */ |
738 |
int fore |
739 |
) |
740 |
{ |
741 |
glPushAttrib(GL_LIGHTING_BIT|GL_ENABLE_BIT); |
742 |
glDisable(GL_LIGHTING); |
743 |
if (fore) |
744 |
glColor3ub(4, 250, 250); |
745 |
else |
746 |
glColor3ub(0, 0, 0); |
747 |
glBegin(GL_LINES); /* draw each grid line */ |
748 |
gridlines(draw3dline); |
749 |
glEnd(); |
750 |
checkglerr("drawing grid lines"); |
751 |
glPopAttrib(); |
752 |
} |
753 |
|
754 |
|
755 |
static int |
756 |
moveview( /* move our view */ |
757 |
int dx, |
758 |
int dy, |
759 |
int mov, |
760 |
int orb |
761 |
) |
762 |
{ |
763 |
VIEW nv; |
764 |
FVECT odir, v1, wip; |
765 |
double d, d1; |
766 |
/* start with old view */ |
767 |
nv = odev.v; |
768 |
/* orient our motion */ |
769 |
if (viewray(v1, odir, &odev.v, |
770 |
(dx+.5)/odev.hres, (dy+.5)/odev.vres) < -FTINY) |
771 |
return(0); /* outside view */ |
772 |
if (mov | orb) { /* moving relative to geometry */ |
773 |
d = getdistance(dx, dy, odir); /* distance from front plane */ |
774 |
#ifdef DOBJ |
775 |
d1 = dobj_trace(NULL, v1, odir); |
776 |
if (d1 < d) |
777 |
d = d1; |
778 |
#endif |
779 |
if (d >= .99*FHUGE) |
780 |
d = 0.5*(dev_zmax+dev_zmin); /* just guess */ |
781 |
VSUM(wip, v1, odir, d); |
782 |
VSUB(odir, wip, odev.v.vp); |
783 |
} else /* panning with constant viewpoint */ |
784 |
VCOPY(nv.vdir, odir); |
785 |
if (orb && mov) { /* orbit left/right */ |
786 |
spinvector(odir, odir, nv.vup, d=MOVDEG*PI/180.*mov); |
787 |
VSUM(nv.vp, wip, odir, -1.); |
788 |
spinvector(nv.vdir, nv.vdir, nv.vup, d); |
789 |
} else if (orb) { /* orbit up/down */ |
790 |
fcross(v1, odir, nv.vup); |
791 |
if (normalize(v1) == 0.) |
792 |
return(0); |
793 |
spinvector(odir, odir, v1, d=MOVDEG*PI/180.*orb); |
794 |
VSUM(nv.vp, wip, odir, -1.); |
795 |
spinvector(nv.vdir, nv.vdir, v1, d); |
796 |
} else if (mov) { /* move forward/backward */ |
797 |
d = MOVPCT/100. * mov; |
798 |
VSUM(nv.vp, nv.vp, odir, d); |
799 |
} |
800 |
if (!mov ^ !orb && viewflags&VWHEADLOCK) { /* restore height */ |
801 |
VSUM(v1, odev.v.vp, nv.vp, -1.); |
802 |
d = DOT(v1, nv.vup); |
803 |
VSUM(nv.vp, nv.vp, odev.v.vup, d); |
804 |
} |
805 |
if (setview(&nv) != NULL) |
806 |
return(0); /* illegal view */ |
807 |
dev_view(&nv); |
808 |
inpresflags |= DFL(DC_SETVIEW); |
809 |
return(1); |
810 |
} |
811 |
|
812 |
|
813 |
static void |
814 |
getframe( /* get focus frame */ |
815 |
XButtonPressedEvent *ebut |
816 |
) |
817 |
{ |
818 |
int startx = ebut->x, starty = ebut->y; |
819 |
int endx, endy; |
820 |
|
821 |
XMaskEvent(ourdisplay, ButtonReleaseMask, levptr(XEvent)); |
822 |
endx = levptr(XButtonReleasedEvent)->x; |
823 |
endy = levptr(XButtonReleasedEvent)->y; |
824 |
if ((endx == startx) | (endy == starty)) { |
825 |
XBell(ourdisplay, 0); |
826 |
return; |
827 |
} |
828 |
if (endx < startx) {register int c = endx; endx = startx; startx = c;} |
829 |
if (endy < starty) {register int c = endy; endy = starty; starty = c;} |
830 |
sprintf(odev_args, "%.3f %.3f %.3f %.3f", |
831 |
(startx+.5)/odev.hres, 1.-(endy+.5)/odev.vres, |
832 |
(endx+.5)/odev.hres, 1.-(starty+.5)/odev.vres); |
833 |
inpresflags |= DFL(DC_FOCUS); |
834 |
} |
835 |
|
836 |
|
837 |
static void |
838 |
waitabit(void) /* pause a moment */ |
839 |
{ |
840 |
struct timespec ts; |
841 |
ts.tv_sec = 0; |
842 |
ts.tv_nsec = 100000000L; |
843 |
nanosleep(&ts, NULL); |
844 |
} |
845 |
|
846 |
|
847 |
static void |
848 |
getmove( /* get view change */ |
849 |
XButtonPressedEvent *ebut |
850 |
) |
851 |
{ |
852 |
int movdir = MOVDIR(ebut->button); |
853 |
int movorb = MOVORB(ebut->state); |
854 |
int ndrawn; |
855 |
Window rootw, childw; |
856 |
int rootx, rooty, wx, wy; |
857 |
unsigned int statemask; |
858 |
|
859 |
XNoOp(ourdisplay); /* makes sure we're not idle */ |
860 |
|
861 |
viewflags &= ~VWSTEADY; /* flag moving view */ |
862 |
setglpersp(); /* start us off in perspective */ |
863 |
while (!XCheckMaskEvent(ourdisplay, |
864 |
ButtonReleaseMask, levptr(XEvent))) { |
865 |
/* pause so as not to move too fast */ |
866 |
waitabit(); |
867 |
/* get cursor position */ |
868 |
if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw, |
869 |
&rootx, &rooty, &wx, &wy, &statemask)) |
870 |
break; /* on another screen */ |
871 |
/* compute view motion */ |
872 |
if (!moveview(wx, odev.vres-1-wy, movdir, movorb)) { |
873 |
sleep(1); |
874 |
continue; /* cursor in bad place */ |
875 |
} |
876 |
draw_grids(1); /* redraw grid */ |
877 |
#ifdef STEREO |
878 |
pushright(); |
879 |
draw_grids(1); |
880 |
ndrawn = gmDrawGeom(); |
881 |
#ifdef DOBJ |
882 |
ndrawn += dobj_render(); |
883 |
#endif |
884 |
popright(); |
885 |
#endif |
886 |
/* redraw octrees */ |
887 |
ndrawn = gmDrawGeom(); |
888 |
#ifdef DOBJ |
889 |
ndrawn += dobj_render(); /* redraw objects */ |
890 |
#endif |
891 |
glXSwapBuffers(ourdisplay, gwind); |
892 |
if (!ndrawn) |
893 |
sleep(1); /* for reasonable interaction */ |
894 |
} |
895 |
if (!(inpresflags & DFL(DC_SETVIEW))) { /* do final motion */ |
896 |
movdir = MOVDIR(levptr(XButtonReleasedEvent)->button); |
897 |
wx = levptr(XButtonReleasedEvent)->x; |
898 |
wy = levptr(XButtonReleasedEvent)->y; |
899 |
moveview(wx, odev.vres-1-wy, movdir, movorb); |
900 |
} |
901 |
viewflags |= VWSTEADY; /* done goofing around */ |
902 |
} |
903 |
|
904 |
|
905 |
static void |
906 |
setglpersp(void) /* set perspective view in GL */ |
907 |
{ |
908 |
double d, xmin, xmax, ymin, ymax; |
909 |
GLfloat vec[4]; |
910 |
double depthlim[2]; |
911 |
/* set depth limits */ |
912 |
gmDepthLimit(depthlim, odev.v.vp, odev.v.vdir); |
913 |
if (depthlim[0] >= depthlim[1]) { |
914 |
dev_zmin = 1.; |
915 |
dev_zmax = 100.; |
916 |
} else { |
917 |
dev_zmin = 0.5*depthlim[0]; |
918 |
dev_zmax = 1.25*depthlim[1]; |
919 |
if (dev_zmin > dev_zmax/5.) |
920 |
dev_zmin = dev_zmax/5.; |
921 |
} |
922 |
if (odev.v.vfore > FTINY) |
923 |
dev_zmin = odev.v.vfore; |
924 |
if (odev.v.vaft > FTINY) |
925 |
dev_zmax = odev.v.vaft; |
926 |
if (dev_zmin*500. < dev_zmax) |
927 |
dev_zmin = dev_zmax/500.; |
928 |
setzrat(); |
929 |
xmax = dev_zmin * tan(PI/180./2. * odev.v.horiz); |
930 |
xmin = -xmax; |
931 |
d = odev.v.hoff * (xmax - xmin); |
932 |
xmin += d; xmax += d; |
933 |
ymax = dev_zmin * tan(PI/180./2. * odev.v.vert); |
934 |
ymin = -ymax; |
935 |
d = odev.v.voff * (ymax - ymin); |
936 |
ymin += d; ymax += d; |
937 |
/* set view matrix */ |
938 |
glMatrixMode(GL_PROJECTION); |
939 |
glLoadIdentity(); |
940 |
glFrustum(xmin, xmax, ymin, ymax, dev_zmin, dev_zmax); |
941 |
gluLookAt(odev.v.vp[0], odev.v.vp[1], odev.v.vp[2], |
942 |
odev.v.vp[0] + odev.v.vdir[0], |
943 |
odev.v.vp[1] + odev.v.vdir[1], |
944 |
odev.v.vp[2] + odev.v.vdir[2], |
945 |
odev.v.vup[0], odev.v.vup[1], odev.v.vup[2]); |
946 |
checkglerr("setting perspective view"); |
947 |
vec[0] = vec[1] = vec[2] = 0.; vec[3] = 1.; |
948 |
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, vec); |
949 |
vec[0] = -odev.v.vdir[0]; |
950 |
vec[1] = -odev.v.vdir[1]; |
951 |
vec[2] = -odev.v.vdir[2]; |
952 |
vec[3] = 0.; |
953 |
glLightfv(GL_LIGHT0, GL_POSITION, vec); |
954 |
vec[0] = vec[1] = vec[2] = .7; vec[3] = 1.; |
955 |
glLightfv(GL_LIGHT0, GL_SPECULAR, vec); |
956 |
glLightfv(GL_LIGHT0, GL_DIFFUSE, vec); |
957 |
vec[0] = vec[1] = vec[2] = .3; vec[3] = 1.; |
958 |
glLightfv(GL_LIGHT0, GL_AMBIENT, vec); |
959 |
glEnable(GL_LIGHT0); |
960 |
glEnable(GL_LIGHTING); /* light our GL objects */ |
961 |
glShadeModel(GL_SMOOTH); |
962 |
viewflags &= ~VWORTHO; |
963 |
viewflags |= VWPERSP; |
964 |
} |
965 |
|
966 |
|
967 |
static void |
968 |
setglortho(void) /* set up orthographic view for cone drawing */ |
969 |
{ |
970 |
glDrawBuffer(GL_FRONT); /* use single-buffer mode */ |
971 |
/* set view matrix */ |
972 |
glMatrixMode(GL_PROJECTION); |
973 |
glLoadIdentity(); |
974 |
glOrtho(0., (double)odev.hres, 0., (double)odev.vres, |
975 |
0.001*OMAXDEPTH, 1.001*(-OMAXDEPTH)); |
976 |
checkglerr("setting orthographic view"); |
977 |
glDisable(GL_LIGHTING); /* cones are constant color */ |
978 |
glShadeModel(GL_FLAT); |
979 |
viewflags &= ~VWPERSP; |
980 |
viewflags |= VWORTHO; |
981 |
} |
982 |
|
983 |
|
984 |
static void |
985 |
wipeclean(void) /* prepare for redraw */ |
986 |
{ |
987 |
glDrawBuffer(GL_BACK); /* use double-buffer mode */ |
988 |
glReadBuffer(GL_BACK); |
989 |
/* clear buffers */ |
990 |
#ifdef STEREO |
991 |
setstereobuf(STEREO_BUFFER_RIGHT); |
992 |
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); |
993 |
setstereobuf(STEREO_BUFFER_LEFT); |
994 |
#endif |
995 |
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); |
996 |
freedepth(); |
997 |
if ((viewflags&(VWCHANGE|VWSTEADY)) == |
998 |
(VWCHANGE|VWSTEADY)) { /* clear samples if new */ |
999 |
odClean(); |
1000 |
viewflags &= ~VWCHANGE; /* change noted */ |
1001 |
} else if (viewflags & VWSTEADY) |
1002 |
odRedrawAll(); |
1003 |
setglpersp(); /* reset view & clipping planes */ |
1004 |
} |
1005 |
|
1006 |
|
1007 |
static void |
1008 |
getkey( /* get input key */ |
1009 |
register XKeyPressedEvent *ekey |
1010 |
) |
1011 |
{ |
1012 |
Window rootw, childw; |
1013 |
int rootx, rooty, wx, wy; |
1014 |
unsigned int statemask; |
1015 |
int n; |
1016 |
char buf[8]; |
1017 |
|
1018 |
n = XLookupString(ekey, buf, sizeof(buf), NULL, NULL); |
1019 |
if (n != 1) |
1020 |
return; |
1021 |
switch (buf[0]) { |
1022 |
case 'h': /* turn on height motion lock */ |
1023 |
viewflags |= VWHEADLOCK; |
1024 |
return; |
1025 |
case 'H': /* turn off height motion lock */ |
1026 |
viewflags &= ~VWHEADLOCK; |
1027 |
return; |
1028 |
case 'l': /* retrieve last view */ |
1029 |
inpresflags |= DFL(DC_LASTVIEW); |
1030 |
return; |
1031 |
case 'p': /* pause computation */ |
1032 |
inpresflags |= DFL(DC_PAUSE); |
1033 |
return; |
1034 |
case 'v': /* spit out view */ |
1035 |
inpresflags |= DFL(DC_GETVIEW); |
1036 |
return; |
1037 |
case 'f': /* frame view position */ |
1038 |
if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw, |
1039 |
&rootx, &rooty, &wx, &wy, &statemask)) |
1040 |
return; /* on another screen */ |
1041 |
sprintf(odev_args, "%.4f %.4f", (wx+.5)/odev.hres, |
1042 |
1.-(wy+.5)/odev.vres); |
1043 |
inpresflags |= DFL(DC_FOCUS); |
1044 |
return; |
1045 |
case 'F': /* unfocus */ |
1046 |
odev_args[0] = '\0'; |
1047 |
inpresflags |= DFL(DC_FOCUS); |
1048 |
return; |
1049 |
case '\n': |
1050 |
case '\r': /* resume computation */ |
1051 |
inpresflags |= DFL(DC_RESUME); |
1052 |
return; |
1053 |
case CTRL('R'): /* redraw screen */ |
1054 |
odRemap(0); /* new tone mapping */ |
1055 |
glClear(GL_DEPTH_BUFFER_BIT); |
1056 |
#ifdef STEREO |
1057 |
setstereobuf(STEREO_BUFFER_RIGHT); |
1058 |
glClear(GL_DEPTH_BUFFER_BIT); |
1059 |
setstereobuf(STEREO_BUFFER_LEFT); |
1060 |
#endif |
1061 |
return; |
1062 |
case CTRL('L'): /* refresh from server */ |
1063 |
if (inpresflags & DFL(DC_REDRAW)) |
1064 |
return; /* already called */ |
1065 |
XRaiseWindow(ourdisplay, gwind); |
1066 |
XFlush(ourdisplay); /* raise up window */ |
1067 |
sleep(1); /* wait for restacking */ |
1068 |
dev_clear(); /* clear buffer and samples */ |
1069 |
odRemap(1); /* start fresh histogram */ |
1070 |
inpresflags |= DFL(DC_REDRAW); /* resend values from server */ |
1071 |
return; |
1072 |
case 'K': /* kill rtrace process(es) */ |
1073 |
inpresflags |= DFL(DC_KILL); |
1074 |
break; |
1075 |
case 'R': /* restart rtrace */ |
1076 |
inpresflags |= DFL(DC_RESTART); |
1077 |
break; |
1078 |
case 'C': /* clobber holodeck */ |
1079 |
inpresflags |= DFL(DC_CLOBBER); |
1080 |
break; |
1081 |
case 'q': /* quit the program */ |
1082 |
inpresflags |= DFL(DC_QUIT); |
1083 |
return; |
1084 |
default: |
1085 |
XBell(ourdisplay, 0); |
1086 |
return; |
1087 |
} |
1088 |
} |
1089 |
|
1090 |
|
1091 |
static void |
1092 |
fixwindow( /* repair damage to window */ |
1093 |
register XExposeEvent *eexp |
1094 |
) |
1095 |
{ |
1096 |
int xmin, ymin, xmax, ymax; |
1097 |
|
1098 |
if ((odev.hres == 0) | (odev.vres == 0)) { /* first exposure */ |
1099 |
resizewindow((XConfigureEvent *)eexp); |
1100 |
return; |
1101 |
} |
1102 |
xmin = eexp->x; xmax = eexp->x + eexp->width; |
1103 |
ymin = odev.vres - eexp->y - eexp->height; ymax = odev.vres - eexp->y; |
1104 |
|
1105 |
if (xmin <= 0 && xmax >= odev.hres-1 && |
1106 |
ymin <= 0 && ymax >= odev.vres) { |
1107 |
DCHECK(eexp->count, WARNING, "multiple clear in fixwindow"); |
1108 |
wipeclean(); /* make sure we're go */ |
1109 |
return; |
1110 |
} |
1111 |
/* clear portion of depth */ |
1112 |
glPushAttrib(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); |
1113 |
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); |
1114 |
glDepthFunc(GL_ALWAYS); |
1115 |
glBegin(GL_POLYGON); |
1116 |
glVertex3i(xmin, ymin, OMAXDEPTH); |
1117 |
glVertex3i(xmax, ymin, OMAXDEPTH); |
1118 |
glVertex3i(xmax, ymax, OMAXDEPTH); |
1119 |
glVertex3i(xmin, ymax, OMAXDEPTH); |
1120 |
glEnd(); |
1121 |
#ifdef STEREO |
1122 |
setstereobuf(STEREO_BUFFER_RIGHT); |
1123 |
glBegin(GL_POLYGON); |
1124 |
glVertex3i(xmin, ymin, OMAXDEPTH); |
1125 |
glVertex3i(xmax, ymin, OMAXDEPTH); |
1126 |
glVertex3i(xmax, ymax, OMAXDEPTH); |
1127 |
glVertex3i(xmin, ymax, OMAXDEPTH); |
1128 |
glEnd(); |
1129 |
odRedraw(1, xmin, ymin, xmax, ymax); |
1130 |
setstereobuf(STEREO_BUFFER_LEFT); |
1131 |
#endif |
1132 |
glPopAttrib(); |
1133 |
odRedraw(0, xmin, ymin, xmax, ymax); |
1134 |
} |
1135 |
|
1136 |
|
1137 |
static void |
1138 |
resizewindow( /* resize window */ |
1139 |
register XConfigureEvent *ersz |
1140 |
) |
1141 |
{ |
1142 |
glViewport(0, 0, ersz->width, ersz->height); |
1143 |
|
1144 |
if (ersz->width == odev.hres && ersz->height == odev.vres) |
1145 |
return; |
1146 |
|
1147 |
odev.hres = ersz->width; |
1148 |
odev.vres = ersz->height; |
1149 |
|
1150 |
odev.v.horiz = 2.*180./PI * atan(0.5/VIEWDIST*pwidth*odev.hres); |
1151 |
odev.v.vert = 2.*180./PI * atan(0.5/VIEWDIST*pheight*odev.vres); |
1152 |
|
1153 |
inpresflags |= DFL(DC_SETVIEW); |
1154 |
viewflags |= VWCHANGE; |
1155 |
} |