2 * This program is under the GNU GPL.
3 * Use at your own risk.
5 * written by David Bucciarelli (tech.hmw@plus.it)
20 #include "tunneldat.h"
24 static int fullscreen
= 1;
27 static int WIDTH
= 640;
28 static int HEIGHT
= 480;
31 static GLint Frames
= 0;
32 static GLint NiceFog
= 1;
37 #define M_PI 3.1415926535
41 extern int striplength_skin_13[];
42 extern float stripdata_skin_13[];
44 extern int striplength_skin_12[];
45 extern float stripdata_skin_12[];
47 extern int striplength_skin_11[];
48 extern float stripdata_skin_11[];
50 extern int striplength_skin_9[];
51 extern float stripdata_skin_9[];
56 static float obs
[3] = { 1000.0, 0.0, 2.0 };
59 static float alpha
= 90.0;
60 static float beta
= 90.0;
63 static int bfcull
= 1;
64 static int usetex
= 1;
65 static int cstrip
= 0;
67 static int joyavailable
= 0;
68 static int joyactive
= 0;
70 static GLuint t1id
, t2id
;
75 glGenTextures(1, &t1id
);
76 glBindTexture(GL_TEXTURE_2D
, t1id
);
78 if (!LoadRGBMipmaps("../images/tile.rgb", GL_RGB
)) {
79 fprintf(stderr
, "Error reading a texture.\n");
83 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
84 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
86 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
,
87 GL_LINEAR_MIPMAP_LINEAR
);
88 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
90 glGenTextures(1, &t2id
);
91 glBindTexture(GL_TEXTURE_2D
, t2id
);
93 if (!LoadRGBMipmaps("../images/bw.rgb", GL_RGB
)) {
94 fprintf(stderr
, "Error reading a texture.\n");
98 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
99 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
101 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
,
102 GL_LINEAR_MIPMAP_LINEAR
);
103 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
105 glTexEnvf(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_MODULATE
);
109 drawobjs(const int *l
, const float *f
)
114 float r
= 0.33, g
= 0.33, b
= 0.33;
132 glBegin(GL_TRIANGLE_STRIP
);
133 for (j
= 0; j
< mend
; j
++) {
147 glBegin(GL_TRIANGLE_STRIP
);
148 for (j
= 0; j
< mend
; j
++) {
163 dir
[0] = sin(alpha
* M_PI
/ 180.0);
164 dir
[1] = cos(alpha
* M_PI
/ 180.0) * sin(beta
* M_PI
/ 180.0);
165 dir
[2] = cos(beta
* M_PI
/ 180.0);
167 if (dir
[0] < 1.0e-5 && dir
[0] > -1.0e-5)
169 if (dir
[1] < 1.0e-5 && dir
[1] > -1.0e-5)
171 if (dir
[2] < 1.0e-5 && dir
[2] > -1.0e-5)
174 obs
[0] += v
* dir
[0];
175 obs
[1] += v
* dir
[1];
176 obs
[2] += v
* dir
[2];
180 special(int k
, int x
, int y
)
199 key(unsigned char k
, int x
, int y
)
215 fullscreen
= (!fullscreen
);
216 XMesaSetFXmode(fullscreen
? XMESA_FX_FULLSCREEN
: XMESA_FX_WINDOW
);
220 joyactive
= (!joyactive
);
233 glDisable(GL_CULL_FACE
);
237 glEnable(GL_CULL_FACE
);
246 fprintf(stderr
, "Deleting textures...\n");
247 glDeleteTextures(1, &t1id
);
248 glDeleteTextures(1, &t2id
);
249 fprintf(stderr
, "Loading textures...\n");
251 fprintf(stderr
, "Done.\n");
255 printf("NiceFog %d\n", NiceFog
);
262 reshape(int w
, int h
)
266 glMatrixMode(GL_PROJECTION
);
268 gluPerspective(80.0, w
/ (float) h
, 1.0, 50.0);
269 glMatrixMode(GL_MODELVIEW
);
271 glViewport(0, 0, w
, h
);
275 printstring(void *font
, char *string
)
279 len
= (int) strlen(string
);
280 for (i
= 0; i
< len
; i
++)
281 glutBitmapCharacter(font
, string
[i
]);
287 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
288 glColor4f(0.0, 0.0, 0.0, 0.5);
289 glRecti(40, 40, 600, 440);
291 glColor3f(1.0, 0.0, 0.0);
292 glRasterPos2i(300, 420);
293 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "Help");
295 glRasterPos2i(60, 390);
296 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "h - Togle Help");
297 glRasterPos2i(60, 360);
298 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "t - Togle Textures");
299 glRasterPos2i(60, 330);
300 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "f - Togle Fog");
301 glRasterPos2i(60, 300);
302 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "m - Togle strips");
303 glRasterPos2i(60, 270);
304 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "b - Togle Back face culling");
305 glRasterPos2i(60, 240);
306 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "Arrow Keys - Rotate");
307 glRasterPos2i(60, 210);
308 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "a - Increase velocity");
309 glRasterPos2i(60, 180);
310 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "z - Decrease velocity");
312 glRasterPos2i(60, 150);
314 printstring(GLUT_BITMAP_TIMES_ROMAN_24
,
315 "j - Togle jostick control (Joystick control available)");
317 printstring(GLUT_BITMAP_TIMES_ROMAN_24
,
318 "(No Joystick control available)");
325 static UINT max
[2] = { 0, 0 };
326 static UINT min
[2] = { 0xffffffff, 0xffffffff }, center
[2];
330 res
= joyGetPos(JOYSTICKID1
, &joy
);
332 if (res
== JOYERR_NOERROR
) {
335 if (max
[0] < joy
.wXpos
)
337 if (min
[0] > joy
.wXpos
)
339 center
[0] = (max
[0] + min
[0]) / 2;
341 if (max
[1] < joy
.wYpos
)
343 if (min
[1] > joy
.wYpos
)
345 center
[1] = (max
[1] + min
[1]) / 2;
348 if (fabs(center
[0] - (float) joy
.wXpos
) > 0.1 * (max
[0] - min
[0]))
350 2.0 * (center
[0] - (float) joy
.wXpos
) / (max
[0] - min
[0]);
351 if (fabs(center
[1] - (float) joy
.wYpos
) > 0.1 * (max
[1] - min
[1]))
352 beta
+= 2.0 * (center
[1] - (float) joy
.wYpos
) / (max
[1] - min
[1]);
354 if (joy
.wButtons
& JOY_BUTTON1
)
356 if (joy
.wButtons
& JOY_BUTTON2
)
368 static char frbuf
[80] = "";
373 glHint(GL_FOG_HINT
, GL_NICEST
);
375 glHint(GL_FOG_HINT
, GL_DONT_CARE
);
379 glClear(GL_COLOR_BUFFER_BIT
);
382 glEnable(GL_TEXTURE_2D
);
384 glDisable(GL_TEXTURE_2D
);
391 glShadeModel(GL_SMOOTH
);
395 gluLookAt(obs
[0], obs
[1], obs
[2],
396 obs
[0] + dir
[0], obs
[1] + dir
[1], obs
[2] + dir
[2],
401 base
= obs
[0] - fmod(obs
[0], 8.0);
405 base
= obs
[0] + (8.0 - fmod(obs
[0], 8.0));
409 glTranslatef(base
- offset
/ 2.0, 0.0, 0.0);
410 for (i
= 0; i
< NUMBLOC
; i
++) {
411 glTranslatef(offset
, 0.0, 0.0);
412 glBindTexture(GL_TEXTURE_2D
, t1id
);
413 drawobjs(striplength_skin_11
, stripdata_skin_11
);
414 glBindTexture(GL_TEXTURE_2D
, t2id
);
415 drawobjs(striplength_skin_12
, stripdata_skin_12
);
416 drawobjs(striplength_skin_9
, stripdata_skin_9
);
417 drawobjs(striplength_skin_13
, stripdata_skin_13
);
422 glDisable(GL_TEXTURE_2D
);
424 glShadeModel(GL_FLAT
);
426 glMatrixMode(GL_PROJECTION
);
429 glOrtho(-0.5, 639.5, -0.5, 479.5, -1.0, 1.0);
431 glMatrixMode(GL_MODELVIEW
);
434 glColor3f(1.0, 0.0, 0.0);
435 glRasterPos2i(10, 10);
436 printstring(GLUT_BITMAP_HELVETICA_18
, frbuf
);
437 glRasterPos2i(350, 470);
438 printstring(GLUT_BITMAP_HELVETICA_10
,
439 "Tunnel V1.5 Written by David Bucciarelli (tech.hmw@plus.it)");
444 glMatrixMode(GL_PROJECTION
);
446 glMatrixMode(GL_MODELVIEW
);
452 GLint t
= glutGet(GLUT_ELAPSED_TIME
);
453 if (t
- T0
>= 2000) {
454 GLfloat seconds
= (t
- T0
) / 1000.0;
455 GLfloat fps
= Frames
/ seconds
;
456 sprintf(frbuf
, "Frame rate: %f", fps
);
472 main(int ac
, char **av
)
474 float fogcolor
[4] = { 0.7, 0.7, 0.7, 1.0 };
477 "Tunnel V1.5\nWritten by David Bucciarelli (tech.hmw@plus.it)\n");
479 glutInitWindowPosition(0, 0);
480 glutInitWindowSize(WIDTH
, HEIGHT
);
483 glutInitDisplayMode(GLUT_RGB
| GLUT_DOUBLE
);
485 if (!(win
= glutCreateWindow("Tunnel"))) {
486 fprintf(stderr
, "Error, couldn't open window\n");
490 glMatrixMode(GL_PROJECTION
);
492 gluPerspective(80.0, WIDTH
/ (float) HEIGHT
, 1.0, 50.0);
494 glMatrixMode(GL_MODELVIEW
);
496 glShadeModel(GL_SMOOTH
);
497 glDisable(GL_DEPTH_TEST
);
498 glEnable(GL_CULL_FACE
);
499 glEnable(GL_TEXTURE_2D
);
502 glFogi(GL_FOG_MODE
, GL_EXP2
);
503 glFogfv(GL_FOG_COLOR
, fogcolor
);
505 glFogf(GL_FOG_DENSITY
, 0.06);
506 glHint(GL_FOG_HINT
, GL_NICEST
);
510 glClearColor(fogcolor
[0], fogcolor
[1], fogcolor
[2], fogcolor
[3]);
511 glClear(GL_COLOR_BUFFER_BIT
);
515 glutReshapeFunc(reshape
);
516 glutDisplayFunc(draw
);
517 glutKeyboardFunc(key
);
518 glutSpecialFunc(special
);
522 /*glBlendFunc(GL_SRC_ALPHA_SATURATE,GL_ONE); */
523 /*glEnable(GL_POLYGON_SMOOTH); */