2 * This program is under the GNU GPL.
3 * Use at your own risk.
5 * written by David Bucciarelli (tech.hmw@plus.it)
19 #include "../util/readtex.c"
20 #include "tunneldat.c"
24 static int fullscreen
= 1;
27 static int WIDTH
= 640;
28 static int HEIGHT
= 480;
35 #define M_PI 3.1415926535
38 extern int striplength_skin_13
[];
39 extern float stripdata_skin_13
[];
41 extern int striplength_skin_12
[];
42 extern float stripdata_skin_12
[];
44 extern int striplength_skin_11
[];
45 extern float stripdata_skin_11
[];
47 extern int striplength_skin_9
[];
48 extern float stripdata_skin_9
[];
53 static float obs
[3] = { 1000.0, 0.0, 2.0 };
56 static float alpha
= 90.0;
57 static float beta
= 90.0;
60 static int bfcull
= 1;
61 static int usetex
= 1;
62 static int cstrip
= 0;
64 static int joyavailable
= 0;
65 static int joyactive
= 0;
67 static GLuint t1id
, t2id
;
72 glGenTextures(1, &t1id
);
73 glBindTexture(GL_TEXTURE_2D
, t1id
);
75 if (!LoadRGBMipmaps("../images/tile.rgb", GL_RGB
)) {
76 fprintf(stderr
, "Error reading a texture.\n");
80 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
81 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
83 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
,
84 GL_LINEAR_MIPMAP_LINEAR
);
85 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
87 glGenTextures(1, &t2id
);
88 glBindTexture(GL_TEXTURE_2D
, t2id
);
90 if (!LoadRGBMipmaps("../images/bw.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_LINEAR
);
100 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
102 glTexEnvf(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_MODULATE
);
106 drawobjs(int *l
, float *f
)
111 float r
= 0.33, g
= 0.33, b
= 0.33;
129 glBegin(GL_TRIANGLE_STRIP
);
130 for (j
= 0; j
< mend
; j
++) {
144 glBegin(GL_TRIANGLE_STRIP
);
145 for (j
= 0; j
< mend
; j
++) {
160 static clock_t told
= 0;
169 return (ris
/ (float) CLOCKS_PER_SEC
);
175 dir
[0] = sin(alpha
* M_PI
/ 180.0);
176 dir
[1] = cos(alpha
* M_PI
/ 180.0) * sin(beta
* M_PI
/ 180.0);
177 dir
[2] = cos(beta
* M_PI
/ 180.0);
179 obs
[0] += v
* dir
[0];
180 obs
[1] += v
* dir
[1];
181 obs
[2] += v
* dir
[2];
185 special(int k
, int x
, int y
)
204 key(unsigned char k
, int x
, int y
)
220 fullscreen
= (!fullscreen
);
221 XMesaSetFXmode(fullscreen
? XMESA_FX_FULLSCREEN
: XMESA_FX_WINDOW
);
226 joyactive
= (!joyactive
);
239 glDisable(GL_CULL_FACE
);
243 glEnable(GL_CULL_FACE
);
252 fprintf(stderr
, "Deleting textures...\n");
253 glDeleteTextures(1, &t1id
);
254 glDeleteTextures(1, &t2id
);
255 fprintf(stderr
, "Loading textures...\n");
257 fprintf(stderr
, "Done.\n");
263 reshape(int w
, int h
)
267 glMatrixMode(GL_PROJECTION
);
269 gluPerspective(80.0, w
/ (float) h
, 1.0, 50.0);
270 glMatrixMode(GL_MODELVIEW
);
272 glViewport(0, 0, w
, h
);
276 printstring(void *font
, char *string
)
280 len
= (int) strlen(string
);
281 for (i
= 0; i
< len
; i
++)
282 glutBitmapCharacter(font
, string
[i
]);
288 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
289 glColor4f(0.0, 0.0, 0.0, 0.5);
290 glRecti(40, 40, 600, 440);
292 glColor3f(1.0, 0.0, 0.0);
293 glRasterPos2i(300, 420);
294 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "Help");
296 glRasterPos2i(60, 390);
297 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "h - Togle Help");
298 glRasterPos2i(60, 360);
299 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "t - Togle Textures");
300 glRasterPos2i(60, 330);
301 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "f - Togle Fog");
302 glRasterPos2i(60, 300);
303 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "m - Togle strips");
304 glRasterPos2i(60, 270);
305 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "b - Togle Back face culling");
306 glRasterPos2i(60, 240);
307 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "Arrow Keys - Rotate");
308 glRasterPos2i(60, 210);
309 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "a - Increase velocity");
310 glRasterPos2i(60, 180);
311 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "z - Decrease velocity");
313 glRasterPos2i(60, 150);
315 printstring(GLUT_BITMAP_TIMES_ROMAN_24
,
316 "j - Togle jostick control (Joystick control available)");
318 printstring(GLUT_BITMAP_TIMES_ROMAN_24
,
319 "(No Joystick control available)");
326 static UINT max
[2] = { 0, 0 };
327 static UINT min
[2] = { 0xffffffff, 0xffffffff }, center
[2];
331 res
= joyGetPos(JOYSTICKID1
, &joy
);
333 if (res
== JOYERR_NOERROR
) {
336 if (max
[0] < joy
.wXpos
)
338 if (min
[0] > joy
.wXpos
)
340 center
[0] = (max
[0] + min
[0]) / 2;
342 if (max
[1] < joy
.wYpos
)
344 if (min
[1] > joy
.wYpos
)
346 center
[1] = (max
[1] + min
[1]) / 2;
349 if (fabs(center
[0] - (float) joy
.wXpos
) > 0.1 * (max
[0] - min
[0]))
351 2.0 * (center
[0] - (float) joy
.wXpos
) / (max
[0] - min
[0]);
352 if (fabs(center
[1] - (float) joy
.wYpos
) > 0.1 * (max
[1] - min
[1]))
353 beta
+= 2.0 * (center
[1] - (float) joy
.wYpos
) / (max
[1] - min
[1]);
355 if (joy
.wButtons
& JOY_BUTTON1
)
357 if (joy
.wButtons
& JOY_BUTTON2
)
369 static int count
= 0;
370 static char frbuf
[80];
372 float fr
, base
, offset
;
376 glClear(GL_COLOR_BUFFER_BIT
);
379 glEnable(GL_TEXTURE_2D
);
381 glDisable(GL_TEXTURE_2D
);
388 glShadeModel(GL_SMOOTH
);
392 gluLookAt(obs
[0], obs
[1], obs
[2],
393 obs
[0] + dir
[0], obs
[1] + dir
[1], obs
[2] + dir
[2],
398 base
= obs
[0] - fmod(obs
[0], 8.0);
402 base
= obs
[0] + (8.0 - fmod(obs
[0], 8.0));
406 glTranslatef(base
- offset
/ 2.0, 0.0, 0.0);
407 for (i
= 0; i
< NUMBLOC
; i
++) {
408 glTranslatef(offset
, 0.0, 0.0);
409 glBindTexture(GL_TEXTURE_2D
, t1id
);
410 drawobjs(striplength_skin_11
, stripdata_skin_11
);
411 glBindTexture(GL_TEXTURE_2D
, t2id
);
412 drawobjs(striplength_skin_12
, stripdata_skin_12
);
413 drawobjs(striplength_skin_9
, stripdata_skin_9
);
414 drawobjs(striplength_skin_13
, stripdata_skin_13
);
419 if ((count
% FRAME
) == 0) {
421 sprintf(frbuf
, "Frame rate: %f", FRAME
/ fr
);
424 glDisable(GL_TEXTURE_2D
);
426 glShadeModel(GL_FLAT
);
428 glMatrixMode(GL_PROJECTION
);
431 glOrtho(-0.5, 639.5, -0.5, 479.5, -1.0, 1.0);
433 glMatrixMode(GL_MODELVIEW
);
436 glColor3f(1.0, 0.0, 0.0);
437 glRasterPos2i(10, 10);
438 printstring(GLUT_BITMAP_HELVETICA_18
, frbuf
);
439 glRasterPos2i(350, 470);
440 printstring(GLUT_BITMAP_HELVETICA_10
,
441 "Tunnel V1.5 Written by David Bucciarelli (tech.hmw@plus.it)");
446 glMatrixMode(GL_PROJECTION
);
448 glMatrixMode(GL_MODELVIEW
);
456 main(int ac
, char **av
)
458 float fogcolor
[4] = { 0.7, 0.7, 0.7, 1.0 };
461 "Tunnel V1.5\nWritten by David Bucciarelli (tech.hmw@plus.it)\n");
463 glutInitWindowPosition(0, 0);
464 glutInitWindowSize(WIDTH
, HEIGHT
);
467 glutInitDisplayMode(GLUT_RGB
| GLUT_DOUBLE
);
469 if (!(win
= glutCreateWindow("Tunnel"))) {
470 fprintf(stderr
, "Error, couldn't open window\n");
474 glMatrixMode(GL_PROJECTION
);
476 gluPerspective(80.0, WIDTH
/ (float) HEIGHT
, 1.0, 50.0);
478 glMatrixMode(GL_MODELVIEW
);
480 glShadeModel(GL_SMOOTH
);
481 glDisable(GL_DEPTH_TEST
);
482 glEnable(GL_CULL_FACE
);
483 glEnable(GL_TEXTURE_2D
);
486 glFogi(GL_FOG_MODE
, GL_EXP2
);
487 glFogfv(GL_FOG_COLOR
, fogcolor
);
489 glFogf(GL_FOG_DENSITY
, 0.06);
490 glHint(GL_FOG_HINT
, GL_NICEST
);
494 glClearColor(fogcolor
[0], fogcolor
[1], fogcolor
[2], fogcolor
[3]);
495 glClear(GL_COLOR_BUFFER_BIT
);
499 glutReshapeFunc(reshape
);
500 glutDisplayFunc(draw
);
501 glutKeyboardFunc(key
);
502 glutSpecialFunc(special
);
506 /*glBlendFunc(GL_SRC_ALPHA_SATURATE,GL_ONE); */
507 /*glEnable(GL_POLYGON_SMOOTH); */