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_NEAREST
);
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 static double t0
= -1.;
164 double dt
, t
= glutGet(GLUT_ELAPSED_TIME
) / 1000.0;
170 dir
[0] = sin(alpha
* M_PI
/ 180.0);
171 dir
[1] = cos(alpha
* M_PI
/ 180.0) * sin(beta
* M_PI
/ 180.0);
172 dir
[2] = cos(beta
* M_PI
/ 180.0);
174 if (dir
[0] < 1.0e-5 && dir
[0] > -1.0e-5)
176 if (dir
[1] < 1.0e-5 && dir
[1] > -1.0e-5)
178 if (dir
[2] < 1.0e-5 && dir
[2] > -1.0e-5)
181 obs
[0] += v
* dir
[0] * dt
;
182 obs
[1] += v
* dir
[1] * dt
;
183 obs
[2] += v
* dir
[2] * dt
;
187 special(int k
, int x
, int y
)
206 key(unsigned char k
, int x
, int y
)
222 fullscreen
= (!fullscreen
);
223 XMesaSetFXmode(fullscreen
? XMESA_FX_FULLSCREEN
: XMESA_FX_WINDOW
);
227 joyactive
= (!joyactive
);
240 glDisable(GL_CULL_FACE
);
244 glEnable(GL_CULL_FACE
);
253 fprintf(stderr
, "Deleting textures...\n");
254 glDeleteTextures(1, &t1id
);
255 glDeleteTextures(1, &t2id
);
256 fprintf(stderr
, "Loading textures...\n");
258 fprintf(stderr
, "Done.\n");
262 printf("NiceFog %d\n", NiceFog
);
269 reshape(int w
, int h
)
273 glMatrixMode(GL_PROJECTION
);
275 gluPerspective(80.0, w
/ (float) h
, 1.0, 50.0);
276 glMatrixMode(GL_MODELVIEW
);
278 glViewport(0, 0, w
, h
);
282 printstring(void *font
, char *string
)
286 len
= (int) strlen(string
);
287 for (i
= 0; i
< len
; i
++)
288 glutBitmapCharacter(font
, string
[i
]);
294 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
295 glColor4f(0.0, 0.0, 0.0, 0.5);
296 glRecti(40, 40, 600, 440);
298 glColor3f(1.0, 0.0, 0.0);
299 glRasterPos2i(300, 420);
300 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "Help");
302 glRasterPos2i(60, 390);
303 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "h - Toggle Help");
304 glRasterPos2i(60, 360);
305 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "t - Toggle Textures");
306 glRasterPos2i(60, 330);
307 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "f - Toggle Fog");
308 glRasterPos2i(60, 300);
309 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "m - Toggle strips");
310 glRasterPos2i(60, 270);
311 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "b - Toggle Back face culling");
312 glRasterPos2i(60, 240);
313 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "Arrow Keys - Rotate");
314 glRasterPos2i(60, 210);
315 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "a - Increase velocity");
316 glRasterPos2i(60, 180);
317 printstring(GLUT_BITMAP_TIMES_ROMAN_24
, "z - Decrease velocity");
319 glRasterPos2i(60, 150);
321 printstring(GLUT_BITMAP_TIMES_ROMAN_24
,
322 "j - Toggle jostick control (Joystick control available)");
324 printstring(GLUT_BITMAP_TIMES_ROMAN_24
,
325 "(No Joystick control available)");
332 static UINT max
[2] = { 0, 0 };
333 static UINT min
[2] = { 0xffffffff, 0xffffffff }, center
[2];
337 res
= joyGetPos(JOYSTICKID1
, &joy
);
339 if (res
== JOYERR_NOERROR
) {
342 if (max
[0] < joy
.wXpos
)
344 if (min
[0] > joy
.wXpos
)
346 center
[0] = (max
[0] + min
[0]) / 2;
348 if (max
[1] < joy
.wYpos
)
350 if (min
[1] > joy
.wYpos
)
352 center
[1] = (max
[1] + min
[1]) / 2;
355 if (fabs(center
[0] - (float) joy
.wXpos
) > 0.1 * (max
[0] - min
[0]))
357 2.0 * (center
[0] - (float) joy
.wXpos
) / (max
[0] - min
[0]);
358 if (fabs(center
[1] - (float) joy
.wYpos
) > 0.1 * (max
[1] - min
[1]))
359 beta
+= 2.0 * (center
[1] - (float) joy
.wYpos
) / (max
[1] - min
[1]);
361 if (joy
.wButtons
& JOY_BUTTON1
)
363 if (joy
.wButtons
& JOY_BUTTON2
)
375 static char frbuf
[80] = "";
380 glHint(GL_FOG_HINT
, GL_NICEST
);
382 glHint(GL_FOG_HINT
, GL_DONT_CARE
);
386 glClear(GL_COLOR_BUFFER_BIT
);
389 glEnable(GL_TEXTURE_2D
);
391 glDisable(GL_TEXTURE_2D
);
398 glShadeModel(GL_SMOOTH
);
402 gluLookAt(obs
[0], obs
[1], obs
[2],
403 obs
[0] + dir
[0], obs
[1] + dir
[1], obs
[2] + dir
[2],
408 base
= obs
[0] - fmod(obs
[0], 8.0);
412 base
= obs
[0] + (8.0 - fmod(obs
[0], 8.0));
416 glTranslatef(base
- offset
/ 2.0, 0.0, 0.0);
417 for (i
= 0; i
< NUMBLOC
; i
++) {
418 glTranslatef(offset
, 0.0, 0.0);
419 glBindTexture(GL_TEXTURE_2D
, t1id
);
420 drawobjs(striplength_skin_11
, stripdata_skin_11
);
421 glBindTexture(GL_TEXTURE_2D
, t2id
);
422 drawobjs(striplength_skin_12
, stripdata_skin_12
);
423 drawobjs(striplength_skin_9
, stripdata_skin_9
);
424 drawobjs(striplength_skin_13
, stripdata_skin_13
);
429 glDisable(GL_TEXTURE_2D
);
431 glShadeModel(GL_FLAT
);
433 glMatrixMode(GL_PROJECTION
);
436 glOrtho(-0.5, 639.5, -0.5, 479.5, -1.0, 1.0);
438 glMatrixMode(GL_MODELVIEW
);
441 glColor3f(1.0, 0.0, 0.0);
442 glRasterPos2i(10, 10);
443 printstring(GLUT_BITMAP_HELVETICA_18
, frbuf
);
444 glRasterPos2i(350, 470);
445 printstring(GLUT_BITMAP_HELVETICA_10
,
446 "Tunnel V1.5 Written by David Bucciarelli (tech.hmw@plus.it)");
451 glMatrixMode(GL_PROJECTION
);
453 glMatrixMode(GL_MODELVIEW
);
459 GLint t
= glutGet(GLUT_ELAPSED_TIME
);
460 if (t
- T0
>= 2000) {
461 GLfloat seconds
= (t
- T0
) / 1000.0;
462 GLfloat fps
= Frames
/ seconds
;
463 sprintf(frbuf
, "Frame rate: %f", fps
);
479 main(int ac
, char **av
)
481 float fogcolor
[4] = { 0.7, 0.7, 0.7, 1.0 };
484 "Tunnel V1.5\nWritten by David Bucciarelli (tech.hmw@plus.it)\n");
486 glutInitWindowPosition(0, 0);
487 glutInitWindowSize(WIDTH
, HEIGHT
);
490 glutInitDisplayMode(GLUT_RGB
| GLUT_DOUBLE
);
492 if (!(win
= glutCreateWindow("Tunnel"))) {
493 fprintf(stderr
, "Error, couldn't open window\n");
497 glMatrixMode(GL_PROJECTION
);
499 gluPerspective(80.0, WIDTH
/ (float) HEIGHT
, 1.0, 50.0);
501 glMatrixMode(GL_MODELVIEW
);
503 glShadeModel(GL_SMOOTH
);
504 glDisable(GL_DEPTH_TEST
);
505 glEnable(GL_CULL_FACE
);
506 glEnable(GL_TEXTURE_2D
);
509 glFogi(GL_FOG_MODE
, GL_EXP2
);
510 glFogfv(GL_FOG_COLOR
, fogcolor
);
512 glFogf(GL_FOG_DENSITY
, 0.06);
513 glHint(GL_FOG_HINT
, GL_NICEST
);
517 glClearColor(fogcolor
[0], fogcolor
[1], fogcolor
[2], fogcolor
[3]);
518 glClear(GL_COLOR_BUFFER_BIT
);
522 glutReshapeFunc(reshape
);
523 glutDisplayFunc(draw
);
524 glutKeyboardFunc(key
);
525 glutSpecialFunc(special
);
529 /*glBlendFunc(GL_SRC_ALPHA_SATURATE,GL_ONE); */
530 /*glEnable(GL_POLYGON_SMOOTH); */