2 * This program is under the GNU GPL.
3 * Use at your own risk.
5 * You need TWO Voodoo Graphics boards in order to run
8 * written by David Bucciarelli (tech.hmw@plus.it)
23 #include "tunneldat.h"
30 static int fullscreen
= 1;
34 GLint
fxMesaSelectCurrentBoard(int);
37 static int WIDTHC0
= 640;
38 static int HEIGHTC0
= 480;
40 static int WIDTHC1
= 640;
41 static int HEIGHTC1
= 480;
44 static GLint Frames
= 0;
49 #define M_PI 3.1415926535
52 static float obs
[3] = { 1000.0, 0.0, 2.0 };
55 static float alpha
= 90.0;
56 static float beta
= 90.0;
59 static int bfcull
= 1;
60 static int usetex
= 1;
61 static int cstrip
= 0;
63 static int joyavailable
= 0;
64 static int joyactive
= 0;
66 static int channel
[2];
68 static GLuint t1id
, t2id
;
73 glGenTextures(1, &t1id
);
74 glBindTexture(GL_TEXTURE_2D
, t1id
);
76 if (!LoadRGBMipmaps("../images/tile.rgb", GL_RGB
)) {
77 fprintf(stderr
, "Error reading a texture.\n");
81 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
82 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
84 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
,
85 GL_LINEAR_MIPMAP_NEAREST
);
86 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
88 glGenTextures(1, &t2id
);
89 glBindTexture(GL_TEXTURE_2D
, t2id
);
91 if (!LoadRGBMipmaps("../images/bw.rgb", GL_RGB
)) {
92 fprintf(stderr
, "Error reading a texture.\n");
96 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
97 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
99 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
,
100 GL_LINEAR_MIPMAP_LINEAR
);
101 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
103 glTexEnvf(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_MODULATE
);
107 drawobjs(const int *l
, const float *f
)
112 float r
= 0.33, g
= 0.33, b
= 0.33;
130 glBegin(GL_TRIANGLE_STRIP
);
131 for (j
= 0; j
< mend
; j
++) {
145 glBegin(GL_TRIANGLE_STRIP
);
146 for (j
= 0; j
< mend
; j
++) {
161 static double t0
= -1.;
162 double dt
, t
= glutGet(GLUT_ELAPSED_TIME
) / 1000.0;
168 dir
[0] = sin(alpha
* M_PI
/ 180.0);
169 dir
[1] = cos(alpha
* M_PI
/ 180.0) * sin(beta
* M_PI
/ 180.0);
170 dir
[2] = cos(beta
* M_PI
/ 180.0);
172 if (dir
[0] < 1.0e-5 && dir
[0] > -1.0e-5)
174 if (dir
[1] < 1.0e-5 && dir
[1] > -1.0e-5)
176 if (dir
[2] < 1.0e-5 && dir
[2] > -1.0e-5)
179 obs
[0] += v
* dir
[0] * dt
;
180 obs
[1] += v
* dir
[1] * dt
;
181 obs
[2] += v
* dir
[2] * dt
;
185 special(int k
, int x
, int y
)
206 glDeleteTextures(1, &t1id
);
207 glDeleteTextures(1, &t2id
);
211 key(unsigned char k
, int x
, int y
)
215 glutDestroyWindow(channel
[0]);
216 glutDestroyWindow(channel
[1]);
230 fullscreen
= (!fullscreen
);
232 glutSetWindow(channel
[0]);
233 XMesaSetFXmode(fullscreen
? XMESA_FX_FULLSCREEN
: XMESA_FX_WINDOW
);
235 glutSetWindow(channel
[1]);
236 XMesaSetFXmode(fullscreen
? XMESA_FX_FULLSCREEN
: XMESA_FX_WINDOW
);
241 joyactive
= (!joyactive
);
254 glDisable(GL_CULL_FACE
);
258 glEnable(GL_CULL_FACE
);
267 fprintf(stderr
, "Deleting textures...\n");
268 glDeleteTextures(1, &t1id
);
269 glDeleteTextures(1, &t2id
);
270 fprintf(stderr
, "Loading textures...\n");
272 fprintf(stderr
, "Done.\n");
278 reshapechannel0(int w
, int h
)
284 glMatrixMode(GL_PROJECTION
);
287 ratio
= 0.5f
* w
/ (float) h
;
289 glFrustum(-2.0, 0.0, -1.0 * ratio
, 1.0 * ratio
, 1.0, 60.0);
291 glMatrixMode(GL_MODELVIEW
);
293 glViewport(0, 0, w
, h
);
297 reshapechannel1(int w
, int h
)
303 glMatrixMode(GL_PROJECTION
);
306 ratio
= 0.5f
* w
/ (float) h
;
308 glFrustum(0.0, 2.0, -1.0 * ratio
, 1.0 * ratio
, 1.0, 60.0);
310 glMatrixMode(GL_MODELVIEW
);
312 glViewport(0, 0, w
, h
);
316 printstring(void *font
, char *string
)
320 len
= (int) strlen(string
);
321 for (i
= 0; i
< len
; i
++)
322 glutBitmapCharacter(font
, string
[i
]);
328 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
329 glColor4f(0.0, 0.0, 0.0, 0.5);
330 glRecti(40, 40, 600, 440);
332 glColor3f(1.0, 0.0, 0.0);
333 glRasterPos2i(300, 420);
334 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "Help");
336 glRasterPos2i(60, 390);
337 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "h - Toggle Help");
338 glRasterPos2i(60, 360);
339 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "t - Toggle Textures");
340 glRasterPos2i(60, 330);
341 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "f - Toggle Fog");
342 glRasterPos2i(60, 300);
343 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "m - Toggle strips");
344 glRasterPos2i(60, 270);
345 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "b - Toggle Back face culling");
346 glRasterPos2i(60, 240);
347 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "Arrow Keys - Rotate");
348 glRasterPos2i(60, 210);
349 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "a - Increase velocity");
350 glRasterPos2i(60, 180);
351 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "z - Decrease velocity");
353 glRasterPos2i(60, 150);
355 printstring(GLUT_BITMAP_TIMES_ROMAN_24
,
356 "j - Toggle jostick control (Joystick control available)");
358 printstring(GLUT_BITMAP_TIMES_ROMAN_24
,
359 "(No Joystick control available)");
366 static UINT max
[2] = { 0, 0 };
367 static UINT min
[2] = { 0xffffffff, 0xffffffff }, center
[2];
371 res
= joyGetPos(JOYSTICKID1
, &joy
);
373 if (res
== JOYERR_NOERROR
) {
376 if (max
[0] < joy
.wXpos
)
378 if (min
[0] > joy
.wXpos
)
380 center
[0] = (max
[0] + min
[0]) / 2;
382 if (max
[1] < joy
.wYpos
)
384 if (min
[1] > joy
.wYpos
)
386 center
[1] = (max
[1] + min
[1]) / 2;
389 if (fabs(center
[0] - (float) joy
.wXpos
) > 0.1 * (max
[0] - min
[0]))
391 2.0 * (center
[0] - (float) joy
.wXpos
) / (max
[0] - min
[0]);
392 if (fabs(center
[1] - (float) joy
.wYpos
) > 0.1 * (max
[1] - min
[1]))
393 beta
+= 2.0 * (center
[1] - (float) joy
.wYpos
) / (max
[1] - min
[1]);
395 if (joy
.wButtons
& JOY_BUTTON1
)
397 if (joy
.wButtons
& JOY_BUTTON2
)
409 static char frbuf
[80] = "";
415 glClear(GL_COLOR_BUFFER_BIT
);
417 glClear(GL_COLOR_BUFFER_BIT
);
420 glEnable(GL_TEXTURE_2D
);
422 glDisable(GL_TEXTURE_2D
);
429 glShadeModel(GL_SMOOTH
);
433 gluLookAt(obs
[0], obs
[1], obs
[2],
434 obs
[0] + dir
[0], obs
[1] + dir
[1], obs
[2] + dir
[2],
439 base
= obs
[0] - fmod(obs
[0], 8.0);
443 base
= obs
[0] + (8.0 - fmod(obs
[0], 8.0));
447 glTranslatef(base
- offset
/ 2.0, 0.0, 0.0);
448 for (i
= 0; i
< NUMBLOC
; i
++) {
449 glTranslatef(offset
, 0.0, 0.0);
450 glBindTexture(GL_TEXTURE_2D
, t1id
);
451 drawobjs(striplength_skin_11
, stripdata_skin_11
);
452 glBindTexture(GL_TEXTURE_2D
, t2id
);
453 drawobjs(striplength_skin_12
, stripdata_skin_12
);
454 drawobjs(striplength_skin_9
, stripdata_skin_9
);
455 drawobjs(striplength_skin_13
, stripdata_skin_13
);
460 glDisable(GL_TEXTURE_2D
);
462 glShadeModel(GL_FLAT
);
464 glMatrixMode(GL_PROJECTION
);
467 glOrtho(-0.5, 639.5, -0.5, 479.5, -1.0, 1.0);
469 glMatrixMode(GL_MODELVIEW
);
472 glColor3f(1.0, 0.0, 0.0);
473 glRasterPos2i(10, 10);
474 printstring(GLUT_BITMAP_HELVETICA_18
, frbuf
);
475 glRasterPos2i(350, 470);
476 printstring(GLUT_BITMAP_HELVETICA_10
,
477 "Tunnel2 V1.0 Written by David Bucciarelli (tech.hmw@plus.it)");
482 glMatrixMode(GL_PROJECTION
);
484 glMatrixMode(GL_MODELVIEW
);
488 GLint t
= glutGet(GLUT_ELAPSED_TIME
);
489 if (t
- T0
>= 2000) {
490 GLfloat seconds
= (t
- T0
) / 1000.0;
491 GLfloat fps
= Frames
/ seconds
;
492 sprintf(frbuf
, "Frame rate: %f", fps
);
502 glutSetWindow(channel
[0]);
510 glutSetWindow(channel
[1]);
518 glutSetWindow(channel
[0]);
520 glutSetWindow(channel
[1]);
523 glutSetWindow(channel
[0]);
525 glutSetWindow(channel
[1]);
532 float fogcolor
[4] = { 0.7, 0.7, 0.7, 1.0 };
534 glShadeModel(GL_SMOOTH
);
535 glDisable(GL_DEPTH_TEST
);
536 glEnable(GL_CULL_FACE
);
537 glEnable(GL_TEXTURE_2D
);
540 glFogi(GL_FOG_MODE
, GL_EXP2
);
541 glFogfv(GL_FOG_COLOR
, fogcolor
);
543 glFogf(GL_FOG_DENSITY
, 0.06);
544 glHint(GL_FOG_HINT
, GL_NICEST
);
548 glBlendFunc(GL_SRC_ALPHA_SATURATE, GL_ONE);
549 glEnable(GL_POLYGON_SMOOTH);
552 glClearColor(fogcolor
[0], fogcolor
[1], fogcolor
[2], fogcolor
[3]);
553 glClear(GL_COLOR_BUFFER_BIT
);
557 main(int ac
, char **av
)
560 "Tunnel2 V1.0\nWritten by David Bucciarelli (tech.hmw@plus.it)\n");
562 glutInitWindowSize(WIDTHC0
, HEIGHTC0
);
565 glutInitDisplayMode(GLUT_RGB
| GLUT_DOUBLE
);
568 if (fxMesaSelectCurrentBoard(0) < 0) {
569 fprintf(stderr
, "The first Voodoo Graphics board is missing !?!?\n");
573 if (!(channel
[0] = glutCreateWindow("Channel 0"))) {
574 fprintf(stderr
, "Error, couldn't open window\n");
578 reshapechannel0(WIDTHC0
, HEIGHTC0
);
581 glutDisplayFunc(drawchannel0
);
582 glutReshapeFunc(reshapechannel0
);
583 glutKeyboardFunc(key
);
584 glutSpecialFunc(special
);
587 if (fxMesaSelectCurrentBoard(1) < 0) {
588 fprintf(stderr
, "The second Voodoo Graphics board is missing !\n");
592 glutInitWindowPosition(WIDTHC0
, 0);
593 glutInitWindowSize(WIDTHC1
, HEIGHTC1
);
594 if (!(channel
[1] = glutCreateWindow("Channel 1"))) {
595 fprintf(stderr
, "Error, couldn't open window\n");
599 reshapechannel1(WIDTHC1
, HEIGHTC1
);
602 glutDisplayFunc(drawchannel1
);
603 glutReshapeFunc(reshapechannel1
);
604 glutKeyboardFunc(key
);
605 glutSpecialFunc(special
);
607 glutIdleFunc(drawall
);