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)
22 #include "../util/readtex.c"
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;
48 #define M_PI 3.1415926535
51 extern int striplength_skin_13
[];
52 extern float stripdata_skin_13
[];
54 extern int striplength_skin_12
[];
55 extern float stripdata_skin_12
[];
57 extern int striplength_skin_11
[];
58 extern float stripdata_skin_11
[];
60 extern int striplength_skin_9
[];
61 extern float stripdata_skin_9
[];
64 static float obs
[3] = { 1000.0, 0.0, 2.0 };
67 static float alpha
= 90.0;
68 static float beta
= 90.0;
71 static int bfcull
= 1;
72 static int usetex
= 1;
73 static int cstrip
= 0;
75 static int joyavailable
= 0;
76 static int joyactive
= 0;
78 static int channel
[2];
80 static GLuint t1id
, t2id
;
87 glGenTextures(1, &t1id
);
88 glBindTexture(GL_TEXTURE_2D
, t1id
);
90 if (!LoadRGBMipmaps("../images/tile.rgb", GL_RGB
)) {
91 fprintf(stderr
, "Error reading a texture.\n");
95 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
96 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
98 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
,
99 GL_LINEAR_MIPMAP_NEAREST
);
100 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
102 glGenTextures(1, &t2id
);
103 glBindTexture(GL_TEXTURE_2D
, t2id
);
105 if (!LoadRGBMipmaps("../images/bw.rgb", GL_RGB
)) {
106 fprintf(stderr
, "Error reading a texture.\n");
110 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
111 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
113 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
,
114 GL_LINEAR_MIPMAP_NEAREST
);
115 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
117 glTexEnvf(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_MODULATE
);
121 drawobjs(int *l
, float *f
)
126 float r
= 0.33, g
= 0.33, b
= 0.33;
144 glBegin(GL_TRIANGLE_STRIP
);
145 for (j
= 0; j
< mend
; j
++) {
159 glBegin(GL_TRIANGLE_STRIP
);
160 for (j
= 0; j
< mend
; j
++) {
175 static clock_t told
= 0;
184 return (ris
/ (float) CLOCKS_PER_SEC
);
190 dir
[0] = sin(alpha
* M_PI
/ 180.0);
191 dir
[1] = cos(alpha
* M_PI
/ 180.0) * sin(beta
* M_PI
/ 180.0);
192 dir
[2] = cos(beta
* M_PI
/ 180.0);
194 obs
[0] += v
* dir
[0];
195 obs
[1] += v
* dir
[1];
196 obs
[2] += v
* dir
[2];
200 special(int k
, int x
, int y
)
219 key(unsigned char k
, int x
, int y
)
235 fullscreen
= (!fullscreen
);
237 glutSetWindow(channel
[0]);
238 XMesaSetFXmode(fullscreen
? XMESA_FX_FULLSCREEN
: XMESA_FX_WINDOW
);
240 glutSetWindow(channel
[1]);
241 XMesaSetFXmode(fullscreen
? XMESA_FX_FULLSCREEN
: XMESA_FX_WINDOW
);
246 joyactive
= (!joyactive
);
259 glDisable(GL_CULL_FACE
);
263 glEnable(GL_CULL_FACE
);
272 fprintf(stderr
, "Deleting textures...\n");
273 glDeleteTextures(1, &t1id
);
274 glDeleteTextures(1, &t2id
);
275 fprintf(stderr
, "Loading textures...\n");
277 fprintf(stderr
, "Done.\n");
283 reshapechannel0(int w
, int h
)
289 glMatrixMode(GL_PROJECTION
);
292 ratio
= 0.5f
* w
/ (float) h
;
294 glFrustum(-2.0, 0.0, -1.0 * ratio
, 1.0 * ratio
, 1.0, 60.0);
296 glMatrixMode(GL_MODELVIEW
);
298 glViewport(0, 0, w
, h
);
302 reshapechannel1(int w
, int h
)
308 glMatrixMode(GL_PROJECTION
);
311 ratio
= 0.5f
* w
/ (float) h
;
313 glFrustum(0.0, 2.0, -1.0 * ratio
, 1.0 * ratio
, 1.0, 60.0);
315 glMatrixMode(GL_MODELVIEW
);
317 glViewport(0, 0, w
, h
);
321 printstring(void *font
, char *string
)
325 len
= (int) strlen(string
);
326 for (i
= 0; i
< len
; i
++)
327 glutBitmapCharacter(font
, string
[i
]);
333 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
334 glColor4f(0.0, 0.0, 0.0, 0.5);
335 glRecti(40, 40, 600, 440);
337 glColor3f(1.0, 0.0, 0.0);
338 glRasterPos2i(300, 420);
339 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "Help");
341 glRasterPos2i(60, 390);
342 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "h - Togle Help");
343 glRasterPos2i(60, 360);
344 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "t - Togle Textures");
345 glRasterPos2i(60, 330);
346 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "f - Togle Fog");
347 glRasterPos2i(60, 300);
348 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "m - Togle strips");
349 glRasterPos2i(60, 270);
350 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "b - Togle Back face culling");
351 glRasterPos2i(60, 240);
352 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "Arrow Keys - Rotate");
353 glRasterPos2i(60, 210);
354 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "a - Increase velocity");
355 glRasterPos2i(60, 180);
356 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "z - Decrease velocity");
358 glRasterPos2i(60, 150);
360 printstring(GLUT_BITMAP_TIMES_ROMAN_24
,
361 "j - Togle jostick control (Joystick control available)");
363 printstring(GLUT_BITMAP_TIMES_ROMAN_24
,
364 "(No Joystick control available)");
371 static UINT max
[2] = { 0, 0 };
372 static UINT min
[2] = { 0xffffffff, 0xffffffff }, center
[2];
376 res
= joyGetPos(JOYSTICKID1
, &joy
);
378 if (res
== JOYERR_NOERROR
) {
381 if (max
[0] < joy
.wXpos
)
383 if (min
[0] > joy
.wXpos
)
385 center
[0] = (max
[0] + min
[0]) / 2;
387 if (max
[1] < joy
.wYpos
)
389 if (min
[1] > joy
.wYpos
)
391 center
[1] = (max
[1] + min
[1]) / 2;
394 if (fabs(center
[0] - (float) joy
.wXpos
) > 0.1 * (max
[0] - min
[0]))
396 2.0 * (center
[0] - (float) joy
.wXpos
) / (max
[0] - min
[0]);
397 if (fabs(center
[1] - (float) joy
.wYpos
) > 0.1 * (max
[1] - min
[1]))
398 beta
+= 2.0 * (center
[1] - (float) joy
.wYpos
) / (max
[1] - min
[1]);
400 if (joy
.wButtons
& JOY_BUTTON1
)
402 if (joy
.wButtons
& JOY_BUTTON2
)
414 static int count
= 0;
415 static char frbuf
[80];
417 float fr
, base
, offset
;
421 glClear(GL_COLOR_BUFFER_BIT
);
423 glClear(GL_COLOR_BUFFER_BIT
);
426 glEnable(GL_TEXTURE_2D
);
428 glDisable(GL_TEXTURE_2D
);
435 glShadeModel(GL_SMOOTH
);
439 gluLookAt(obs
[0], obs
[1], obs
[2],
440 obs
[0] + dir
[0], obs
[1] + dir
[1], obs
[2] + dir
[2],
445 base
= obs
[0] - fmod(obs
[0], 8.0);
449 base
= obs
[0] + (8.0 - fmod(obs
[0], 8.0));
453 glTranslatef(base
- offset
/ 2.0, 0.0, 0.0);
454 for (i
= 0; i
< NUMBLOC
; i
++) {
455 glTranslatef(offset
, 0.0, 0.0);
456 glBindTexture(GL_TEXTURE_2D
, t1id
);
457 drawobjs(striplength_skin_11
, stripdata_skin_11
);
458 glBindTexture(GL_TEXTURE_2D
, t2id
);
459 drawobjs(striplength_skin_12
, stripdata_skin_12
);
460 drawobjs(striplength_skin_9
, stripdata_skin_9
);
461 drawobjs(striplength_skin_13
, stripdata_skin_13
);
466 if ((count
% FRAME
) == 0) {
468 sprintf(frbuf
, "Frame rate: %f", FRAME
/ fr
);
471 glDisable(GL_TEXTURE_2D
);
473 glShadeModel(GL_FLAT
);
475 glMatrixMode(GL_PROJECTION
);
478 glOrtho(-0.5, 639.5, -0.5, 479.5, -1.0, 1.0);
480 glMatrixMode(GL_MODELVIEW
);
483 glColor3f(1.0, 0.0, 0.0);
484 glRasterPos2i(10, 10);
485 printstring(GLUT_BITMAP_HELVETICA_18
, frbuf
);
486 glRasterPos2i(350, 470);
487 printstring(GLUT_BITMAP_HELVETICA_10
,
488 "Tunnel2 V1.0 Written by David Bucciarelli (tech.hmw@plus.it)");
493 glMatrixMode(GL_PROJECTION
);
495 glMatrixMode(GL_MODELVIEW
);
503 glutSetWindow(channel
[0]);
511 glutSetWindow(channel
[1]);
519 glutSetWindow(channel
[0]);
521 glutSetWindow(channel
[1]);
524 glutSetWindow(channel
[0]);
526 glutSetWindow(channel
[1]);
533 float fogcolor
[4] = { 0.7, 0.7, 0.7, 1.0 };
535 glShadeModel(GL_SMOOTH
);
536 glDisable(GL_DEPTH_TEST
);
537 glEnable(GL_CULL_FACE
);
538 glEnable(GL_TEXTURE_2D
);
541 glFogi(GL_FOG_MODE
, GL_EXP2
);
542 glFogfv(GL_FOG_COLOR
, fogcolor
);
544 glFogf(GL_FOG_DENSITY
, 0.06);
545 glHint(GL_FOG_HINT
, GL_NICEST
);
549 glBlendFunc(GL_SRC_ALPHA_SATURATE, GL_ONE);
550 glEnable(GL_POLYGON_SMOOTH);
553 glClearColor(fogcolor
[0], fogcolor
[1], fogcolor
[2], fogcolor
[3]);
554 glClear(GL_COLOR_BUFFER_BIT
);
558 main(int ac
, char **av
)
561 "Tunnel2 V1.0\nWritten by David Bucciarelli (tech.hmw@plus.it)\n");
563 "You need TWO Voodoo Graphics boards in order to run this demo !\n");
565 glutInitWindowPosition(0, 0);
566 glutInitWindowSize(WIDTHC0
, HEIGHTC0
);
569 glutInitDisplayMode(GLUT_RGB
| GLUT_DOUBLE
| GLUT_ALPHA
);
572 if (!fxMesaSelectCurrentBoard(0)) {
573 fprintf(stderr
, "The first Voodoo Graphics board is missing !?!?\n");
577 if (!(channel
[0] = glutCreateWindow("Channel 0"))) {
578 fprintf(stderr
, "Error, couldn't open window\n");
582 reshapechannel0(WIDTHC0
, HEIGHTC0
);
585 glutDisplayFunc(drawchannel0
);
586 glutReshapeFunc(reshapechannel0
);
587 glutKeyboardFunc(key
);
588 glutSpecialFunc(special
);
591 if (!fxMesaSelectCurrentBoard(1)) {
592 fprintf(stderr
, "The second Voodoo Graphics board is missing !\n");
596 glutInitWindowPosition(WIDTHC0
, 0);
597 glutInitWindowSize(WIDTHC1
, HEIGHTC1
);
598 if (!(channel
[1] = glutCreateWindow("Channel 1"))) {
599 fprintf(stderr
, "Error, couldn't open window\n");
603 reshapechannel1(WIDTHC1
, HEIGHTC1
);
606 glutDisplayFunc(drawchannel1
);
607 glutReshapeFunc(reshapechannel1
);
608 glutKeyboardFunc(key
);
609 glutSpecialFunc(special
);
611 glutIdleFunc(drawall
);