| 1 |
– |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
| 2 |
– |
|
| 1 |
|
#ifndef lint |
| 2 |
< |
static char SCCSid[] = "$SunId$ SGI"; |
| 2 |
> |
static const char RCSid[] = "$Id$"; |
| 3 |
|
#endif |
| 6 |
– |
|
| 4 |
|
/* |
| 5 |
|
* OpenGL driver for holodeck display. |
| 6 |
|
* Based on GLX driver using T-mesh. |
| 17 |
|
#endif |
| 18 |
|
#endif |
| 19 |
|
|
| 23 |
– |
#include "standard.h" |
| 20 |
|
|
| 21 |
< |
#include <sys/types.h> |
| 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 |
| 36 |
|
#include "x11icon.h" |
| 37 |
|
|
| 38 |
|
#ifndef RAYQLEN |
| 39 |
< |
#define RAYQLEN 10240 /* max. rays to queue before flush */ |
| 39 |
> |
#define RAYQLEN 0 /* max. rays to queue before flush */ |
| 40 |
|
#endif |
| 41 |
< |
|
| 42 |
< |
#ifndef PORTALP |
| 43 |
< |
#define PORTRED 2 /* portal red color */ |
| 45 |
< |
#define PORTGRN -1 /* portal green left alone */ |
| 46 |
< |
#define PORTBLU 128 /* portal blue color */ |
| 47 |
< |
#define PORTALP -1 /* don't use alpha channel */ |
| 41 |
> |
#ifndef MINWIDTH |
| 42 |
> |
#define MINWIDTH 480 /* minimum graphics window width */ |
| 43 |
> |
#define MINHEIGHT 400 /* minimum graphics window height */ |
| 44 |
|
#endif |
| 45 |
< |
#define isportal(c) ((PORTRED<0 || (c)[0]==PORTRED) && \ |
| 46 |
< |
(PORTGRN<0 || (c)[1]==PORTGRN) && \ |
| 47 |
< |
(PORTBLU<0 || (c)[2]==PORTBLU) && \ |
| 48 |
< |
(PORTALP<0 || (c)[3]==PORTALP)) |
| 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)) |
| 69 |
|
#define MOVDEG (-5) /* degrees to orbit CW/down /frame */ |
| 70 |
|
#define MOVORB(s) ((s)&ShiftMask ? 1 : (s)&ControlMask ? -1 : 0) |
| 71 |
|
|
| 67 |
– |
#define MINWIDTH 480 /* minimum graphics window width */ |
| 68 |
– |
#define MINHEIGHT 400 /* minimum graphics window height */ |
| 69 |
– |
|
| 70 |
– |
#define VIEWDIST 356 /* assumed viewing distance (mm) */ |
| 71 |
– |
|
| 72 |
– |
#define BORWIDTH 5 /* border width */ |
| 73 |
– |
|
| 72 |
|
#define setstereobuf(bid) (glXWaitGL(), \ |
| 73 |
|
XSGISetStereoBuffer(ourdisplay, gwind, bid), \ |
| 74 |
|
glXWaitX()) |
| 82 |
|
|
| 83 |
|
struct driver odev; /* global device driver structure */ |
| 84 |
|
|
| 85 |
+ |
TMstruct *tmGlobal; /* global tone-mapping structure */ |
| 86 |
+ |
|
| 87 |
|
char odev_args[64]; /* command arguments */ |
| 88 |
|
|
| 89 |
|
static GLfloat *depthbuffer = NULL; /* depth buffer */ |
| 97 |
|
|
| 98 |
|
static XEvent currentevent; /* current event */ |
| 99 |
|
|
| 100 |
– |
static int mapped = 0; /* window is mapped? */ |
| 100 |
|
static unsigned long ourblack=0, ourwhite=~0; |
| 101 |
|
|
| 102 |
|
static Display *ourdisplay = NULL; /* our display */ |
| 114 |
|
|
| 115 |
|
static int inpresflags; /* input result flags */ |
| 116 |
|
|
| 117 |
< |
static int headlocked; /* lock vertical motion */ |
| 117 |
> |
static int viewflags; /* what's happening with view */ |
| 118 |
|
|
| 119 |
< |
static int isperspective; /* perspective/ortho view */ |
| 121 |
< |
|
| 122 |
< |
static int viewsteady; /* is view steady? */ |
| 123 |
< |
|
| 119 |
> |
/* |
| 120 |
|
static int resizewindow(), getevent(), getkey(), moveview(), wipeclean(), |
| 121 |
|
xferdepth(), freedepth(), setglortho(), |
| 122 |
|
setglpersp(), getframe(), getmove(), fixwindow(), mytmflags(); |
| 123 |
|
|
| 124 |
|
static double getdistance(); |
| 125 |
+ |
*/ |
| 126 |
+ |
static void checkglerr(char *where); |
| 127 |
+ |
static void xferdepth(void); |
| 128 |
+ |
static void freedepth(void); |
| 129 |
+ |
static double getdistance(int dx, int dy, FVECT direc); |
| 130 |
+ |
static int mytmflags(void); |
| 131 |
+ |
static void getevent(void); |
| 132 |
+ |
static void draw3dline(register FVECT wp[2]); |
| 133 |
+ |
static void draw_grids(int fore); |
| 134 |
+ |
static int moveview(int dx, int dy, int mov, int orb); |
| 135 |
+ |
static void getframe(XButtonPressedEvent *ebut); |
| 136 |
+ |
static void getmove(XButtonPressedEvent *ebut); |
| 137 |
+ |
static void getkey(register XKeyPressedEvent *ekey); |
| 138 |
+ |
static void fixwindow(register XExposeEvent *eexp); |
| 139 |
+ |
static void resizewindow(register XConfigureEvent *ersz); |
| 140 |
+ |
static void waitabit(void); |
| 141 |
+ |
static void setglpersp(void); |
| 142 |
+ |
static void setglortho(void); |
| 143 |
+ |
static void wipeclean(void); |
| 144 |
|
|
| 145 |
+ |
|
| 146 |
|
#ifdef STEREO |
| 147 |
< |
static int pushright(), popright(); |
| 147 |
> |
static void pushright(void); |
| 148 |
> |
static void popright(void); |
| 149 |
|
#endif |
| 150 |
|
|
| 151 |
|
extern int gmPortals; /* GL portal list id */ |
| 153 |
|
extern time_t time(); |
| 154 |
|
|
| 155 |
|
|
| 156 |
+ |
extern void |
| 157 |
|
dev_open(id) /* initialize GLX driver */ |
| 158 |
|
char *id; |
| 159 |
|
{ |
| 160 |
|
extern char *getenv(); |
| 161 |
|
static RGBPRIMS myprims = STDPRIMS; |
| 162 |
< |
#if (PORTALP<0) |
| 163 |
< |
static int atlBest[] = {GLX_RGBA, GLX_RED_SIZE,8, |
| 164 |
< |
GLX_GREEN_SIZE,8, GLX_BLUE_SIZE,8, |
| 165 |
< |
GLX_DEPTH_SIZE,15, None}; |
| 166 |
< |
#else |
| 167 |
< |
static int atlBest[] = {GLX_RGBA, GLX_RED_SIZE,8, |
| 150 |
< |
GLX_GREEN_SIZE,8, GLX_BLUE_SIZE,8, |
| 151 |
< |
GLX_ALPHA_SIZE,2, GLX_DEPTH_SIZE,15, None}; |
| 152 |
< |
#endif |
| 162 |
> |
static int atlBest[] = {GLX_RGBA, GLX_DOUBLEBUFFER, |
| 163 |
> |
GLX_RED_SIZE,8, GLX_GREEN_SIZE,8, |
| 164 |
> |
GLX_BLUE_SIZE,8, GLX_DEPTH_SIZE,15, None}; |
| 165 |
> |
static int atlOK[] = {GLX_RGBA, GLX_DOUBLEBUFFER, |
| 166 |
> |
GLX_RED_SIZE,4, GLX_GREEN_SIZE,4, |
| 167 |
> |
GLX_BLUE_SIZE,4, GLX_DEPTH_SIZE,15, None}; |
| 168 |
|
char *ev; |
| 169 |
|
double gamval = GAMMA; |
| 170 |
|
RGBPRIMP dpri = stdprims; |
| 195 |
|
#endif |
| 196 |
|
/* find a usable visual */ |
| 197 |
|
ourvinf = glXChooseVisual(ourdisplay, ourscreen, atlBest); |
| 198 |
+ |
if (ourvinf == NULL) |
| 199 |
+ |
ourvinf = glXChooseVisual(ourdisplay, ourscreen, atlOK); |
| 200 |
|
CHECK(ourvinf==NULL, USER, "no suitable visuals available"); |
| 201 |
|
/* get a context */ |
| 202 |
|
gctx = glXCreateContext(ourdisplay, ourvinf, NULL, GL_TRUE); |
| 211 |
|
&myprims[BLU][CIEX],&myprims[BLU][CIEY], |
| 212 |
|
&myprims[WHT][CIEX],&myprims[WHT][CIEY]) >= 6) |
| 213 |
|
dpri = myprims; |
| 214 |
< |
if (tmInit(mytmflags(), dpri, gamval) == NULL) |
| 214 |
> |
tmGlobal = tmInit(mytmflags(), dpri, gamval); |
| 215 |
> |
if (tmGlobal == NULL) |
| 216 |
|
error(SYSTEM, "not enough memory in dev_open"); |
| 217 |
|
/* open window */ |
| 218 |
|
ourwinattr.background_pixel = ourblack; |
| 235 |
|
/* set window manager hints */ |
| 236 |
|
ourxwmhints.flags = InputHint|IconPixmapHint; |
| 237 |
|
ourxwmhints.input = True; |
| 238 |
< |
ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay, |
| 239 |
< |
gwind, x11icon_bits, x11icon_width, x11icon_height); |
| 238 |
> |
ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay, gwind, |
| 239 |
> |
(char *)x11icon_bits, x11icon_width, x11icon_height); |
| 240 |
|
XSetWMHints(ourdisplay, gwind, &ourxwmhints); |
| 241 |
|
oursizhints.min_width = MINWIDTH; |
| 242 |
|
#ifdef STEREO |
| 254 |
|
glXMakeCurrent(ourdisplay, gwind, gctx); |
| 255 |
|
glEnable(GL_DEPTH_TEST); |
| 256 |
|
glDepthFunc(GL_LEQUAL); |
| 257 |
< |
glDisable(GL_DITHER); |
| 257 |
> |
glClearColor(0, 0, 0, 0); |
| 258 |
|
glFrontFace(GL_CCW); |
| 259 |
|
glDisable(GL_CULL_FACE); |
| 260 |
|
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); |
| 261 |
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); |
| 262 |
+ |
glPixelStorei(GL_PACK_ALIGNMENT, 1); |
| 263 |
+ |
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 264 |
|
/* figure out sensible view */ |
| 265 |
|
pwidth = (double)DisplayWidthMM(ourdisplay, ourscreen) / |
| 266 |
|
DisplayWidth(ourdisplay, ourscreen); |
| 271 |
|
setstereobuf(STEREO_BUFFER_LEFT); |
| 272 |
|
#endif |
| 273 |
|
checkglerr("setting rendering parameters"); |
| 274 |
< |
copystruct(&odev.v, &stdview); |
| 274 |
> |
odev.v = stdview; |
| 275 |
|
odev.v.type = VT_PER; |
| 276 |
< |
headlocked = 0; /* free up head movement */ |
| 257 |
< |
viewsteady = 1; /* view starts static */ |
| 258 |
< |
isperspective = -1; /* but no view set, yet */ |
| 276 |
> |
viewflags = VWSTEADY; /* view starts static */ |
| 277 |
|
/* map the window */ |
| 278 |
|
XMapWindow(ourdisplay, gwind); |
| 279 |
|
dev_input(); /* sets size and view angles */ |
| 280 |
|
if (!odInit(DisplayWidth(ourdisplay,ourscreen) * |
| 281 |
< |
DisplayHeight(ourdisplay,ourscreen) / 4)) |
| 281 |
> |
DisplayHeight(ourdisplay,ourscreen) / 3)) |
| 282 |
|
error(SYSTEM, "insufficient memory for value storage"); |
| 283 |
|
odev.name = id; |
| 284 |
|
odev.firstuse = 1; /* can't recycle samples */ |
| 286 |
|
} |
| 287 |
|
|
| 288 |
|
|
| 289 |
< |
dev_close() /* close our display and free resources */ |
| 289 |
> |
extern void |
| 290 |
> |
dev_close(void) /* close our display and free resources */ |
| 291 |
|
{ |
| 292 |
|
#ifdef DOBJ |
| 293 |
|
dobj_cleanup(); |
| 302 |
|
gwind = 0; |
| 303 |
|
XCloseDisplay(ourdisplay); |
| 304 |
|
ourdisplay = NULL; |
| 305 |
< |
tmDone(NULL); |
| 305 |
> |
tmDone(tmGlobal); |
| 306 |
|
odev.v.type = 0; |
| 307 |
|
odev.hres = odev.vres = 0; |
| 308 |
|
odev.ifd = -1; |
| 309 |
|
} |
| 310 |
|
|
| 311 |
|
|
| 312 |
< |
dev_clear() /* clear our representation */ |
| 312 |
> |
extern void |
| 313 |
> |
dev_clear(void) /* clear our representation */ |
| 314 |
|
{ |
| 315 |
< |
wipeclean(); |
| 315 |
> |
viewflags |= VWCHANGE; /* pretend our view has changed */ |
| 316 |
> |
wipeclean(); /* clean off display and samples */ |
| 317 |
> |
dev_flush(); /* redraw geometry & get depth */ |
| 318 |
|
rayqleft = 0; /* hold off update */ |
| 319 |
|
} |
| 320 |
|
|
| 321 |
|
|
| 322 |
< |
int |
| 323 |
< |
dev_view(nv) /* assign new driver view */ |
| 324 |
< |
register VIEW *nv; |
| 322 |
> |
extern int |
| 323 |
> |
dev_view( /* assign new driver view */ |
| 324 |
> |
register VIEW *nv |
| 325 |
> |
) |
| 326 |
|
{ |
| 327 |
+ |
#ifdef STEREO |
| 328 |
|
double d; |
| 329 |
< |
|
| 329 |
> |
#endif |
| 330 |
|
if (nv->type != VT_PER || /* check view legality */ |
| 331 |
|
nv->horiz > 160. || nv->vert > 160.) { |
| 332 |
|
error(COMMAND, "illegal view type/angle"); |
| 362 |
|
XResizeWindow(ourdisplay, gwind, odev.hres, odev.vres); |
| 363 |
|
dev_input(); /* get resize event */ |
| 364 |
|
} |
| 365 |
< |
copystruct(&odev.v, nv); /* setview() already called */ |
| 365 |
> |
odev.v = *nv; /* setview() already called */ |
| 366 |
> |
viewflags |= VWCHANGE; |
| 367 |
> |
} |
| 368 |
|
#ifdef STEREO |
| 369 |
< |
copystruct(&vwright, nv); |
| 370 |
< |
d = eyesepdist / sqrt(nv->hn2); |
| 371 |
< |
VSUM(vwright.vp, nv->vp, nv->hvec, d); |
| 372 |
< |
/* setview(&vwright); -- Unnecessary */ |
| 369 |
> |
vwright = *nv; |
| 370 |
> |
d = eyesepdist / sqrt(nv->hn2); |
| 371 |
> |
VSUM(vwright.vp, nv->vp, nv->hvec, d); |
| 372 |
> |
/* setview(&vwright); -- Unnecessary */ |
| 373 |
|
#endif |
| 348 |
– |
} else |
| 349 |
– |
viewsteady = 1; |
| 374 |
|
wipeclean(); |
| 375 |
|
return(1); |
| 376 |
|
} |
| 377 |
|
|
| 378 |
|
|
| 379 |
< |
dev_section(gfn, pfn) /* add octree for geometry rendering */ |
| 380 |
< |
char *gfn, *pfn; |
| 379 |
> |
extern void |
| 380 |
> |
dev_section( /* add octree for geometry rendering */ |
| 381 |
> |
char *gfn, |
| 382 |
> |
char *pfn |
| 383 |
> |
) |
| 384 |
|
{ |
| 358 |
– |
extern char *index(); |
| 359 |
– |
char *cp; |
| 360 |
– |
|
| 385 |
|
if (gfn == NULL) { |
| 386 |
|
gmEndGeom(); |
| 387 |
|
gmEndPortal(); |
| 401 |
|
} |
| 402 |
|
|
| 403 |
|
|
| 404 |
< |
dev_auxcom(cmd, args) /* process an auxiliary command */ |
| 405 |
< |
char *cmd, *args; |
| 404 |
> |
extern void |
| 405 |
> |
dev_auxcom( /* process an auxiliary command */ |
| 406 |
> |
char *cmd, |
| 407 |
> |
char *args |
| 408 |
> |
) |
| 409 |
|
{ |
| 410 |
|
#ifdef DOBJ |
| 411 |
< |
if (dobj_command(cmd, args) >= 0) |
| 411 |
> |
int vischange; |
| 412 |
> |
|
| 413 |
> |
if ((vischange = dobj_command(cmd, args)) >= 0) { |
| 414 |
> |
if (vischange) { |
| 415 |
> |
imm_mode = beam_sync(1) > 0; |
| 416 |
> |
dev_clear(); |
| 417 |
> |
} |
| 418 |
|
return; |
| 419 |
+ |
} |
| 420 |
|
#endif |
| 421 |
|
sprintf(errmsg, "%s: unknown command", cmd); |
| 422 |
|
error(COMMAND, errmsg); |
| 423 |
|
} |
| 424 |
|
|
| 425 |
|
|
| 426 |
< |
VIEW * |
| 427 |
< |
dev_auxview(n, hvres) /* return nth auxiliary view */ |
| 428 |
< |
int n; |
| 429 |
< |
int hvres[2]; |
| 426 |
> |
extern VIEW * |
| 427 |
> |
dev_auxview( /* return nth auxiliary view */ |
| 428 |
> |
int n, |
| 429 |
> |
int hvres[2] |
| 430 |
> |
) |
| 431 |
|
{ |
| 432 |
|
hvres[0] = odev.hres; hvres[1] = odev.vres; |
| 433 |
|
if (n == 0) |
| 440 |
|
} |
| 441 |
|
|
| 442 |
|
|
| 443 |
< |
int |
| 444 |
< |
dev_input() /* get X11 input */ |
| 443 |
> |
extern int |
| 444 |
> |
dev_input(void) /* get X11 input */ |
| 445 |
|
{ |
| 446 |
|
inpresflags = 0; |
| 447 |
|
|
| 456 |
|
} |
| 457 |
|
|
| 458 |
|
|
| 459 |
< |
dev_value(c, d, p) /* add a pixel value to our texture */ |
| 460 |
< |
COLR c; |
| 461 |
< |
FVECT d, p; |
| 459 |
> |
extern void |
| 460 |
> |
dev_value( /* add a pixel value to our texture */ |
| 461 |
> |
COLR c, |
| 462 |
> |
FVECT d, |
| 463 |
> |
FVECT p |
| 464 |
> |
) |
| 465 |
|
{ |
| 466 |
|
#ifdef DOBJ |
| 467 |
|
if (dobj_lightsamp != NULL) { /* in light source sampling */ |
| 475 |
|
} |
| 476 |
|
|
| 477 |
|
|
| 478 |
< |
int |
| 479 |
< |
dev_flush() /* flush output as appropriate */ |
| 478 |
> |
extern int |
| 479 |
> |
dev_flush(void) /* flush output as appropriate */ |
| 480 |
|
{ |
| 481 |
|
int ndrawn; |
| 482 |
|
|
| 483 |
< |
if (mapped && isperspective > 0) { |
| 483 |
> |
if ((viewflags&(VWMAPPED|VWPERSP)) == (VWMAPPED|VWPERSP)) { |
| 484 |
|
#ifdef STEREO |
| 485 |
|
pushright(); /* draw right eye */ |
| 486 |
|
ndrawn = gmDrawGeom(); |
| 487 |
|
#ifdef DOBJ |
| 488 |
|
ndrawn += dobj_render(); |
| 489 |
|
#endif |
| 452 |
– |
if (ndrawn) |
| 453 |
– |
gmDrawPortals(PORTRED, PORTGRN, PORTBLU, PORTALP); |
| 490 |
|
checkglerr("rendering right eye"); |
| 491 |
|
popright(); /* draw left eye */ |
| 492 |
|
#endif |
| 494 |
|
#ifdef DOBJ |
| 495 |
|
ndrawn += dobj_render(); |
| 496 |
|
#endif |
| 497 |
< |
if (ndrawn) |
| 462 |
< |
gmDrawPortals(PORTRED, PORTGRN, PORTBLU, PORTALP); |
| 497 |
> |
glXSwapBuffers(ourdisplay, gwind); |
| 498 |
|
checkglerr("rendering base view"); |
| 499 |
|
} |
| 500 |
< |
if (mapped && viewsteady) |
| 501 |
< |
if (isperspective > 0) { /* first time after steady */ |
| 502 |
< |
if (ndrawn) |
| 503 |
< |
xferdepth(); /* transfer and clear depth */ |
| 504 |
< |
setglortho(); /* set orthographic view */ |
| 505 |
< |
} else if (!isperspective) { |
| 500 |
> |
if ((viewflags&(VWMAPPED|VWSTEADY|VWPERSP|VWORTHO)) == |
| 501 |
> |
(VWMAPPED|VWSTEADY|VWPERSP)) { |
| 502 |
> |
/* first time after steady */ |
| 503 |
> |
if (ndrawn) |
| 504 |
> |
xferdepth(); /* transfer and clear depth */ |
| 505 |
> |
setglortho(); /* set orthographic view */ |
| 506 |
> |
|
| 507 |
> |
} |
| 508 |
> |
if ((viewflags&(VWMAPPED|VWSTEADY|VWPERSP|VWORTHO)) == |
| 509 |
> |
(VWMAPPED|VWSTEADY|VWORTHO)) { |
| 510 |
> |
/* else update cones */ |
| 511 |
|
#ifdef STEREO |
| 512 |
< |
pushright(); |
| 513 |
< |
odUpdate(1); /* draw right eye */ |
| 514 |
< |
popright(); |
| 512 |
> |
pushright(); |
| 513 |
> |
odUpdate(1); /* draw right eye */ |
| 514 |
> |
popright(); |
| 515 |
|
#endif |
| 516 |
< |
odUpdate(0); /* draw left eye */ |
| 517 |
< |
} |
| 518 |
< |
glFlush(); /* flush OpenGL */ |
| 516 |
> |
odUpdate(0); /* draw left eye */ |
| 517 |
> |
glFlush(); /* flush OpenGL */ |
| 518 |
> |
} |
| 519 |
|
rayqleft = RAYQLEN; |
| 520 |
|
/* flush X11 and return # pending */ |
| 521 |
|
return(odev.inpready = XPending(ourdisplay)); |
| 522 |
|
} |
| 523 |
|
|
| 524 |
|
|
| 525 |
< |
checkglerr(where) /* check for GL or GLU error */ |
| 526 |
< |
char *where; |
| 525 |
> |
static void |
| 526 |
> |
checkglerr( /* check for GL or GLU error */ |
| 527 |
> |
char *where |
| 528 |
> |
) |
| 529 |
|
{ |
| 530 |
|
register GLenum errcode; |
| 531 |
|
|
| 537 |
|
} |
| 538 |
|
|
| 539 |
|
|
| 540 |
< |
static |
| 541 |
< |
xferdepth() /* load and clear depth buffer */ |
| 540 |
> |
static void |
| 541 |
> |
xferdepth(void) /* load and clear depth buffer */ |
| 542 |
|
{ |
| 543 |
|
register GLfloat *dbp; |
| 544 |
< |
register GLubyte *cbuf; |
| 544 |
> |
register GLubyte *pbuf; |
| 545 |
|
|
| 546 |
|
if (depthbuffer == NULL) { /* allocate private depth buffer */ |
| 547 |
|
#ifdef STEREO |
| 554 |
|
} |
| 555 |
|
/* allocate alpha buffer for portals */ |
| 556 |
|
if (gmPortals) |
| 557 |
< |
cbuf = (GLubyte *)malloc(odev.hres*odev.vres* |
| 516 |
< |
(4*sizeof(GLubyte))); |
| 557 |
> |
pbuf = (GLubyte *)malloc(odev.hres*odev.vres*sizeof(GLubyte)); |
| 558 |
|
else |
| 559 |
< |
cbuf = NULL; |
| 559 |
> |
pbuf = NULL; |
| 560 |
|
#ifdef STEREO |
| 561 |
< |
setstereobuf(STEREO_BUFFER_RIGHT); |
| 561 |
> |
pushright(); |
| 562 |
|
glReadPixels(0, 0, odev.hres, odev.vres, |
| 563 |
|
GL_DEPTH_COMPONENT, GL_FLOAT, depthright); |
| 564 |
< |
if (cbuf != NULL) |
| 564 |
> |
if (pbuf != NULL) { |
| 565 |
> |
glClear(GL_COLOR_BUFFER_BIT); |
| 566 |
> |
gmDrawPortals(0xff, -1, -1, -1); |
| 567 |
|
glReadPixels(0, 0, odev.hres, odev.vres, |
| 568 |
< |
GL_RGBA, GL_UNSIGNED_BYTE, cbuf); |
| 568 |
> |
GL_RED, GL_UNSIGNED_BYTE, pbuf); |
| 569 |
> |
} |
| 570 |
|
for (dbp = depthright + odev.hres*odev.vres; dbp-- > depthright; ) |
| 571 |
< |
if (cbuf != NULL && isportal(cbuf+4*(dbp-depthright))) |
| 571 |
> |
if (pbuf != NULL && pbuf[dbp-depthright]&0x40) |
| 572 |
|
*dbp = FHUGE; |
| 573 |
|
else |
| 574 |
|
*dbp = mapdepth(*dbp); |
| 575 |
|
glClear(GL_DEPTH_BUFFER_BIT); |
| 532 |
– |
setstereobuf(STEREO_BUFFER_LEFT); |
| 576 |
|
odDepthMap(1, depthright); |
| 577 |
+ |
popright(); |
| 578 |
|
#endif |
| 579 |
|
/* read back depth buffer */ |
| 580 |
|
glReadPixels(0, 0, odev.hres, odev.vres, |
| 581 |
|
GL_DEPTH_COMPONENT, GL_FLOAT, depthbuffer); |
| 582 |
< |
if (cbuf != NULL) |
| 582 |
> |
if (pbuf != NULL) { |
| 583 |
> |
glClear(GL_COLOR_BUFFER_BIT); /* find portals */ |
| 584 |
> |
gmDrawPortals(0xff, -1, -1, -1); |
| 585 |
|
glReadPixels(0, 0, odev.hres, odev.vres, |
| 586 |
< |
GL_RGBA, GL_UNSIGNED_BYTE, cbuf); |
| 586 |
> |
GL_RED, GL_UNSIGNED_BYTE, pbuf); |
| 587 |
> |
#ifdef DEBUG |
| 588 |
> |
glXSwapBuffers(ourdisplay, gwind); |
| 589 |
> |
#endif |
| 590 |
> |
} |
| 591 |
|
for (dbp = depthbuffer + odev.hres*odev.vres; dbp-- > depthbuffer; ) |
| 592 |
< |
if (cbuf != NULL && isportal(cbuf+4*(dbp-depthbuffer))) |
| 592 |
> |
if (pbuf != NULL && pbuf[dbp-depthbuffer]&0x40) |
| 593 |
|
*dbp = FHUGE; |
| 594 |
|
else |
| 595 |
|
*dbp = mapdepth(*dbp); |
| 596 |
|
glClear(GL_DEPTH_BUFFER_BIT); /* clear system depth buffer */ |
| 547 |
– |
if (cbuf != NULL) |
| 548 |
– |
free((char *)cbuf); /* free our color buffer */ |
| 597 |
|
odDepthMap(0, depthbuffer); /* transfer depth data */ |
| 598 |
+ |
if (pbuf != NULL) |
| 599 |
+ |
free((void *)pbuf); /* free our portal buffer */ |
| 600 |
|
} |
| 601 |
|
|
| 602 |
|
|
| 603 |
< |
static |
| 604 |
< |
freedepth() /* free recorded depth buffer */ |
| 603 |
> |
static void |
| 604 |
> |
freedepth(void) /* free recorded depth buffer */ |
| 605 |
|
{ |
| 606 |
|
if (depthbuffer == NULL) |
| 607 |
|
return; |
| 608 |
|
#ifdef STEREO |
| 609 |
|
odDepthMap(1, NULL); |
| 610 |
< |
free((char *)depthright); |
| 610 |
> |
free((void *)depthright); |
| 611 |
|
depthright = NULL; |
| 612 |
|
#endif |
| 613 |
|
odDepthMap(0, NULL); |
| 614 |
< |
free((char *)depthbuffer); |
| 614 |
> |
free((void *)depthbuffer); |
| 615 |
|
depthbuffer = NULL; |
| 616 |
|
} |
| 617 |
|
|
| 618 |
|
|
| 619 |
|
static double |
| 620 |
< |
getdistance(dx, dy, direc) /* distance from fore plane along view ray */ |
| 621 |
< |
int dx, dy; |
| 622 |
< |
FVECT direc; |
| 620 |
> |
getdistance( /* distance from fore plane along view ray */ |
| 621 |
> |
int dx, |
| 622 |
> |
int dy, |
| 623 |
> |
FVECT direc |
| 624 |
> |
) |
| 625 |
|
{ |
| 626 |
|
GLfloat gldepth; |
| 575 |
– |
GLubyte glcolor[4]; |
| 627 |
|
double dist; |
| 628 |
|
|
| 629 |
< |
if (dx<0 | dx>=odev.hres | dy<0 | dy>=odev.vres) |
| 629 |
> |
if ((dx<0) | (dx>=odev.hres) | (dy<0) | (dy>=odev.vres)) |
| 630 |
|
return(FHUGE); |
| 631 |
|
if (depthbuffer != NULL) |
| 632 |
|
dist = depthbuffer[dy*odev.hres + dx]; |
| 633 |
|
else { |
| 634 |
|
glReadPixels(dx,dy, 1,1, GL_DEPTH_COMPONENT, |
| 635 |
|
GL_FLOAT, &gldepth); |
| 636 |
< |
if (gmPortals) { |
| 637 |
< |
glReadPixels(dx,dy, 1,1, GL_RGBA, |
| 587 |
< |
GL_UNSIGNED_BYTE, glcolor); |
| 588 |
< |
if (isportal(glcolor)) |
| 589 |
< |
return(FHUGE); |
| 590 |
< |
} |
| 636 |
> |
if (gldepth <= FTINY) |
| 637 |
> |
return (FHUGE); /* call failed */ |
| 638 |
|
dist = mapdepth(gldepth); |
| 639 |
|
} |
| 640 |
|
if (dist >= .99*FHUGE) |
| 644 |
|
|
| 645 |
|
|
| 646 |
|
#ifdef STEREO |
| 647 |
< |
static |
| 648 |
< |
pushright() /* push on right view & buffer */ |
| 647 |
> |
static void |
| 648 |
> |
pushright(void) /* push on right view & buffer */ |
| 649 |
|
{ |
| 650 |
|
double d; |
| 651 |
|
|
| 652 |
|
setstereobuf(STEREO_BUFFER_RIGHT); |
| 653 |
< |
if (isperspective > 0) { |
| 653 |
> |
if (viewflags & VWPERSP) { |
| 654 |
|
glMatrixMode(GL_MODELVIEW); |
| 655 |
|
glPushMatrix(); |
| 656 |
|
d = -eyesepdist / sqrt(odev.v.hn2); |
| 661 |
|
} |
| 662 |
|
|
| 663 |
|
|
| 664 |
< |
static |
| 665 |
< |
popright() /* pop off right view & buffer */ |
| 664 |
> |
static void |
| 665 |
> |
popright(void) /* pop off right view & buffer */ |
| 666 |
|
{ |
| 667 |
< |
if (isperspective > 0) { |
| 667 |
> |
if (viewflags & VWPERSP) { |
| 668 |
|
glMatrixMode(GL_MODELVIEW); |
| 669 |
|
glPopMatrix(); |
| 670 |
|
} |
| 674 |
|
|
| 675 |
|
|
| 676 |
|
static int |
| 677 |
< |
mytmflags() /* figure out tone mapping flags */ |
| 677 |
> |
mytmflags(void) /* figure out tone mapping flags */ |
| 678 |
|
{ |
| 679 |
|
extern char *progname; |
| 680 |
|
register char *cp, *tail; |
| 698 |
|
} |
| 699 |
|
|
| 700 |
|
|
| 701 |
< |
static |
| 702 |
< |
getevent() /* get next event */ |
| 701 |
> |
static void |
| 702 |
> |
getevent(void) /* get next event */ |
| 703 |
|
{ |
| 704 |
|
XNextEvent(ourdisplay, levptr(XEvent)); |
| 705 |
|
switch (levptr(XEvent)->type) { |
| 707 |
|
resizewindow(levptr(XConfigureEvent)); |
| 708 |
|
break; |
| 709 |
|
case UnmapNotify: |
| 710 |
< |
mapped = 0; |
| 710 |
> |
viewflags &= ~VWMAPPED; |
| 711 |
|
break; |
| 712 |
|
case MapNotify: |
| 713 |
|
odRemap(0); |
| 714 |
< |
mapped = 1; |
| 714 |
> |
viewflags |= VWMAPPED; |
| 715 |
|
break; |
| 716 |
|
case Expose: |
| 717 |
|
fixwindow(levptr(XExposeEvent)); |
| 729 |
|
} |
| 730 |
|
|
| 731 |
|
|
| 732 |
< |
static |
| 733 |
< |
draw3dline(wp) /* draw 3d line in world coordinates */ |
| 734 |
< |
register FVECT wp[2]; |
| 732 |
> |
static void |
| 733 |
> |
draw3dline( /* draw 3d line in world coordinates */ |
| 734 |
> |
register FVECT wp[2] |
| 735 |
> |
) |
| 736 |
|
{ |
| 737 |
|
glVertex3d(wp[0][0], wp[0][1], wp[0][2]); |
| 738 |
|
glVertex3d(wp[1][0], wp[1][1], wp[1][2]); |
| 739 |
|
} |
| 740 |
|
|
| 741 |
|
|
| 742 |
< |
static |
| 743 |
< |
draw_grids(fore) /* draw holodeck section grids */ |
| 744 |
< |
int fore; |
| 742 |
> |
static void |
| 743 |
> |
draw_grids( /* draw holodeck section grids */ |
| 744 |
> |
int fore |
| 745 |
> |
) |
| 746 |
|
{ |
| 747 |
|
glPushAttrib(GL_LIGHTING_BIT|GL_ENABLE_BIT); |
| 748 |
|
glDisable(GL_LIGHTING); |
| 749 |
|
if (fore) |
| 750 |
< |
glColor3ub(0, 255, 255); |
| 750 |
> |
glColor3ub(4, 250, 250); |
| 751 |
|
else |
| 752 |
|
glColor3ub(0, 0, 0); |
| 753 |
|
glBegin(GL_LINES); /* draw each grid line */ |
| 758 |
|
} |
| 759 |
|
|
| 760 |
|
|
| 761 |
< |
static |
| 762 |
< |
moveview(dx, dy, mov, orb) /* move our view */ |
| 763 |
< |
int dx, dy, mov, orb; |
| 761 |
> |
static int |
| 762 |
> |
moveview( /* move our view */ |
| 763 |
> |
int dx, |
| 764 |
> |
int dy, |
| 765 |
> |
int mov, |
| 766 |
> |
int orb |
| 767 |
> |
) |
| 768 |
|
{ |
| 769 |
|
VIEW nv; |
| 770 |
|
FVECT odir, v1, wip; |
| 771 |
< |
double d, d1; |
| 772 |
< |
register int li; |
| 771 |
> |
double d; |
| 772 |
> |
#ifdef DOBJ |
| 773 |
> |
double d1; |
| 774 |
> |
#endif |
| 775 |
|
/* start with old view */ |
| 776 |
< |
copystruct(&nv, &odev.v); |
| 776 |
> |
nv = odev.v; |
| 777 |
|
/* orient our motion */ |
| 778 |
|
if (viewray(v1, odir, &odev.v, |
| 779 |
|
(dx+.5)/odev.hres, (dy+.5)/odev.vres) < -FTINY) |
| 806 |
|
d = MOVPCT/100. * mov; |
| 807 |
|
VSUM(nv.vp, nv.vp, odir, d); |
| 808 |
|
} |
| 809 |
< |
if (!mov ^ !orb && headlocked) { /* restore head height */ |
| 809 |
> |
if (!mov ^ !orb && viewflags&VWHEADLOCK) { /* restore height */ |
| 810 |
|
VSUM(v1, odev.v.vp, nv.vp, -1.); |
| 811 |
|
d = DOT(v1, nv.vup); |
| 812 |
|
VSUM(nv.vp, nv.vp, odev.v.vup, d); |
| 819 |
|
} |
| 820 |
|
|
| 821 |
|
|
| 822 |
< |
static |
| 823 |
< |
getframe(ebut) /* get focus frame */ |
| 824 |
< |
XButtonPressedEvent *ebut; |
| 822 |
> |
static void |
| 823 |
> |
getframe( /* get focus frame */ |
| 824 |
> |
XButtonPressedEvent *ebut |
| 825 |
> |
) |
| 826 |
|
{ |
| 827 |
|
int startx = ebut->x, starty = ebut->y; |
| 828 |
< |
int endx, endy; |
| 829 |
< |
|
| 828 |
> |
int endx, endy, midx, midy; |
| 829 |
> |
FVECT odir, v1; |
| 830 |
> |
double d; |
| 831 |
> |
#ifdef DOBJ |
| 832 |
> |
double d1; |
| 833 |
> |
#endif |
| 834 |
> |
/* get mouse drag */ |
| 835 |
|
XMaskEvent(ourdisplay, ButtonReleaseMask, levptr(XEvent)); |
| 836 |
|
endx = levptr(XButtonReleasedEvent)->x; |
| 837 |
|
endy = levptr(XButtonReleasedEvent)->y; |
| 838 |
< |
if (endx == startx | endy == starty) { |
| 839 |
< |
XBell(ourdisplay, 0); |
| 838 |
> |
midx = (startx + endx) >> 1; |
| 839 |
> |
midy = (starty + endy) >> 1; |
| 840 |
> |
/* set focus distance */ |
| 841 |
> |
if (viewray(v1, odir, &odev.v, |
| 842 |
> |
(midx+.5)/odev.hres, (midy+.5)/odev.vres) < -FTINY) |
| 843 |
|
return; |
| 844 |
< |
} |
| 844 |
> |
d = getdistance(midx, midy, odir); /* distance from front plane */ |
| 845 |
> |
#ifdef DOBJ |
| 846 |
> |
d1 = dobj_trace(NULL, v1, odir); |
| 847 |
> |
if (d1 < d) |
| 848 |
> |
d = d1; |
| 849 |
> |
#endif |
| 850 |
> |
if (d < .99*FHUGE) |
| 851 |
> |
odev.v.vdist = d + sqrt(dist2(v1, odev.v.vp)); |
| 852 |
> |
/* set frame for rendering */ |
| 853 |
> |
if ((endx == startx) | (endy == starty)) |
| 854 |
> |
return; |
| 855 |
|
if (endx < startx) {register int c = endx; endx = startx; startx = c;} |
| 856 |
|
if (endy < starty) {register int c = endy; endy = starty; starty = c;} |
| 857 |
|
sprintf(odev_args, "%.3f %.3f %.3f %.3f", |
| 861 |
|
} |
| 862 |
|
|
| 863 |
|
|
| 864 |
< |
static |
| 865 |
< |
getmove(ebut) /* get view change */ |
| 792 |
< |
XButtonPressedEvent *ebut; |
| 864 |
> |
static void |
| 865 |
> |
waitabit(void) /* pause a moment */ |
| 866 |
|
{ |
| 867 |
+ |
struct timespec ts; |
| 868 |
+ |
ts.tv_sec = 0; |
| 869 |
+ |
ts.tv_nsec = 100000000L; |
| 870 |
+ |
nanosleep(&ts, NULL); |
| 871 |
+ |
} |
| 872 |
+ |
|
| 873 |
+ |
|
| 874 |
+ |
static void |
| 875 |
+ |
getmove( /* get view change */ |
| 876 |
+ |
XButtonPressedEvent *ebut |
| 877 |
+ |
) |
| 878 |
+ |
{ |
| 879 |
|
int movdir = MOVDIR(ebut->button); |
| 880 |
|
int movorb = MOVORB(ebut->state); |
| 881 |
|
int ndrawn; |
| 885 |
|
|
| 886 |
|
XNoOp(ourdisplay); /* makes sure we're not idle */ |
| 887 |
|
|
| 888 |
< |
viewsteady = 0; /* flag moving view */ |
| 889 |
< |
setglpersp(&odev.v); /* start us off in perspective */ |
| 888 |
> |
viewflags &= ~VWSTEADY; /* flag moving view */ |
| 889 |
> |
setglpersp(); /* start us off in perspective */ |
| 890 |
|
while (!XCheckMaskEvent(ourdisplay, |
| 891 |
|
ButtonReleaseMask, levptr(XEvent))) { |
| 892 |
+ |
/* pause so as not to move too fast */ |
| 893 |
+ |
waitabit(); |
| 894 |
|
/* get cursor position */ |
| 895 |
|
if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw, |
| 896 |
|
&rootx, &rooty, &wx, &wy, &statemask)) |
| 908 |
|
#ifdef DOBJ |
| 909 |
|
ndrawn += dobj_render(); |
| 910 |
|
#endif |
| 824 |
– |
if (ndrawn) |
| 825 |
– |
gmDrawPortals(PORTRED, PORTGRN, PORTBLU, PORTALP); |
| 911 |
|
popright(); |
| 912 |
|
#endif |
| 913 |
|
/* redraw octrees */ |
| 915 |
|
#ifdef DOBJ |
| 916 |
|
ndrawn += dobj_render(); /* redraw objects */ |
| 917 |
|
#endif |
| 918 |
< |
if (ndrawn) |
| 919 |
< |
gmDrawPortals(PORTRED, PORTGRN, PORTBLU, PORTALP); |
| 835 |
< |
glFlush(); |
| 836 |
< |
if (!ndrawn) { |
| 918 |
> |
glXSwapBuffers(ourdisplay, gwind); |
| 919 |
> |
if (!ndrawn) |
| 920 |
|
sleep(1); /* for reasonable interaction */ |
| 838 |
– |
#ifdef STEREO |
| 839 |
– |
pushright(); |
| 840 |
– |
draw_grids(0); |
| 841 |
– |
popright(); |
| 842 |
– |
#endif |
| 843 |
– |
draw_grids(0); |
| 844 |
– |
} |
| 921 |
|
} |
| 922 |
|
if (!(inpresflags & DFL(DC_SETVIEW))) { /* do final motion */ |
| 923 |
|
movdir = MOVDIR(levptr(XButtonReleasedEvent)->button); |
| 925 |
|
wy = levptr(XButtonReleasedEvent)->y; |
| 926 |
|
moveview(wx, odev.vres-1-wy, movdir, movorb); |
| 927 |
|
} |
| 928 |
+ |
viewflags |= VWSTEADY; /* done goofing around */ |
| 929 |
|
} |
| 930 |
|
|
| 931 |
|
|
| 932 |
< |
static |
| 933 |
< |
setglpersp(vp) /* set perspective view in GL */ |
| 857 |
< |
register VIEW *vp; |
| 932 |
> |
static void |
| 933 |
> |
setglpersp(void) /* set perspective view in GL */ |
| 934 |
|
{ |
| 935 |
|
double d, xmin, xmax, ymin, ymax; |
| 936 |
|
GLfloat vec[4]; |
| 942 |
|
dev_zmax = 100.; |
| 943 |
|
} else { |
| 944 |
|
dev_zmin = 0.5*depthlim[0]; |
| 945 |
< |
dev_zmax = 1.75*depthlim[1]; |
| 945 |
> |
dev_zmax = 1.25*depthlim[1]; |
| 946 |
|
if (dev_zmin > dev_zmax/5.) |
| 947 |
|
dev_zmin = dev_zmax/5.; |
| 948 |
|
} |
| 950 |
|
dev_zmin = odev.v.vfore; |
| 951 |
|
if (odev.v.vaft > FTINY) |
| 952 |
|
dev_zmax = odev.v.vaft; |
| 953 |
< |
if (dev_zmin < dev_zmax/100.) |
| 954 |
< |
dev_zmin = dev_zmax/100.; |
| 953 |
> |
if (dev_zmin*500. < dev_zmax) |
| 954 |
> |
dev_zmin = dev_zmax/500.; |
| 955 |
|
setzrat(); |
| 956 |
|
xmax = dev_zmin * tan(PI/180./2. * odev.v.horiz); |
| 957 |
|
xmin = -xmax; |
| 971 |
|
odev.v.vp[2] + odev.v.vdir[2], |
| 972 |
|
odev.v.vup[0], odev.v.vup[1], odev.v.vup[2]); |
| 973 |
|
checkglerr("setting perspective view"); |
| 898 |
– |
isperspective = 1; |
| 974 |
|
vec[0] = vec[1] = vec[2] = 0.; vec[3] = 1.; |
| 975 |
|
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, vec); |
| 976 |
|
vec[0] = -odev.v.vdir[0]; |
| 986 |
|
glEnable(GL_LIGHT0); |
| 987 |
|
glEnable(GL_LIGHTING); /* light our GL objects */ |
| 988 |
|
glShadeModel(GL_SMOOTH); |
| 989 |
+ |
viewflags &= ~VWORTHO; |
| 990 |
+ |
viewflags |= VWPERSP; |
| 991 |
|
} |
| 992 |
|
|
| 993 |
|
|
| 994 |
< |
static |
| 995 |
< |
setglortho() /* set up orthographic view for cone drawing */ |
| 994 |
> |
static void |
| 995 |
> |
setglortho(void) /* set up orthographic view for cone drawing */ |
| 996 |
|
{ |
| 997 |
+ |
glDrawBuffer(GL_FRONT); /* use single-buffer mode */ |
| 998 |
|
/* set view matrix */ |
| 999 |
|
glMatrixMode(GL_PROJECTION); |
| 1000 |
|
glLoadIdentity(); |
| 1001 |
|
glOrtho(0., (double)odev.hres, 0., (double)odev.vres, |
| 1002 |
|
0.001*OMAXDEPTH, 1.001*(-OMAXDEPTH)); |
| 1003 |
|
checkglerr("setting orthographic view"); |
| 926 |
– |
isperspective = 0; |
| 1004 |
|
glDisable(GL_LIGHTING); /* cones are constant color */ |
| 1005 |
|
glShadeModel(GL_FLAT); |
| 1006 |
+ |
viewflags &= ~VWPERSP; |
| 1007 |
+ |
viewflags |= VWORTHO; |
| 1008 |
|
} |
| 1009 |
|
|
| 1010 |
|
|
| 1011 |
< |
static |
| 1012 |
< |
wipeclean() /* prepare for redraw */ |
| 1011 |
> |
static void |
| 1012 |
> |
wipeclean(void) /* prepare for redraw */ |
| 1013 |
|
{ |
| 1014 |
< |
/* clear depth buffer */ |
| 1014 |
> |
glDrawBuffer(GL_BACK); /* use double-buffer mode */ |
| 1015 |
> |
glReadBuffer(GL_BACK); |
| 1016 |
> |
/* clear buffers */ |
| 1017 |
|
#ifdef STEREO |
| 1018 |
|
setstereobuf(STEREO_BUFFER_RIGHT); |
| 1019 |
< |
glClear(GL_DEPTH_BUFFER_BIT); |
| 1019 |
> |
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); |
| 1020 |
|
setstereobuf(STEREO_BUFFER_LEFT); |
| 1021 |
|
#endif |
| 1022 |
< |
glClear(GL_DEPTH_BUFFER_BIT); |
| 942 |
< |
if (viewsteady) /* clear samples if steady */ |
| 943 |
< |
odClean(); |
| 1022 |
> |
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); |
| 1023 |
|
freedepth(); |
| 1024 |
< |
setglpersp(&odev.v); /* reset view & clipping planes */ |
| 1024 |
> |
if ((viewflags&(VWCHANGE|VWSTEADY)) == |
| 1025 |
> |
(VWCHANGE|VWSTEADY)) { /* clear samples if new */ |
| 1026 |
> |
odClean(); |
| 1027 |
> |
viewflags &= ~VWCHANGE; /* change noted */ |
| 1028 |
> |
} else if (viewflags & VWSTEADY) |
| 1029 |
> |
odRedrawAll(); |
| 1030 |
> |
setglpersp(); /* reset view & clipping planes */ |
| 1031 |
|
} |
| 1032 |
|
|
| 1033 |
|
|
| 1034 |
< |
static |
| 1035 |
< |
getkey(ekey) /* get input key */ |
| 1036 |
< |
register XKeyPressedEvent *ekey; |
| 1034 |
> |
static void |
| 1035 |
> |
getkey( /* get input key */ |
| 1036 |
> |
register XKeyPressedEvent *ekey |
| 1037 |
> |
) |
| 1038 |
|
{ |
| 1039 |
|
Window rootw, childw; |
| 1040 |
|
int rootx, rooty, wx, wy; |
| 1047 |
|
return; |
| 1048 |
|
switch (buf[0]) { |
| 1049 |
|
case 'h': /* turn on height motion lock */ |
| 1050 |
< |
headlocked = 1; |
| 1050 |
> |
viewflags |= VWHEADLOCK; |
| 1051 |
|
return; |
| 1052 |
|
case 'H': /* turn off height motion lock */ |
| 1053 |
< |
headlocked = 0; |
| 1053 |
> |
viewflags &= ~VWHEADLOCK; |
| 1054 |
|
return; |
| 1055 |
|
case 'l': /* retrieve last view */ |
| 1056 |
|
inpresflags |= DFL(DC_LASTVIEW); |
| 1078 |
|
inpresflags |= DFL(DC_RESUME); |
| 1079 |
|
return; |
| 1080 |
|
case CTRL('R'): /* redraw screen */ |
| 1081 |
< |
odRemap(0); |
| 1082 |
< |
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); |
| 1081 |
> |
odRemap(0); /* new tone mapping */ |
| 1082 |
> |
glClear(GL_DEPTH_BUFFER_BIT); |
| 1083 |
|
#ifdef STEREO |
| 1084 |
|
setstereobuf(STEREO_BUFFER_RIGHT); |
| 1085 |
< |
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); |
| 1085 |
> |
glClear(GL_DEPTH_BUFFER_BIT); |
| 1086 |
|
setstereobuf(STEREO_BUFFER_LEFT); |
| 1087 |
|
#endif |
| 1088 |
|
return; |
| 1089 |
|
case CTRL('L'): /* refresh from server */ |
| 1090 |
|
if (inpresflags & DFL(DC_REDRAW)) |
| 1091 |
< |
return; |
| 1091 |
> |
return; /* already called */ |
| 1092 |
|
XRaiseWindow(ourdisplay, gwind); |
| 1093 |
< |
XFlush(ourdisplay); |
| 1094 |
< |
sleep(1); |
| 1095 |
< |
wipeclean(); /* fresh display */ |
| 1096 |
< |
odRemap(1); /* fresh tone mapping */ |
| 1011 |
< |
dev_flush(); /* draw octrees */ |
| 1093 |
> |
XFlush(ourdisplay); /* raise up window */ |
| 1094 |
> |
sleep(1); /* wait for restacking */ |
| 1095 |
> |
dev_clear(); /* clear buffer and samples */ |
| 1096 |
> |
odRemap(1); /* start fresh histogram */ |
| 1097 |
|
inpresflags |= DFL(DC_REDRAW); /* resend values from server */ |
| 1013 |
– |
rayqleft = 0; /* hold off update */ |
| 1098 |
|
return; |
| 1099 |
|
case 'K': /* kill rtrace process(es) */ |
| 1100 |
|
inpresflags |= DFL(DC_KILL); |
| 1115 |
|
} |
| 1116 |
|
|
| 1117 |
|
|
| 1118 |
< |
static |
| 1119 |
< |
fixwindow(eexp) /* repair damage to window */ |
| 1120 |
< |
register XExposeEvent *eexp; |
| 1118 |
> |
static void |
| 1119 |
> |
fixwindow( /* repair damage to window */ |
| 1120 |
> |
register XExposeEvent *eexp |
| 1121 |
> |
) |
| 1122 |
|
{ |
| 1123 |
|
int xmin, ymin, xmax, ymax; |
| 1124 |
|
|
| 1125 |
< |
if (odev.hres == 0 | odev.vres == 0) { /* first exposure */ |
| 1125 |
> |
if ((odev.hres == 0) | (odev.vres == 0)) { /* first exposure */ |
| 1126 |
|
resizewindow((XConfigureEvent *)eexp); |
| 1127 |
|
return; |
| 1128 |
|
} |
| 1129 |
|
xmin = eexp->x; xmax = eexp->x + eexp->width; |
| 1130 |
|
ymin = odev.vres - eexp->y - eexp->height; ymax = odev.vres - eexp->y; |
| 1131 |
+ |
|
| 1132 |
+ |
if (xmin <= 0 && xmax >= odev.hres-1 && |
| 1133 |
+ |
ymin <= 0 && ymax >= odev.vres) { |
| 1134 |
+ |
DCHECK(eexp->count, WARNING, "multiple clear in fixwindow"); |
| 1135 |
+ |
wipeclean(); /* make sure we're go */ |
| 1136 |
+ |
return; |
| 1137 |
+ |
} |
| 1138 |
|
/* clear portion of depth */ |
| 1139 |
|
glPushAttrib(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); |
| 1140 |
|
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); |
| 1161 |
|
} |
| 1162 |
|
|
| 1163 |
|
|
| 1164 |
< |
static |
| 1165 |
< |
resizewindow(ersz) /* resize window */ |
| 1166 |
< |
register XConfigureEvent *ersz; |
| 1164 |
> |
static void |
| 1165 |
> |
resizewindow( /* resize window */ |
| 1166 |
> |
register XConfigureEvent *ersz |
| 1167 |
> |
) |
| 1168 |
|
{ |
| 1169 |
|
glViewport(0, 0, ersz->width, ersz->height); |
| 1170 |
|
|
| 1178 |
|
odev.v.vert = 2.*180./PI * atan(0.5/VIEWDIST*pheight*odev.vres); |
| 1179 |
|
|
| 1180 |
|
inpresflags |= DFL(DC_SETVIEW); |
| 1181 |
+ |
viewflags |= VWCHANGE; |
| 1182 |
|
} |