tunnel.c revision 32001f49
132001f49Smrg/* 232001f49Smrg * This program is under the GNU GPL. 332001f49Smrg * Use at your own risk. 432001f49Smrg * 532001f49Smrg * written by David Bucciarelli (tech.hmw@plus.it) 632001f49Smrg * Humanware s.r.l. 732001f49Smrg */ 832001f49Smrg 932001f49Smrg#include <stdio.h> 1032001f49Smrg#include <stdlib.h> 1132001f49Smrg#include <math.h> 1232001f49Smrg#include <string.h> 1332001f49Smrg 1432001f49Smrg#ifdef WIN32 1532001f49Smrg#include <windows.h> 1632001f49Smrg#endif 1732001f49Smrg 1832001f49Smrg#include "glut_wrap.h" 1932001f49Smrg#include "readtex.h" 2032001f49Smrg#include "tunneldat.h" 2132001f49Smrg 2232001f49Smrg#ifdef XMESA 2332001f49Smrg#include "GL/xmesa.h" 2432001f49Smrgstatic int fullscreen = 1; 2532001f49Smrg#endif 2632001f49Smrg 2732001f49Smrgstatic int WIDTH = 640; 2832001f49Smrgstatic int HEIGHT = 480; 2932001f49Smrg 3032001f49Smrgstatic GLint T0 = 0; 3132001f49Smrgstatic GLint Frames = 0; 3232001f49Smrgstatic GLint NiceFog = 1; 3332001f49Smrg 3432001f49Smrg#define NUMBLOC 5 3532001f49Smrg 3632001f49Smrg#ifndef M_PI 3732001f49Smrg#define M_PI 3.1415926535 3832001f49Smrg#endif 3932001f49Smrg 4032001f49Smrg/* 4132001f49Smrgextern int striplength_skin_13[]; 4232001f49Smrgextern float stripdata_skin_13[]; 4332001f49Smrg 4432001f49Smrgextern int striplength_skin_12[]; 4532001f49Smrgextern float stripdata_skin_12[]; 4632001f49Smrg 4732001f49Smrgextern int striplength_skin_11[]; 4832001f49Smrgextern float stripdata_skin_11[]; 4932001f49Smrg 5032001f49Smrgextern int striplength_skin_9[]; 5132001f49Smrgextern float stripdata_skin_9[]; 5232001f49Smrg*/ 5332001f49Smrg 5432001f49Smrgstatic int win = 0; 5532001f49Smrg 5632001f49Smrgstatic float obs[3] = { 1000.0, 0.0, 2.0 }; 5732001f49Smrgstatic float dir[3]; 5832001f49Smrgstatic float v = 30.; 5932001f49Smrgstatic float alpha = 90.0; 6032001f49Smrgstatic float beta = 90.0; 6132001f49Smrg 6232001f49Smrgstatic int fog = 1; 6332001f49Smrgstatic int bfcull = 1; 6432001f49Smrgstatic int usetex = 1; 6532001f49Smrgstatic int cstrip = 0; 6632001f49Smrgstatic int help = 1; 6732001f49Smrgstatic int joyavailable = 0; 6832001f49Smrgstatic int joyactive = 0; 6932001f49Smrg 7032001f49Smrgstatic GLuint t1id, t2id; 7132001f49Smrg 7232001f49Smrgstatic void 7332001f49Smrginittextures(void) 7432001f49Smrg{ 7532001f49Smrg glGenTextures(1, &t1id); 7632001f49Smrg glBindTexture(GL_TEXTURE_2D, t1id); 7732001f49Smrg 7832001f49Smrg if (!LoadRGBMipmaps(DEMOS_DATA_DIR "tile.rgb", GL_RGB)) { 7932001f49Smrg fprintf(stderr, "Error reading a texture.\n"); 8032001f49Smrg exit(-1); 8132001f49Smrg } 8232001f49Smrg 8332001f49Smrg glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 8432001f49Smrg glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 8532001f49Smrg 8632001f49Smrg glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, 8732001f49Smrg GL_LINEAR_MIPMAP_NEAREST); 8832001f49Smrg glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 8932001f49Smrg 9032001f49Smrg glGenTextures(1, &t2id); 9132001f49Smrg glBindTexture(GL_TEXTURE_2D, t2id); 9232001f49Smrg 9332001f49Smrg if (!LoadRGBMipmaps(DEMOS_DATA_DIR "bw.rgb", GL_RGB)) { 9432001f49Smrg fprintf(stderr, "Error reading a texture.\n"); 9532001f49Smrg exit(-1); 9632001f49Smrg } 9732001f49Smrg 9832001f49Smrg glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 9932001f49Smrg glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 10032001f49Smrg 10132001f49Smrg glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, 10232001f49Smrg GL_LINEAR_MIPMAP_LINEAR); 10332001f49Smrg glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 10432001f49Smrg 10532001f49Smrg glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 10632001f49Smrg} 10732001f49Smrg 10832001f49Smrgstatic void 10932001f49Smrgdrawobjs(const int *l, const float *f) 11032001f49Smrg{ 11132001f49Smrg int mend, j; 11232001f49Smrg 11332001f49Smrg if (cstrip) { 11432001f49Smrg float r = 0.33, g = 0.33, b = 0.33; 11532001f49Smrg 11632001f49Smrg for (; (*l) != 0;) { 11732001f49Smrg mend = *l++; 11832001f49Smrg 11932001f49Smrg r += 0.33; 12032001f49Smrg if (r > 1.0) { 12132001f49Smrg r = 0.33; 12232001f49Smrg g += 0.33; 12332001f49Smrg if (g > 1.0) { 12432001f49Smrg g = 0.33; 12532001f49Smrg b += 0.33; 12632001f49Smrg if (b > 1.0) 12732001f49Smrg b = 0.33; 12832001f49Smrg } 12932001f49Smrg } 13032001f49Smrg 13132001f49Smrg glColor3f(r, g, b); 13232001f49Smrg glBegin(GL_TRIANGLE_STRIP); 13332001f49Smrg for (j = 0; j < mend; j++) { 13432001f49Smrg f += 4; 13532001f49Smrg glTexCoord2fv(f); 13632001f49Smrg f += 2; 13732001f49Smrg glVertex3fv(f); 13832001f49Smrg f += 3; 13932001f49Smrg } 14032001f49Smrg glEnd(); 14132001f49Smrg } 14232001f49Smrg } 14332001f49Smrg else 14432001f49Smrg for (; (*l) != 0;) { 14532001f49Smrg mend = *l++; 14632001f49Smrg 14732001f49Smrg glBegin(GL_TRIANGLE_STRIP); 14832001f49Smrg for (j = 0; j < mend; j++) { 14932001f49Smrg glColor4fv(f); 15032001f49Smrg f += 4; 15132001f49Smrg glTexCoord2fv(f); 15232001f49Smrg f += 2; 15332001f49Smrg glVertex3fv(f); 15432001f49Smrg f += 3; 15532001f49Smrg } 15632001f49Smrg glEnd(); 15732001f49Smrg } 15832001f49Smrg} 15932001f49Smrg 16032001f49Smrgstatic void 16132001f49Smrgcalcposobs(void) 16232001f49Smrg{ 16332001f49Smrg static double t0 = -1.; 16432001f49Smrg double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; 16532001f49Smrg if (t0 < 0.0) 16632001f49Smrg t0 = t; 16732001f49Smrg dt = t - t0; 16832001f49Smrg t0 = t; 16932001f49Smrg 17032001f49Smrg dir[0] = sin(alpha * M_PI / 180.0); 17132001f49Smrg dir[1] = cos(alpha * M_PI / 180.0) * sin(beta * M_PI / 180.0); 17232001f49Smrg dir[2] = cos(beta * M_PI / 180.0); 17332001f49Smrg 17432001f49Smrg if (dir[0] < 1.0e-5 && dir[0] > -1.0e-5) 17532001f49Smrg dir[0] = 0; 17632001f49Smrg if (dir[1] < 1.0e-5 && dir[1] > -1.0e-5) 17732001f49Smrg dir[1] = 0; 17832001f49Smrg if (dir[2] < 1.0e-5 && dir[2] > -1.0e-5) 17932001f49Smrg dir[2] = 0; 18032001f49Smrg 18132001f49Smrg obs[0] += v * dir[0] * dt; 18232001f49Smrg obs[1] += v * dir[1] * dt; 18332001f49Smrg obs[2] += v * dir[2] * dt; 18432001f49Smrg} 18532001f49Smrg 18632001f49Smrgstatic void 18732001f49Smrgspecial(int k, int x, int y) 18832001f49Smrg{ 18932001f49Smrg switch (k) { 19032001f49Smrg case GLUT_KEY_LEFT: 19132001f49Smrg alpha -= 2.0; 19232001f49Smrg break; 19332001f49Smrg case GLUT_KEY_RIGHT: 19432001f49Smrg alpha += 2.0; 19532001f49Smrg break; 19632001f49Smrg case GLUT_KEY_DOWN: 19732001f49Smrg beta -= 2.0; 19832001f49Smrg break; 19932001f49Smrg case GLUT_KEY_UP: 20032001f49Smrg beta += 2.0; 20132001f49Smrg break; 20232001f49Smrg } 20332001f49Smrg} 20432001f49Smrg 20532001f49Smrgstatic void 20632001f49Smrgcleanup(void) 20732001f49Smrg{ 20832001f49Smrg glDeleteTextures(1, &t1id); 20932001f49Smrg glDeleteTextures(1, &t2id); 21032001f49Smrg} 21132001f49Smrg 21232001f49Smrgstatic void 21332001f49Smrgkey(unsigned char k, int x, int y) 21432001f49Smrg{ 21532001f49Smrg switch (k) { 21632001f49Smrg case 27: 21732001f49Smrg cleanup(); 21832001f49Smrg exit(0); 21932001f49Smrg break; 22032001f49Smrg 22132001f49Smrg case 'a': 22232001f49Smrg v += 5.; 22332001f49Smrg break; 22432001f49Smrg case 'z': 22532001f49Smrg v -= 5.; 22632001f49Smrg break; 22732001f49Smrg 22832001f49Smrg#ifdef XMESA 22932001f49Smrg case ' ': 23032001f49Smrg fullscreen = (!fullscreen); 23132001f49Smrg XMesaSetFXmode(fullscreen ? XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW); 23232001f49Smrg break; 23332001f49Smrg#endif 23432001f49Smrg case 'j': 23532001f49Smrg joyactive = (!joyactive); 23632001f49Smrg break; 23732001f49Smrg case 'h': 23832001f49Smrg help = (!help); 23932001f49Smrg break; 24032001f49Smrg case 'f': 24132001f49Smrg fog = (!fog); 24232001f49Smrg break; 24332001f49Smrg case 't': 24432001f49Smrg usetex = (!usetex); 24532001f49Smrg break; 24632001f49Smrg case 'b': 24732001f49Smrg if (bfcull) { 24832001f49Smrg glDisable(GL_CULL_FACE); 24932001f49Smrg bfcull = 0; 25032001f49Smrg } 25132001f49Smrg else { 25232001f49Smrg glEnable(GL_CULL_FACE); 25332001f49Smrg bfcull = 1; 25432001f49Smrg } 25532001f49Smrg break; 25632001f49Smrg case 'm': 25732001f49Smrg cstrip = (!cstrip); 25832001f49Smrg break; 25932001f49Smrg 26032001f49Smrg case 'd': 26132001f49Smrg fprintf(stderr, "Deleting textures...\n"); 26232001f49Smrg glDeleteTextures(1, &t1id); 26332001f49Smrg glDeleteTextures(1, &t2id); 26432001f49Smrg fprintf(stderr, "Loading textures...\n"); 26532001f49Smrg inittextures(); 26632001f49Smrg fprintf(stderr, "Done.\n"); 26732001f49Smrg break; 26832001f49Smrg case 'n': 26932001f49Smrg NiceFog = !NiceFog; 27032001f49Smrg printf("NiceFog %d\n", NiceFog); 27132001f49Smrg break; 27232001f49Smrg } 27332001f49Smrg glutPostRedisplay(); 27432001f49Smrg} 27532001f49Smrg 27632001f49Smrgstatic void 27732001f49Smrgreshape(int w, int h) 27832001f49Smrg{ 27932001f49Smrg WIDTH = w; 28032001f49Smrg HEIGHT = h; 28132001f49Smrg glMatrixMode(GL_PROJECTION); 28232001f49Smrg glLoadIdentity(); 28332001f49Smrg gluPerspective(80.0, w / (float) h, 1.0, 50.0); 28432001f49Smrg glMatrixMode(GL_MODELVIEW); 28532001f49Smrg glLoadIdentity(); 28632001f49Smrg glViewport(0, 0, w, h); 28732001f49Smrg} 28832001f49Smrg 28932001f49Smrgstatic void 29032001f49Smrgprintstring(void *font, char *string) 29132001f49Smrg{ 29232001f49Smrg int len, i; 29332001f49Smrg 29432001f49Smrg len = (int) strlen(string); 29532001f49Smrg for (i = 0; i < len; i++) 29632001f49Smrg glutBitmapCharacter(font, string[i]); 29732001f49Smrg} 29832001f49Smrg 29932001f49Smrgstatic void 30032001f49Smrgprinthelp(void) 30132001f49Smrg{ 30232001f49Smrg glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 30332001f49Smrg glColor4f(0.0, 0.0, 0.0, 0.5); 30432001f49Smrg glRecti(40, 40, 600, 440); 30532001f49Smrg 30632001f49Smrg glColor3f(1.0, 0.0, 0.0); 30732001f49Smrg glRasterPos2i(300, 420); 30832001f49Smrg printstring(GLUT_BITMAP_TIMES_ROMAN_24, "Help"); 30932001f49Smrg 31032001f49Smrg glRasterPos2i(60, 390); 31132001f49Smrg printstring(GLUT_BITMAP_TIMES_ROMAN_24, "h - Toggle Help"); 31232001f49Smrg glRasterPos2i(60, 360); 31332001f49Smrg printstring(GLUT_BITMAP_TIMES_ROMAN_24, "t - Toggle Textures"); 31432001f49Smrg glRasterPos2i(60, 330); 31532001f49Smrg printstring(GLUT_BITMAP_TIMES_ROMAN_24, "f - Toggle Fog"); 31632001f49Smrg glRasterPos2i(60, 300); 31732001f49Smrg printstring(GLUT_BITMAP_TIMES_ROMAN_24, "m - Toggle strips"); 31832001f49Smrg glRasterPos2i(60, 270); 31932001f49Smrg printstring(GLUT_BITMAP_TIMES_ROMAN_24, "b - Toggle Back face culling"); 32032001f49Smrg glRasterPos2i(60, 240); 32132001f49Smrg printstring(GLUT_BITMAP_TIMES_ROMAN_24, "Arrow Keys - Rotate"); 32232001f49Smrg glRasterPos2i(60, 210); 32332001f49Smrg printstring(GLUT_BITMAP_TIMES_ROMAN_24, "a - Increase velocity"); 32432001f49Smrg glRasterPos2i(60, 180); 32532001f49Smrg printstring(GLUT_BITMAP_TIMES_ROMAN_24, "z - Decrease velocity"); 32632001f49Smrg 32732001f49Smrg glRasterPos2i(60, 150); 32832001f49Smrg if (joyavailable) 32932001f49Smrg printstring(GLUT_BITMAP_TIMES_ROMAN_24, 33032001f49Smrg "j - Toggle jostick control (Joystick control available)"); 33132001f49Smrg else 33232001f49Smrg printstring(GLUT_BITMAP_TIMES_ROMAN_24, 33332001f49Smrg "(No Joystick control available)"); 33432001f49Smrg} 33532001f49Smrg 33632001f49Smrgstatic void 33732001f49Smrgdojoy(void) 33832001f49Smrg{ 33932001f49Smrg#ifdef WIN32 34032001f49Smrg static UINT max[2] = { 0, 0 }; 34132001f49Smrg static UINT min[2] = { 0xffffffff, 0xffffffff }, center[2]; 34232001f49Smrg MMRESULT res; 34332001f49Smrg JOYINFO joy; 34432001f49Smrg 34532001f49Smrg res = joyGetPos(JOYSTICKID1, &joy); 34632001f49Smrg 34732001f49Smrg if (res == JOYERR_NOERROR) { 34832001f49Smrg joyavailable = 1; 34932001f49Smrg 35032001f49Smrg if (max[0] < joy.wXpos) 35132001f49Smrg max[0] = joy.wXpos; 35232001f49Smrg if (min[0] > joy.wXpos) 35332001f49Smrg min[0] = joy.wXpos; 35432001f49Smrg center[0] = (max[0] + min[0]) / 2; 35532001f49Smrg 35632001f49Smrg if (max[1] < joy.wYpos) 35732001f49Smrg max[1] = joy.wYpos; 35832001f49Smrg if (min[1] > joy.wYpos) 35932001f49Smrg min[1] = joy.wYpos; 36032001f49Smrg center[1] = (max[1] + min[1]) / 2; 36132001f49Smrg 36232001f49Smrg if (joyactive) { 36332001f49Smrg if (fabs(center[0] - (float) joy.wXpos) > 0.1 * (max[0] - min[0])) 36432001f49Smrg alpha -= 36532001f49Smrg 2.0 * (center[0] - (float) joy.wXpos) / (max[0] - min[0]); 36632001f49Smrg if (fabs(center[1] - (float) joy.wYpos) > 0.1 * (max[1] - min[1])) 36732001f49Smrg beta += 2.0 * (center[1] - (float) joy.wYpos) / (max[1] - min[1]); 36832001f49Smrg 36932001f49Smrg if (joy.wButtons & JOY_BUTTON1) 37032001f49Smrg v += 0.01; 37132001f49Smrg if (joy.wButtons & JOY_BUTTON2) 37232001f49Smrg v -= 0.01; 37332001f49Smrg } 37432001f49Smrg } 37532001f49Smrg else 37632001f49Smrg joyavailable = 0; 37732001f49Smrg#endif 37832001f49Smrg} 37932001f49Smrg 38032001f49Smrgstatic void 38132001f49Smrgdraw(void) 38232001f49Smrg{ 38332001f49Smrg static char frbuf[80] = ""; 38432001f49Smrg int i; 38532001f49Smrg float base, offset; 38632001f49Smrg 38732001f49Smrg if (NiceFog) 38832001f49Smrg glHint(GL_FOG_HINT, GL_NICEST); 38932001f49Smrg else 39032001f49Smrg glHint(GL_FOG_HINT, GL_DONT_CARE); 39132001f49Smrg 39232001f49Smrg dojoy(); 39332001f49Smrg 39432001f49Smrg glClear(GL_COLOR_BUFFER_BIT); 39532001f49Smrg 39632001f49Smrg if (usetex) 39732001f49Smrg glEnable(GL_TEXTURE_2D); 39832001f49Smrg else 39932001f49Smrg glDisable(GL_TEXTURE_2D); 40032001f49Smrg 40132001f49Smrg if (fog) 40232001f49Smrg glEnable(GL_FOG); 40332001f49Smrg else 40432001f49Smrg glDisable(GL_FOG); 40532001f49Smrg 40632001f49Smrg glShadeModel(GL_SMOOTH); 40732001f49Smrg 40832001f49Smrg glPushMatrix(); 40932001f49Smrg calcposobs(); 41032001f49Smrg gluLookAt(obs[0], obs[1], obs[2], 41132001f49Smrg obs[0] + dir[0], obs[1] + dir[1], obs[2] + dir[2], 41232001f49Smrg 0.0, 0.0, 1.0); 41332001f49Smrg 41432001f49Smrg if (dir[0] > 0) { 41532001f49Smrg offset = 8.0; 41632001f49Smrg base = obs[0] - fmod(obs[0], 8.0); 41732001f49Smrg } 41832001f49Smrg else { 41932001f49Smrg offset = -8.0; 42032001f49Smrg base = obs[0] + (8.0 - fmod(obs[0], 8.0)); 42132001f49Smrg } 42232001f49Smrg 42332001f49Smrg glPushMatrix(); 42432001f49Smrg glTranslatef(base - offset / 2.0, 0.0, 0.0); 42532001f49Smrg for (i = 0; i < NUMBLOC; i++) { 42632001f49Smrg glTranslatef(offset, 0.0, 0.0); 42732001f49Smrg glBindTexture(GL_TEXTURE_2D, t1id); 42832001f49Smrg drawobjs(striplength_skin_11, stripdata_skin_11); 42932001f49Smrg glBindTexture(GL_TEXTURE_2D, t2id); 43032001f49Smrg drawobjs(striplength_skin_12, stripdata_skin_12); 43132001f49Smrg drawobjs(striplength_skin_9, stripdata_skin_9); 43232001f49Smrg drawobjs(striplength_skin_13, stripdata_skin_13); 43332001f49Smrg } 43432001f49Smrg glPopMatrix(); 43532001f49Smrg glPopMatrix(); 43632001f49Smrg 43732001f49Smrg glDisable(GL_TEXTURE_2D); 43832001f49Smrg glDisable(GL_FOG); 43932001f49Smrg glShadeModel(GL_FLAT); 44032001f49Smrg 44132001f49Smrg glMatrixMode(GL_PROJECTION); 44232001f49Smrg glPushMatrix(); 44332001f49Smrg glLoadIdentity(); 44432001f49Smrg glOrtho(-0.5, 639.5, -0.5, 479.5, -1.0, 1.0); 44532001f49Smrg 44632001f49Smrg glMatrixMode(GL_MODELVIEW); 44732001f49Smrg glLoadIdentity(); 44832001f49Smrg 44932001f49Smrg glColor3f(1.0, 0.0, 0.0); 45032001f49Smrg glRasterPos2i(10, 10); 45132001f49Smrg printstring(GLUT_BITMAP_HELVETICA_18, frbuf); 45232001f49Smrg glRasterPos2i(350, 470); 45332001f49Smrg printstring(GLUT_BITMAP_HELVETICA_10, 45432001f49Smrg "Tunnel V1.5 Written by David Bucciarelli (tech.hmw@plus.it)"); 45532001f49Smrg 45632001f49Smrg if (help) 45732001f49Smrg printhelp(); 45832001f49Smrg 45932001f49Smrg glMatrixMode(GL_PROJECTION); 46032001f49Smrg glPopMatrix(); 46132001f49Smrg glMatrixMode(GL_MODELVIEW); 46232001f49Smrg 46332001f49Smrg glutSwapBuffers(); 46432001f49Smrg 46532001f49Smrg Frames++; 46632001f49Smrg { 46732001f49Smrg GLint t = glutGet(GLUT_ELAPSED_TIME); 46832001f49Smrg if (t - T0 >= 2000) { 46932001f49Smrg GLfloat seconds = (t - T0) / 1000.0; 47032001f49Smrg GLfloat fps = Frames / seconds; 47132001f49Smrg sprintf(frbuf, "Frame rate: %f", fps); 47232001f49Smrg printf("%s\n", frbuf); 47332001f49Smrg T0 = t; 47432001f49Smrg Frames = 0; 47532001f49Smrg } 47632001f49Smrg } 47732001f49Smrg} 47832001f49Smrg 47932001f49Smrgstatic void 48032001f49Smrgidle(void) 48132001f49Smrg{ 48232001f49Smrg glutPostRedisplay(); 48332001f49Smrg} 48432001f49Smrg 48532001f49Smrg 48632001f49Smrg 48732001f49Smrgint 48832001f49Smrgmain(int ac, char **av) 48932001f49Smrg{ 49032001f49Smrg float fogcolor[4] = { 0.7, 0.7, 0.7, 1.0 }; 49132001f49Smrg 49232001f49Smrg fprintf(stderr, 49332001f49Smrg "Tunnel V1.5\nWritten by David Bucciarelli (tech.hmw@plus.it)\n"); 49432001f49Smrg 49532001f49Smrg glutInitWindowSize(WIDTH, HEIGHT); 49632001f49Smrg glutInit(&ac, av); 49732001f49Smrg 49832001f49Smrg glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); 49932001f49Smrg 50032001f49Smrg if (!(win = glutCreateWindow("Tunnel"))) { 50132001f49Smrg fprintf(stderr, "Error, couldn't open window\n"); 50232001f49Smrg return -1; 50332001f49Smrg } 50432001f49Smrg 50532001f49Smrg glMatrixMode(GL_PROJECTION); 50632001f49Smrg glLoadIdentity(); 50732001f49Smrg gluPerspective(80.0, WIDTH / (float) HEIGHT, 1.0, 50.0); 50832001f49Smrg 50932001f49Smrg glMatrixMode(GL_MODELVIEW); 51032001f49Smrg 51132001f49Smrg glShadeModel(GL_SMOOTH); 51232001f49Smrg glDisable(GL_DEPTH_TEST); 51332001f49Smrg glEnable(GL_CULL_FACE); 51432001f49Smrg glEnable(GL_TEXTURE_2D); 51532001f49Smrg 51632001f49Smrg glEnable(GL_FOG); 51732001f49Smrg glFogi(GL_FOG_MODE, GL_EXP2); 51832001f49Smrg glFogfv(GL_FOG_COLOR, fogcolor); 51932001f49Smrg 52032001f49Smrg glFogf(GL_FOG_DENSITY, 0.06); 52132001f49Smrg glHint(GL_FOG_HINT, GL_NICEST); 52232001f49Smrg 52332001f49Smrg inittextures(); 52432001f49Smrg 52532001f49Smrg glClearColor(fogcolor[0], fogcolor[1], fogcolor[2], fogcolor[3]); 52632001f49Smrg glClear(GL_COLOR_BUFFER_BIT); 52732001f49Smrg 52832001f49Smrg calcposobs(); 52932001f49Smrg 53032001f49Smrg glutReshapeFunc(reshape); 53132001f49Smrg glutDisplayFunc(draw); 53232001f49Smrg glutKeyboardFunc(key); 53332001f49Smrg glutSpecialFunc(special); 53432001f49Smrg glutIdleFunc(idle); 53532001f49Smrg 53632001f49Smrg glEnable(GL_BLEND); 53732001f49Smrg /*glBlendFunc(GL_SRC_ALPHA_SATURATE,GL_ONE); */ 53832001f49Smrg /*glEnable(GL_POLYGON_SMOOTH); */ 53932001f49Smrg 54032001f49Smrg glutMainLoop(); 54132001f49Smrg 54232001f49Smrg cleanup(); 54332001f49Smrg return 0; 54432001f49Smrg} 545