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;
31 static GLint Frames
= 0;
36 #define M_PI 3.1415926535
39 extern int striplength_skin_13
[];
40 extern float stripdata_skin_13
[];
42 extern int striplength_skin_12
[];
43 extern float stripdata_skin_12
[];
45 extern int striplength_skin_11
[];
46 extern float stripdata_skin_11
[];
48 extern int striplength_skin_9
[];
49 extern float stripdata_skin_9
[];
54 static float obs
[3] = { 1000.0, 0.0, 2.0 };
57 static float alpha
= 90.0;
58 static float beta
= 90.0;
61 static int bfcull
= 1;
62 static int usetex
= 1;
63 static int cstrip
= 0;
65 static int joyavailable
= 0;
66 static int joyactive
= 0;
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_LINEAR
);
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(int *l
, 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
);
207 XMesaSetFXmode(fullscreen
? XMESA_FX_FULLSCREEN
: XMESA_FX_WINDOW
);
212 joyactive
= (!joyactive
);
225 glDisable(GL_CULL_FACE
);
229 glEnable(GL_CULL_FACE
);
238 fprintf(stderr
, "Deleting textures...\n");
239 glDeleteTextures(1, &t1id
);
240 glDeleteTextures(1, &t2id
);
241 fprintf(stderr
, "Loading textures...\n");
243 fprintf(stderr
, "Done.\n");
249 reshape(int w
, int h
)
253 glMatrixMode(GL_PROJECTION
);
255 gluPerspective(80.0, w
/ (float) h
, 1.0, 50.0);
256 glMatrixMode(GL_MODELVIEW
);
258 glViewport(0, 0, w
, h
);
262 printstring(void *font
, char *string
)
266 len
= (int) strlen(string
);
267 for (i
= 0; i
< len
; i
++)
268 glutBitmapCharacter(font
, string
[i
]);
274 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
275 glColor4f(0.0, 0.0, 0.0, 0.5);
276 glRecti(40, 40, 600, 440);
278 glColor3f(1.0, 0.0, 0.0);
279 glRasterPos2i(300, 420);
280 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "Help");
282 glRasterPos2i(60, 390);
283 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "h - Togle Help");
284 glRasterPos2i(60, 360);
285 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "t - Togle Textures");
286 glRasterPos2i(60, 330);
287 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "f - Togle Fog");
288 glRasterPos2i(60, 300);
289 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "m - Togle strips");
290 glRasterPos2i(60, 270);
291 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "b - Togle Back face culling");
292 glRasterPos2i(60, 240);
293 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "Arrow Keys - Rotate");
294 glRasterPos2i(60, 210);
295 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "a - Increase velocity");
296 glRasterPos2i(60, 180);
297 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "z - Decrease velocity");
299 glRasterPos2i(60, 150);
301 printstring(GLUT_BITMAP_TIMES_ROMAN_24
,
302 "j - Togle jostick control (Joystick control available)");
304 printstring(GLUT_BITMAP_TIMES_ROMAN_24
,
305 "(No Joystick control available)");
312 static UINT max
[2] = { 0, 0 };
313 static UINT min
[2] = { 0xffffffff, 0xffffffff }, center
[2];
317 res
= joyGetPos(JOYSTICKID1
, &joy
);
319 if (res
== JOYERR_NOERROR
) {
322 if (max
[0] < joy
.wXpos
)
324 if (min
[0] > joy
.wXpos
)
326 center
[0] = (max
[0] + min
[0]) / 2;
328 if (max
[1] < joy
.wYpos
)
330 if (min
[1] > joy
.wYpos
)
332 center
[1] = (max
[1] + min
[1]) / 2;
335 if (fabs(center
[0] - (float) joy
.wXpos
) > 0.1 * (max
[0] - min
[0]))
337 2.0 * (center
[0] - (float) joy
.wXpos
) / (max
[0] - min
[0]);
338 if (fabs(center
[1] - (float) joy
.wYpos
) > 0.1 * (max
[1] - min
[1]))
339 beta
+= 2.0 * (center
[1] - (float) joy
.wYpos
) / (max
[1] - min
[1]);
341 if (joy
.wButtons
& JOY_BUTTON1
)
343 if (joy
.wButtons
& JOY_BUTTON2
)
355 static char frbuf
[80] = "";
361 glClear(GL_COLOR_BUFFER_BIT
);
364 glEnable(GL_TEXTURE_2D
);
366 glDisable(GL_TEXTURE_2D
);
373 glShadeModel(GL_SMOOTH
);
377 gluLookAt(obs
[0], obs
[1], obs
[2],
378 obs
[0] + dir
[0], obs
[1] + dir
[1], obs
[2] + dir
[2],
383 base
= obs
[0] - fmod(obs
[0], 8.0);
387 base
= obs
[0] + (8.0 - fmod(obs
[0], 8.0));
391 glTranslatef(base
- offset
/ 2.0, 0.0, 0.0);
392 for (i
= 0; i
< NUMBLOC
; i
++) {
393 glTranslatef(offset
, 0.0, 0.0);
394 glBindTexture(GL_TEXTURE_2D
, t1id
);
395 drawobjs(striplength_skin_11
, stripdata_skin_11
);
396 glBindTexture(GL_TEXTURE_2D
, t2id
);
397 drawobjs(striplength_skin_12
, stripdata_skin_12
);
398 drawobjs(striplength_skin_9
, stripdata_skin_9
);
399 drawobjs(striplength_skin_13
, stripdata_skin_13
);
404 glDisable(GL_TEXTURE_2D
);
406 glShadeModel(GL_FLAT
);
408 glMatrixMode(GL_PROJECTION
);
411 glOrtho(-0.5, 639.5, -0.5, 479.5, -1.0, 1.0);
413 glMatrixMode(GL_MODELVIEW
);
416 glColor3f(1.0, 0.0, 0.0);
417 glRasterPos2i(10, 10);
418 printstring(GLUT_BITMAP_HELVETICA_18
, frbuf
);
419 glRasterPos2i(350, 470);
420 printstring(GLUT_BITMAP_HELVETICA_10
,
421 "Tunnel V1.5 Written by David Bucciarelli (tech.hmw@plus.it)");
426 glMatrixMode(GL_PROJECTION
);
428 glMatrixMode(GL_MODELVIEW
);
434 GLint t
= glutGet(GLUT_ELAPSED_TIME
);
435 if (t
- T0
>= 2000) {
436 GLfloat seconds
= (t
- T0
) / 1000.0;
437 GLfloat fps
= Frames
/ seconds
;
438 sprintf(frbuf
, "Frame rate: %f", fps
);
446 main(int ac
, char **av
)
448 float fogcolor
[4] = { 0.7, 0.7, 0.7, 1.0 };
451 "Tunnel V1.5\nWritten by David Bucciarelli (tech.hmw@plus.it)\n");
453 glutInitWindowPosition(0, 0);
454 glutInitWindowSize(WIDTH
, HEIGHT
);
457 glutInitDisplayMode(GLUT_RGB
| GLUT_DOUBLE
);
459 if (!(win
= glutCreateWindow("Tunnel"))) {
460 fprintf(stderr
, "Error, couldn't open window\n");
464 glMatrixMode(GL_PROJECTION
);
466 gluPerspective(80.0, WIDTH
/ (float) HEIGHT
, 1.0, 50.0);
468 glMatrixMode(GL_MODELVIEW
);
470 glShadeModel(GL_SMOOTH
);
471 glDisable(GL_DEPTH_TEST
);
472 glEnable(GL_CULL_FACE
);
473 glEnable(GL_TEXTURE_2D
);
476 glFogi(GL_FOG_MODE
, GL_EXP2
);
477 glFogfv(GL_FOG_COLOR
, fogcolor
);
479 glFogf(GL_FOG_DENSITY
, 0.06);
480 glHint(GL_FOG_HINT
, GL_NICEST
);
484 glClearColor(fogcolor
[0], fogcolor
[1], fogcolor
[2], fogcolor
[3]);
485 glClear(GL_COLOR_BUFFER_BIT
);
489 glutReshapeFunc(reshape
);
490 glutDisplayFunc(draw
);
491 glutKeyboardFunc(key
);
492 glutSpecialFunc(special
);
496 /*glBlendFunc(GL_SRC_ALPHA_SATURATE,GL_ONE); */
497 /*glEnable(GL_POLYGON_SMOOTH); */