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 GLboolean
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_NEAREST
);
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 dir
[0] = sin(alpha
* M_PI
/ 180.0);
162 dir
[1] = cos(alpha
* M_PI
/ 180.0) * sin(beta
* M_PI
/ 180.0);
163 dir
[2] = cos(beta
* M_PI
/ 180.0);
165 obs
[0] += v
* dir
[0];
166 obs
[1] += v
* dir
[1];
167 obs
[2] += v
* dir
[2];
171 special(int k
, int x
, int y
)
190 key(unsigned char k
, int x
, int y
)
206 fullscreen
= (!fullscreen
);
208 glutSetWindow(channel
[0]);
209 XMesaSetFXmode(fullscreen
? XMESA_FX_FULLSCREEN
: XMESA_FX_WINDOW
);
211 glutSetWindow(channel
[1]);
212 XMesaSetFXmode(fullscreen
? XMESA_FX_FULLSCREEN
: XMESA_FX_WINDOW
);
217 joyactive
= (!joyactive
);
230 glDisable(GL_CULL_FACE
);
234 glEnable(GL_CULL_FACE
);
243 fprintf(stderr
, "Deleting textures...\n");
244 glDeleteTextures(1, &t1id
);
245 glDeleteTextures(1, &t2id
);
246 fprintf(stderr
, "Loading textures...\n");
248 fprintf(stderr
, "Done.\n");
254 reshapechannel0(int w
, int h
)
260 glMatrixMode(GL_PROJECTION
);
263 ratio
= 0.5f
* w
/ (float) h
;
265 glFrustum(-2.0, 0.0, -1.0 * ratio
, 1.0 * ratio
, 1.0, 60.0);
267 glMatrixMode(GL_MODELVIEW
);
269 glViewport(0, 0, w
, h
);
273 reshapechannel1(int w
, int h
)
279 glMatrixMode(GL_PROJECTION
);
282 ratio
= 0.5f
* w
/ (float) h
;
284 glFrustum(0.0, 2.0, -1.0 * ratio
, 1.0 * ratio
, 1.0, 60.0);
286 glMatrixMode(GL_MODELVIEW
);
288 glViewport(0, 0, w
, h
);
292 printstring(void *font
, char *string
)
296 len
= (int) strlen(string
);
297 for (i
= 0; i
< len
; i
++)
298 glutBitmapCharacter(font
, string
[i
]);
304 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
305 glColor4f(0.0, 0.0, 0.0, 0.5);
306 glRecti(40, 40, 600, 440);
308 glColor3f(1.0, 0.0, 0.0);
309 glRasterPos2i(300, 420);
310 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "Help");
312 glRasterPos2i(60, 390);
313 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "h - Togle Help");
314 glRasterPos2i(60, 360);
315 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "t - Togle Textures");
316 glRasterPos2i(60, 330);
317 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "f - Togle Fog");
318 glRasterPos2i(60, 300);
319 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "m - Togle strips");
320 glRasterPos2i(60, 270);
321 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "b - Togle Back face culling");
322 glRasterPos2i(60, 240);
323 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "Arrow Keys - Rotate");
324 glRasterPos2i(60, 210);
325 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "a - Increase velocity");
326 glRasterPos2i(60, 180);
327 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "z - Decrease velocity");
329 glRasterPos2i(60, 150);
331 printstring(GLUT_BITMAP_TIMES_ROMAN_24
,
332 "j - Togle jostick control (Joystick control available)");
334 printstring(GLUT_BITMAP_TIMES_ROMAN_24
,
335 "(No Joystick control available)");
342 static UINT max
[2] = { 0, 0 };
343 static UINT min
[2] = { 0xffffffff, 0xffffffff }, center
[2];
347 res
= joyGetPos(JOYSTICKID1
, &joy
);
349 if (res
== JOYERR_NOERROR
) {
352 if (max
[0] < joy
.wXpos
)
354 if (min
[0] > joy
.wXpos
)
356 center
[0] = (max
[0] + min
[0]) / 2;
358 if (max
[1] < joy
.wYpos
)
360 if (min
[1] > joy
.wYpos
)
362 center
[1] = (max
[1] + min
[1]) / 2;
365 if (fabs(center
[0] - (float) joy
.wXpos
) > 0.1 * (max
[0] - min
[0]))
367 2.0 * (center
[0] - (float) joy
.wXpos
) / (max
[0] - min
[0]);
368 if (fabs(center
[1] - (float) joy
.wYpos
) > 0.1 * (max
[1] - min
[1]))
369 beta
+= 2.0 * (center
[1] - (float) joy
.wYpos
) / (max
[1] - min
[1]);
371 if (joy
.wButtons
& JOY_BUTTON1
)
373 if (joy
.wButtons
& JOY_BUTTON2
)
385 static char frbuf
[80] = "";
391 glClear(GL_COLOR_BUFFER_BIT
);
393 glClear(GL_COLOR_BUFFER_BIT
);
396 glEnable(GL_TEXTURE_2D
);
398 glDisable(GL_TEXTURE_2D
);
405 glShadeModel(GL_SMOOTH
);
409 gluLookAt(obs
[0], obs
[1], obs
[2],
410 obs
[0] + dir
[0], obs
[1] + dir
[1], obs
[2] + dir
[2],
415 base
= obs
[0] - fmod(obs
[0], 8.0);
419 base
= obs
[0] + (8.0 - fmod(obs
[0], 8.0));
423 glTranslatef(base
- offset
/ 2.0, 0.0, 0.0);
424 for (i
= 0; i
< NUMBLOC
; i
++) {
425 glTranslatef(offset
, 0.0, 0.0);
426 glBindTexture(GL_TEXTURE_2D
, t1id
);
427 drawobjs(striplength_skin_11
, stripdata_skin_11
);
428 glBindTexture(GL_TEXTURE_2D
, t2id
);
429 drawobjs(striplength_skin_12
, stripdata_skin_12
);
430 drawobjs(striplength_skin_9
, stripdata_skin_9
);
431 drawobjs(striplength_skin_13
, stripdata_skin_13
);
436 glDisable(GL_TEXTURE_2D
);
438 glShadeModel(GL_FLAT
);
440 glMatrixMode(GL_PROJECTION
);
443 glOrtho(-0.5, 639.5, -0.5, 479.5, -1.0, 1.0);
445 glMatrixMode(GL_MODELVIEW
);
448 glColor3f(1.0, 0.0, 0.0);
449 glRasterPos2i(10, 10);
450 printstring(GLUT_BITMAP_HELVETICA_18
, frbuf
);
451 glRasterPos2i(350, 470);
452 printstring(GLUT_BITMAP_HELVETICA_10
,
453 "Tunnel2 V1.0 Written by David Bucciarelli (tech.hmw@plus.it)");
458 glMatrixMode(GL_PROJECTION
);
460 glMatrixMode(GL_MODELVIEW
);
464 GLint t
= glutGet(GLUT_ELAPSED_TIME
);
465 if (t
- T0
>= 2000) {
466 GLfloat seconds
= (t
- T0
) / 1000.0;
467 GLfloat fps
= Frames
/ seconds
;
468 sprintf(frbuf
, "Frame rate: %f", fps
);
478 glutSetWindow(channel
[0]);
486 glutSetWindow(channel
[1]);
494 glutSetWindow(channel
[0]);
496 glutSetWindow(channel
[1]);
499 glutSetWindow(channel
[0]);
501 glutSetWindow(channel
[1]);
508 float fogcolor
[4] = { 0.7, 0.7, 0.7, 1.0 };
510 glShadeModel(GL_SMOOTH
);
511 glDisable(GL_DEPTH_TEST
);
512 glEnable(GL_CULL_FACE
);
513 glEnable(GL_TEXTURE_2D
);
516 glFogi(GL_FOG_MODE
, GL_EXP2
);
517 glFogfv(GL_FOG_COLOR
, fogcolor
);
519 glFogf(GL_FOG_DENSITY
, 0.06);
520 glHint(GL_FOG_HINT
, GL_NICEST
);
524 glBlendFunc(GL_SRC_ALPHA_SATURATE, GL_ONE);
525 glEnable(GL_POLYGON_SMOOTH);
528 glClearColor(fogcolor
[0], fogcolor
[1], fogcolor
[2], fogcolor
[3]);
529 glClear(GL_COLOR_BUFFER_BIT
);
533 main(int ac
, char **av
)
536 "Tunnel2 V1.0\nWritten by David Bucciarelli (tech.hmw@plus.it)\n");
538 glutInitWindowPosition(0, 0);
539 glutInitWindowSize(WIDTHC0
, HEIGHTC0
);
542 glutInitDisplayMode(GLUT_RGB
| GLUT_DOUBLE
);
545 if (!fxMesaSelectCurrentBoard(0)) {
546 fprintf(stderr
, "The first Voodoo Graphics board is missing !?!?\n");
550 if (!(channel
[0] = glutCreateWindow("Channel 0"))) {
551 fprintf(stderr
, "Error, couldn't open window\n");
555 reshapechannel0(WIDTHC0
, HEIGHTC0
);
558 glutDisplayFunc(drawchannel0
);
559 glutReshapeFunc(reshapechannel0
);
560 glutKeyboardFunc(key
);
561 glutSpecialFunc(special
);
564 if (!fxMesaSelectCurrentBoard(1)) {
565 fprintf(stderr
, "The second Voodoo Graphics board is missing !\n");
569 glutInitWindowPosition(WIDTHC0
, 0);
570 glutInitWindowSize(WIDTHC1
, HEIGHTC1
);
571 if (!(channel
[1] = glutCreateWindow("Channel 1"))) {
572 fprintf(stderr
, "Error, couldn't open window\n");
576 reshapechannel1(WIDTHC1
, HEIGHTC1
);
579 glutDisplayFunc(drawchannel1
);
580 glutReshapeFunc(reshapechannel1
);
581 glutKeyboardFunc(key
);
582 glutSpecialFunc(special
);
584 glutIdleFunc(drawall
);