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.c"
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 extern int striplength_skin_13
[];
53 extern float stripdata_skin_13
[];
55 extern int striplength_skin_12
[];
56 extern float stripdata_skin_12
[];
58 extern int striplength_skin_11
[];
59 extern float stripdata_skin_11
[];
61 extern int striplength_skin_9
[];
62 extern float stripdata_skin_9
[];
65 static float obs
[3] = { 1000.0, 0.0, 2.0 };
68 static float alpha
= 90.0;
69 static float beta
= 90.0;
72 static int bfcull
= 1;
73 static int usetex
= 1;
74 static int cstrip
= 0;
76 static int joyavailable
= 0;
77 static int joyactive
= 0;
79 static int channel
[2];
81 static GLuint t1id
, t2id
;
86 glGenTextures(1, &t1id
);
87 glBindTexture(GL_TEXTURE_2D
, t1id
);
89 if (!LoadRGBMipmaps("../images/tile.rgb", GL_RGB
)) {
90 fprintf(stderr
, "Error reading a texture.\n");
94 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
95 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
97 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
,
98 GL_LINEAR_MIPMAP_NEAREST
);
99 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
101 glGenTextures(1, &t2id
);
102 glBindTexture(GL_TEXTURE_2D
, t2id
);
104 if (!LoadRGBMipmaps("../images/bw.rgb", GL_RGB
)) {
105 fprintf(stderr
, "Error reading a texture.\n");
109 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
110 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
112 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
,
113 GL_LINEAR_MIPMAP_NEAREST
);
114 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
116 glTexEnvf(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_MODULATE
);
120 drawobjs(int *l
, float *f
)
125 float r
= 0.33, g
= 0.33, b
= 0.33;
143 glBegin(GL_TRIANGLE_STRIP
);
144 for (j
= 0; j
< mend
; j
++) {
158 glBegin(GL_TRIANGLE_STRIP
);
159 for (j
= 0; j
< mend
; j
++) {
174 dir
[0] = sin(alpha
* M_PI
/ 180.0);
175 dir
[1] = cos(alpha
* M_PI
/ 180.0) * sin(beta
* M_PI
/ 180.0);
176 dir
[2] = cos(beta
* M_PI
/ 180.0);
178 obs
[0] += v
* dir
[0];
179 obs
[1] += v
* dir
[1];
180 obs
[2] += v
* dir
[2];
184 special(int k
, int x
, int y
)
203 key(unsigned char k
, int x
, int y
)
219 fullscreen
= (!fullscreen
);
221 glutSetWindow(channel
[0]);
222 XMesaSetFXmode(fullscreen
? XMESA_FX_FULLSCREEN
: XMESA_FX_WINDOW
);
224 glutSetWindow(channel
[1]);
225 XMesaSetFXmode(fullscreen
? XMESA_FX_FULLSCREEN
: XMESA_FX_WINDOW
);
230 joyactive
= (!joyactive
);
243 glDisable(GL_CULL_FACE
);
247 glEnable(GL_CULL_FACE
);
256 fprintf(stderr
, "Deleting textures...\n");
257 glDeleteTextures(1, &t1id
);
258 glDeleteTextures(1, &t2id
);
259 fprintf(stderr
, "Loading textures...\n");
261 fprintf(stderr
, "Done.\n");
267 reshapechannel0(int w
, int h
)
273 glMatrixMode(GL_PROJECTION
);
276 ratio
= 0.5f
* w
/ (float) h
;
278 glFrustum(-2.0, 0.0, -1.0 * ratio
, 1.0 * ratio
, 1.0, 60.0);
280 glMatrixMode(GL_MODELVIEW
);
282 glViewport(0, 0, w
, h
);
286 reshapechannel1(int w
, int h
)
292 glMatrixMode(GL_PROJECTION
);
295 ratio
= 0.5f
* w
/ (float) h
;
297 glFrustum(0.0, 2.0, -1.0 * ratio
, 1.0 * ratio
, 1.0, 60.0);
299 glMatrixMode(GL_MODELVIEW
);
301 glViewport(0, 0, w
, h
);
305 printstring(void *font
, char *string
)
309 len
= (int) strlen(string
);
310 for (i
= 0; i
< len
; i
++)
311 glutBitmapCharacter(font
, string
[i
]);
317 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
318 glColor4f(0.0, 0.0, 0.0, 0.5);
319 glRecti(40, 40, 600, 440);
321 glColor3f(1.0, 0.0, 0.0);
322 glRasterPos2i(300, 420);
323 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "Help");
325 glRasterPos2i(60, 390);
326 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "h - Togle Help");
327 glRasterPos2i(60, 360);
328 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "t - Togle Textures");
329 glRasterPos2i(60, 330);
330 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "f - Togle Fog");
331 glRasterPos2i(60, 300);
332 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "m - Togle strips");
333 glRasterPos2i(60, 270);
334 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "b - Togle Back face culling");
335 glRasterPos2i(60, 240);
336 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "Arrow Keys - Rotate");
337 glRasterPos2i(60, 210);
338 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "a - Increase velocity");
339 glRasterPos2i(60, 180);
340 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "z - Decrease velocity");
342 glRasterPos2i(60, 150);
344 printstring(GLUT_BITMAP_TIMES_ROMAN_24
,
345 "j - Togle jostick control (Joystick control available)");
347 printstring(GLUT_BITMAP_TIMES_ROMAN_24
,
348 "(No Joystick control available)");
355 static UINT max
[2] = { 0, 0 };
356 static UINT min
[2] = { 0xffffffff, 0xffffffff }, center
[2];
360 res
= joyGetPos(JOYSTICKID1
, &joy
);
362 if (res
== JOYERR_NOERROR
) {
365 if (max
[0] < joy
.wXpos
)
367 if (min
[0] > joy
.wXpos
)
369 center
[0] = (max
[0] + min
[0]) / 2;
371 if (max
[1] < joy
.wYpos
)
373 if (min
[1] > joy
.wYpos
)
375 center
[1] = (max
[1] + min
[1]) / 2;
378 if (fabs(center
[0] - (float) joy
.wXpos
) > 0.1 * (max
[0] - min
[0]))
380 2.0 * (center
[0] - (float) joy
.wXpos
) / (max
[0] - min
[0]);
381 if (fabs(center
[1] - (float) joy
.wYpos
) > 0.1 * (max
[1] - min
[1]))
382 beta
+= 2.0 * (center
[1] - (float) joy
.wYpos
) / (max
[1] - min
[1]);
384 if (joy
.wButtons
& JOY_BUTTON1
)
386 if (joy
.wButtons
& JOY_BUTTON2
)
398 static char frbuf
[80] = "";
404 glClear(GL_COLOR_BUFFER_BIT
);
406 glClear(GL_COLOR_BUFFER_BIT
);
409 glEnable(GL_TEXTURE_2D
);
411 glDisable(GL_TEXTURE_2D
);
418 glShadeModel(GL_SMOOTH
);
422 gluLookAt(obs
[0], obs
[1], obs
[2],
423 obs
[0] + dir
[0], obs
[1] + dir
[1], obs
[2] + dir
[2],
428 base
= obs
[0] - fmod(obs
[0], 8.0);
432 base
= obs
[0] + (8.0 - fmod(obs
[0], 8.0));
436 glTranslatef(base
- offset
/ 2.0, 0.0, 0.0);
437 for (i
= 0; i
< NUMBLOC
; i
++) {
438 glTranslatef(offset
, 0.0, 0.0);
439 glBindTexture(GL_TEXTURE_2D
, t1id
);
440 drawobjs(striplength_skin_11
, stripdata_skin_11
);
441 glBindTexture(GL_TEXTURE_2D
, t2id
);
442 drawobjs(striplength_skin_12
, stripdata_skin_12
);
443 drawobjs(striplength_skin_9
, stripdata_skin_9
);
444 drawobjs(striplength_skin_13
, stripdata_skin_13
);
449 glDisable(GL_TEXTURE_2D
);
451 glShadeModel(GL_FLAT
);
453 glMatrixMode(GL_PROJECTION
);
456 glOrtho(-0.5, 639.5, -0.5, 479.5, -1.0, 1.0);
458 glMatrixMode(GL_MODELVIEW
);
461 glColor3f(1.0, 0.0, 0.0);
462 glRasterPos2i(10, 10);
463 printstring(GLUT_BITMAP_HELVETICA_18
, frbuf
);
464 glRasterPos2i(350, 470);
465 printstring(GLUT_BITMAP_HELVETICA_10
,
466 "Tunnel2 V1.0 Written by David Bucciarelli (tech.hmw@plus.it)");
471 glMatrixMode(GL_PROJECTION
);
473 glMatrixMode(GL_MODELVIEW
);
477 GLint t
= glutGet(GLUT_ELAPSED_TIME
);
478 if (t
- T0
>= 2000) {
479 GLfloat seconds
= (t
- T0
) / 1000.0;
480 GLfloat fps
= Frames
/ seconds
;
481 sprintf(frbuf
, "Frame rate: %f", fps
);
491 glutSetWindow(channel
[0]);
499 glutSetWindow(channel
[1]);
507 glutSetWindow(channel
[0]);
509 glutSetWindow(channel
[1]);
512 glutSetWindow(channel
[0]);
514 glutSetWindow(channel
[1]);
521 float fogcolor
[4] = { 0.7, 0.7, 0.7, 1.0 };
523 glShadeModel(GL_SMOOTH
);
524 glDisable(GL_DEPTH_TEST
);
525 glEnable(GL_CULL_FACE
);
526 glEnable(GL_TEXTURE_2D
);
529 glFogi(GL_FOG_MODE
, GL_EXP2
);
530 glFogfv(GL_FOG_COLOR
, fogcolor
);
532 glFogf(GL_FOG_DENSITY
, 0.06);
533 glHint(GL_FOG_HINT
, GL_NICEST
);
537 glBlendFunc(GL_SRC_ALPHA_SATURATE, GL_ONE);
538 glEnable(GL_POLYGON_SMOOTH);
541 glClearColor(fogcolor
[0], fogcolor
[1], fogcolor
[2], fogcolor
[3]);
542 glClear(GL_COLOR_BUFFER_BIT
);
546 main(int ac
, char **av
)
549 "Tunnel2 V1.0\nWritten by David Bucciarelli (tech.hmw@plus.it)\n");
551 "You need TWO Voodoo Graphics boards in order to run this demo !\n");
553 glutInitWindowPosition(0, 0);
554 glutInitWindowSize(WIDTHC0
, HEIGHTC0
);
557 glutInitDisplayMode(GLUT_RGB
| GLUT_DOUBLE
);
560 if (!fxMesaSelectCurrentBoard(0)) {
561 fprintf(stderr
, "The first Voodoo Graphics board is missing !?!?\n");
565 if (!(channel
[0] = glutCreateWindow("Channel 0"))) {
566 fprintf(stderr
, "Error, couldn't open window\n");
570 reshapechannel0(WIDTHC0
, HEIGHTC0
);
573 glutDisplayFunc(drawchannel0
);
574 glutReshapeFunc(reshapechannel0
);
575 glutKeyboardFunc(key
);
576 glutSpecialFunc(special
);
579 if (!fxMesaSelectCurrentBoard(1)) {
580 fprintf(stderr
, "The second Voodoo Graphics board is missing !\n");
584 glutInitWindowPosition(WIDTHC0
, 0);
585 glutInitWindowSize(WIDTHC1
, HEIGHTC1
);
586 if (!(channel
[1] = glutCreateWindow("Channel 1"))) {
587 fprintf(stderr
, "Error, couldn't open window\n");
591 reshapechannel1(WIDTHC1
, HEIGHTC1
);
594 glutDisplayFunc(drawchannel1
);
595 glutReshapeFunc(reshapechannel1
);
596 glutKeyboardFunc(key
);
597 glutSpecialFunc(special
);
599 glutIdleFunc(drawall
);