9 |
|
#include "standard.h" |
10 |
|
|
11 |
|
#include <GL/glx.h> |
12 |
+ |
#include <GL/glu.h> |
13 |
|
|
14 |
+ |
#include "platform.h" |
15 |
|
#include "rhd_qtree.h" |
16 |
< |
|
16 |
> |
#include "rhdriver.h" |
17 |
> |
#include "rhdisp.h" |
18 |
|
#include "x11icon.h" |
19 |
|
|
20 |
|
#ifndef RAYQLEN |
21 |
|
#define RAYQLEN 50000 /* max. rays to queue before flush */ |
22 |
|
#endif |
23 |
|
|
21 |
– |
#ifndef FEQ |
22 |
– |
#define FEQ(a,b) ((a)-(b) <= FTINY && (a)-(b) >= -FTINY) |
23 |
– |
#endif |
24 |
– |
|
24 |
|
#ifndef MAXCONE |
25 |
|
#define MAXCONE 16 /* number of different cone sizes */ |
26 |
|
#endif |
57 |
|
|
58 |
|
struct driver odev; /* global device driver structure */ |
59 |
|
|
60 |
+ |
TMstruct *tmGlobal; /* global tone-mapping structure */ |
61 |
+ |
|
62 |
|
char odev_args[64]; /* command arguments */ |
63 |
|
|
64 |
|
static XEvent currentevent; /* current event */ |
86 |
|
|
87 |
|
static int headlocked = 0; /* lock vertical motion */ |
88 |
|
|
88 |
– |
static int resizewindow(), getevent(), getkey(), moveview(), |
89 |
– |
initcones(), freecones(), |
90 |
– |
getmove(), fixwindow(), mytmflags(); |
89 |
|
|
90 |
+ |
static int mytmflags(void); |
91 |
+ |
static void initcones(void); |
92 |
+ |
static void freecones(void); |
93 |
+ |
static void getevent(void); |
94 |
+ |
static void draw3dline(FVECT wp[2]); |
95 |
+ |
static void draw_grids(void); |
96 |
+ |
static int moveview(int dx, int dy, int mov, int orb); |
97 |
+ |
static void getmove(XButtonPressedEvent *ebut); |
98 |
+ |
static void getkey(XKeyPressedEvent *ekey); |
99 |
+ |
static void fixwindow(XExposeEvent *eexp); |
100 |
+ |
static void resizewindow(XConfigureEvent *ersz); |
101 |
|
|
102 |
< |
dev_open(id) /* initialize X11 driver */ |
103 |
< |
char *id; |
102 |
> |
|
103 |
> |
void |
104 |
> |
dev_open( |
105 |
> |
char *id |
106 |
> |
) |
107 |
|
{ |
108 |
|
extern char *getenv(); |
109 |
|
static RGBPRIMS myprims = STDPRIMS; |
140 |
|
&myprims[BLU][CIEX],&myprims[BLU][CIEY], |
141 |
|
&myprims[WHT][CIEX],&myprims[WHT][CIEY]) >= 6) |
142 |
|
dpri = myprims; |
143 |
< |
if (tmInit(mytmflags(), dpri, gamval) == NULL) |
143 |
> |
tmGlobal = tmInit(mytmflags(), dpri, gamval); |
144 |
> |
if (tmGlobal == NULL) |
145 |
|
error(SYSTEM, "not enough memory in dev_open"); |
146 |
|
/* open window */ |
147 |
|
ourwinattr.background_pixel = ourblack; |
200 |
|
} |
201 |
|
|
202 |
|
|
203 |
< |
dev_close() /* close our display and free resources */ |
203 |
> |
void |
204 |
> |
dev_close(void) /* close our display and free resources */ |
205 |
|
{ |
206 |
|
glXMakeCurrent(ourdisplay, None, NULL); |
207 |
|
glXDestroyContext(ourdisplay, gctx); |
210 |
|
XCloseDisplay(ourdisplay); |
211 |
|
ourdisplay = NULL; |
212 |
|
qtFreeLeaves(); |
213 |
< |
tmDone(NULL); |
213 |
> |
tmDone(tmGlobal); |
214 |
|
freecones(); |
215 |
|
odev.v.type = 0; |
216 |
|
odev.hres = odev.vres = 0; |
218 |
|
} |
219 |
|
|
220 |
|
|
221 |
< |
dev_clear() /* clear our quadtree */ |
221 |
> |
void |
222 |
> |
dev_clear(void) /* clear our quadtree */ |
223 |
|
{ |
224 |
|
qtCompost(100); |
225 |
|
glClear(GL_DEPTH_BUFFER_BIT); |
228 |
|
|
229 |
|
|
230 |
|
int |
231 |
< |
dev_view(nv) /* assign new driver view */ |
232 |
< |
register VIEW *nv; |
231 |
> |
dev_view( /* assign new driver view */ |
232 |
> |
VIEW *nv |
233 |
> |
) |
234 |
|
{ |
235 |
|
if (nv->type == VT_PAR || /* check view legality */ |
236 |
|
nv->horiz > 160. || nv->vert > 160.) { |
246 |
|
return(0); |
247 |
|
} |
248 |
|
if (nv != &odev.v) { |
249 |
< |
if (!FEQ(nv->horiz,odev.v.horiz) || /* resize window? */ |
250 |
< |
!FEQ(nv->vert,odev.v.vert)) { |
249 |
> |
if (!FABSEQ(nv->horiz,odev.v.horiz) || /* resize window? */ |
250 |
> |
!FABSEQ(nv->vert,odev.v.vert)) { |
251 |
|
int dw = DisplayWidth(ourdisplay,ourscreen); |
252 |
|
int dh = DisplayHeight(ourdisplay,ourscreen); |
253 |
|
|
280 |
|
} |
281 |
|
|
282 |
|
|
283 |
< |
dev_section(ofn) /* add octree for geometry rendering */ |
284 |
< |
char *ofn; |
283 |
> |
void |
284 |
> |
dev_section( /* add octree for geometry rendering */ |
285 |
> |
char *gfn, |
286 |
> |
char *pfn |
287 |
> |
) |
288 |
|
{ |
289 |
|
/* unimplemented */ |
290 |
|
} |
291 |
|
|
292 |
|
|
293 |
< |
dev_auxcom(cmd, args) /* process an auxiliary command */ |
294 |
< |
char *cmd, *args; |
293 |
> |
void |
294 |
> |
dev_auxcom( /* process an auxiliary command */ |
295 |
> |
char *cmd, |
296 |
> |
char *args |
297 |
> |
) |
298 |
|
{ |
299 |
|
sprintf(errmsg, "%s: unknown command", cmd); |
300 |
|
error(COMMAND, errmsg); |
302 |
|
|
303 |
|
|
304 |
|
VIEW * |
305 |
< |
dev_auxview(n, hvres) /* return nth auxiliary view */ |
306 |
< |
int n; |
307 |
< |
int hvres[2]; |
305 |
> |
dev_auxview( /* return nth auxiliary view */ |
306 |
> |
int n, |
307 |
> |
int hvres[2] |
308 |
> |
) |
309 |
|
{ |
310 |
|
if (n) |
311 |
|
return(NULL); |
315 |
|
|
316 |
|
|
317 |
|
int |
318 |
< |
dev_input() /* get X11 input */ |
318 |
> |
dev_input(void) /* get X11 input */ |
319 |
|
{ |
320 |
|
inpresflags = 0; |
321 |
|
|
329 |
|
|
330 |
|
|
331 |
|
int |
332 |
< |
dev_flush() /* flush output */ |
332 |
> |
dev_flush(void) /* flush output */ |
333 |
|
{ |
334 |
|
qtUpdate(); |
335 |
|
glFlush(); |
338 |
|
} |
339 |
|
|
340 |
|
|
341 |
< |
dev_cone(rgb, ip, rad) /* render a cone in view coordinates */ |
342 |
< |
BYTE rgb[3]; |
343 |
< |
FVECT ip; |
344 |
< |
double rad; |
341 |
> |
void |
342 |
> |
dev_cone( /* render a cone in view coordinates */ |
343 |
> |
uby8 rgb[3], |
344 |
> |
FVECT ip, |
345 |
> |
double rad |
346 |
> |
) |
347 |
|
{ |
348 |
< |
register int ci, j; |
348 |
> |
int ci, j; |
349 |
|
double apexh, basez; |
350 |
|
/* is window mapped? */ |
351 |
|
if (!mapped) |
380 |
|
|
381 |
|
|
382 |
|
static int |
383 |
< |
mytmflags() /* figure out tone mapping flags */ |
383 |
> |
mytmflags(void) /* figure out tone mapping flags */ |
384 |
|
{ |
385 |
|
extern char *progname; |
386 |
< |
register char *cp, *tail; |
386 |
> |
char *cp, *tail; |
387 |
|
/* find basic name */ |
388 |
|
for (cp = tail = progname; *cp; cp++) |
389 |
|
if (*cp == '/') |
395 |
|
if (cp-tail == 5 && !strncmp(tail, "glx1h", 5)) |
396 |
|
return(TM_F_HUMAN|TM_F_NOSTDERR); |
397 |
|
error(USER, "illegal driver name"); |
398 |
+ |
return -1; /* pro forma return */ |
399 |
|
} |
400 |
|
|
401 |
|
|
402 |
< |
static |
403 |
< |
initcones() /* initialize cone vertices */ |
402 |
> |
static void |
403 |
> |
initcones(void) /* initialize cone vertices */ |
404 |
|
{ |
405 |
< |
register int i, j; |
405 |
> |
int i, j; |
406 |
|
double minrad, d; |
407 |
|
|
408 |
|
if (cone[0].nverts) |
426 |
|
} |
427 |
|
|
428 |
|
|
429 |
< |
static |
430 |
< |
freecones() /* free cone vertices */ |
429 |
> |
static void |
430 |
> |
freecones(void) /* free cone vertices */ |
431 |
|
{ |
432 |
< |
register int i; |
432 |
> |
int i; |
433 |
|
|
434 |
|
for (i = MAXCONE; i--; ) |
435 |
|
if (cone[i].nverts) { |
440 |
|
} |
441 |
|
|
442 |
|
|
443 |
< |
static |
444 |
< |
getevent() /* get next event */ |
443 |
> |
static void |
444 |
> |
getevent(void) /* get next event */ |
445 |
|
{ |
446 |
|
XNextEvent(ourdisplay, levptr(XEvent)); |
447 |
|
switch (levptr(XEvent)->type) { |
461 |
|
getkey(levptr(XKeyPressedEvent)); |
462 |
|
break; |
463 |
|
case ButtonPress: |
464 |
< |
getmove(levptr(XButtonPressedEvent)); |
464 |
> |
switch (levptr(XButtonPressedEvent)->button) { |
465 |
> |
case Button4: /* wheel up */ |
466 |
> |
case Button5: /* wheel down */ |
467 |
> |
break; |
468 |
> |
default: |
469 |
> |
getmove(levptr(XButtonPressedEvent)); |
470 |
> |
break; |
471 |
> |
} |
472 |
|
break; |
473 |
|
} |
474 |
|
} |
475 |
|
|
476 |
|
|
477 |
< |
static |
478 |
< |
draw3dline(wp) /* draw 3d line in world coordinates */ |
479 |
< |
register FVECT wp[2]; |
477 |
> |
static void |
478 |
> |
draw3dline( /* draw 3d line in world coordinates */ |
479 |
> |
FVECT wp[2] |
480 |
> |
) |
481 |
|
{ |
482 |
|
glVertex3d(wp[0][0], wp[0][1], wp[0][2]); |
483 |
|
glVertex3d(wp[1][0], wp[1][1], wp[1][2]); |
484 |
|
} |
485 |
|
|
486 |
|
|
487 |
< |
static |
488 |
< |
draw_grids() /* draw holodeck section grids */ |
487 |
> |
static void |
488 |
> |
draw_grids(void) /* draw holodeck section grids */ |
489 |
|
{ |
490 |
< |
static BYTE gridrgba[4] = {0x0, 0xff, 0xff, 0x00}; |
490 |
> |
static uby8 gridrgba[4] = {0x0, 0xff, 0xff, 0x00}; |
491 |
|
double xmin, xmax, ymin, ymax, zmin, zmax; |
492 |
< |
double d, cx, sx, crad; |
459 |
< |
FVECT vx, vy; |
460 |
< |
register int i, j; |
492 |
> |
double d; |
493 |
|
/* can we even do it? */ |
494 |
|
if (!mapped || odev.v.type != VT_PER) |
495 |
|
return; |
530 |
|
} |
531 |
|
|
532 |
|
|
533 |
< |
static |
534 |
< |
moveview(dx, dy, mov, orb) /* move our view */ |
535 |
< |
int dx, dy, mov, orb; |
533 |
> |
static int |
534 |
> |
moveview( /* move our view */ |
535 |
> |
int dx, |
536 |
> |
int dy, |
537 |
> |
int mov, |
538 |
> |
int orb |
539 |
> |
) |
540 |
|
{ |
541 |
|
VIEW nv; |
542 |
|
FVECT odir, v1; |
543 |
|
double d; |
544 |
< |
register int li; |
544 |
> |
int li; |
545 |
|
/* start with old view */ |
546 |
|
nv = odev.v; |
547 |
|
/* change view direction */ |
559 |
|
VSUM(nv.vp, qtL.wp[li], odir, -1.); |
560 |
|
spinvector(nv.vdir, nv.vdir, nv.vup, d); |
561 |
|
} else if (orb) { /* orbit up/down */ |
562 |
< |
fcross(v1, odir, nv.vup); |
563 |
< |
if (normalize(v1) == 0.) |
562 |
> |
if (geodesic(odir, odir, nv.vup, |
563 |
> |
d=MOVDEG*PI/180.*orb, GEOD_RAD) == 0.0) |
564 |
|
return(0); |
529 |
– |
spinvector(odir, odir, v1, d=MOVDEG*PI/180.*orb); |
565 |
|
VSUM(nv.vp, qtL.wp[li], odir, -1.); |
566 |
< |
spinvector(nv.vdir, nv.vdir, v1, d); |
566 |
> |
geodesic(nv.vdir, nv.vdir, nv.vup, d, GEOD_RAD); |
567 |
|
} else if (mov) { /* move forward/backward */ |
568 |
|
d = MOVPCT/100. * mov; |
569 |
|
VSUM(nv.vp, nv.vp, odir, d); |
581 |
|
} |
582 |
|
|
583 |
|
|
584 |
< |
static |
585 |
< |
getmove(ebut) /* get view change */ |
586 |
< |
XButtonPressedEvent *ebut; |
584 |
> |
static void |
585 |
> |
getmove( /* get view change */ |
586 |
> |
XButtonPressedEvent *ebut |
587 |
> |
) |
588 |
|
{ |
589 |
|
int movdir = MOVDIR(ebut->button); |
590 |
|
int movorb = MOVORB(ebut->state); |
624 |
|
} |
625 |
|
|
626 |
|
|
627 |
< |
static |
628 |
< |
getkey(ekey) /* get input key */ |
629 |
< |
register XKeyPressedEvent *ekey; |
627 |
> |
static void |
628 |
> |
getkey( /* get input key */ |
629 |
> |
XKeyPressedEvent *ekey |
630 |
> |
) |
631 |
|
{ |
632 |
|
int n; |
633 |
|
char buf[8]; |
696 |
|
} |
697 |
|
|
698 |
|
|
699 |
< |
static |
700 |
< |
fixwindow(eexp) /* repair damage to window */ |
701 |
< |
register XExposeEvent *eexp; |
699 |
> |
static void |
700 |
> |
fixwindow( /* repair damage to window */ |
701 |
> |
XExposeEvent *eexp |
702 |
> |
) |
703 |
|
{ |
704 |
|
int xmin, xmax, ymin, ymax; |
705 |
|
|
722 |
|
} |
723 |
|
|
724 |
|
|
725 |
< |
static |
726 |
< |
resizewindow(ersz) /* resize window */ |
727 |
< |
register XConfigureEvent *ersz; |
725 |
> |
static void |
726 |
> |
resizewindow( /* resize window */ |
727 |
> |
XConfigureEvent *ersz |
728 |
> |
) |
729 |
|
{ |
730 |
|
glViewport(0, 0, ersz->width, ersz->height); |
731 |
|
|