Merge branch 'mesa_7_6_branch'
[mesa.git] / progs / demos / tunnel.c
index 431d286603080d8bda0965e2d3c62560715820dd..6981da32988db505d92f2b112a6423c7418a4b50 100644 (file)
@@ -9,15 +9,15 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <math.h>
-#include <time.h>
+#include <string.h>
 
 #ifdef WIN32
 #include <windows.h>
 #endif
 
 #include <GL/glut.h>
-#include "../util/readtex.c"
-#include "tunneldat.c"
+#include "readtex.h"
+#include "tunneldat.h"
 
 #ifdef XMESA
 #include "GL/xmesa.h"
@@ -29,6 +29,7 @@ static int HEIGHT = 480;
 
 static GLint T0 = 0;
 static GLint Frames = 0;
+static GLint NiceFog = 1;
 
 #define NUMBLOC 5
 
@@ -36,6 +37,7 @@ static GLint Frames = 0;
 #define M_PI 3.1415926535
 #endif
 
+/*
 extern int striplength_skin_13[];
 extern float stripdata_skin_13[];
 
@@ -47,13 +49,13 @@ extern float stripdata_skin_11[];
 
 extern int striplength_skin_9[];
 extern float stripdata_skin_9[];
-
+*/
 
 static int win = 0;
 
 static float obs[3] = { 1000.0, 0.0, 2.0 };
 static float dir[3];
-static float v = 0.5;
+static float v = 30.;
 static float alpha = 90.0;
 static float beta = 90.0;
 
@@ -82,7 +84,7 @@ inittextures(void)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
 
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
-                  GL_LINEAR_MIPMAP_LINEAR);
+                  GL_LINEAR_MIPMAP_NEAREST);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 
    glGenTextures(1, &t2id);
@@ -104,7 +106,7 @@ inittextures(void)
 }
 
 static void
-drawobjs(int *l, float *f)
+drawobjs(const int *l, const float *f)
 {
    int mend, j;
 
@@ -158,13 +160,27 @@ drawobjs(int *l, float *f)
 static void
 calcposobs(void)
 {
+   static double t0 = -1.;
+   double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;
+   if (t0 < 0.0)
+      t0 = t;
+   dt = t - t0;
+   t0 = t;
+
    dir[0] = sin(alpha * M_PI / 180.0);
    dir[1] = cos(alpha * M_PI / 180.0) * sin(beta * M_PI / 180.0);
    dir[2] = cos(beta * M_PI / 180.0);
 
-   obs[0] += v * dir[0];
-   obs[1] += v * dir[1];
-   obs[2] += v * dir[2];
+   if (dir[0] < 1.0e-5 && dir[0] > -1.0e-5)
+      dir[0] = 0;
+   if (dir[1] < 1.0e-5 && dir[1] > -1.0e-5)
+      dir[1] = 0;
+   if (dir[2] < 1.0e-5 && dir[2] > -1.0e-5)
+      dir[2] = 0;
+
+   obs[0] += v * dir[0] * dt;
+   obs[1] += v * dir[1] * dt;
+   obs[2] += v * dir[2] * dt;
 }
 
 static void
@@ -186,19 +202,27 @@ special(int k, int x, int y)
    }
 }
 
+static void
+cleanup(void)
+{
+   glDeleteTextures(1, &t1id);
+   glDeleteTextures(1, &t2id);
+}
+
 static void
 key(unsigned char k, int x, int y)
 {
    switch (k) {
    case 27:
+      cleanup();
       exit(0);
       break;
 
    case 'a':
-      v += 0.01;
+      v += 5.;
       break;
    case 'z':
-      v -= 0.01;
+      v -= 5.;
       break;
 
 #ifdef XMESA
@@ -241,6 +265,10 @@ key(unsigned char k, int x, int y)
       inittextures();
       fprintf(stderr, "Done.\n");
       break;
+   case 'n':
+      NiceFog = !NiceFog;
+      printf("NiceFog %d\n", NiceFog);
+      break;
    }
    glutPostRedisplay();
 }
@@ -280,15 +308,15 @@ printhelp(void)
    printstring(GLUT_BITMAP_TIMES_ROMAN_24, "Help");
 
    glRasterPos2i(60, 390);
-   printstring(GLUT_BITMAP_TIMES_ROMAN_24, "h - Togle Help");
+   printstring(GLUT_BITMAP_TIMES_ROMAN_24, "h - Toggle Help");
    glRasterPos2i(60, 360);
-   printstring(GLUT_BITMAP_TIMES_ROMAN_24, "t - Togle Textures");
+   printstring(GLUT_BITMAP_TIMES_ROMAN_24, "t - Toggle Textures");
    glRasterPos2i(60, 330);
-   printstring(GLUT_BITMAP_TIMES_ROMAN_24, "f - Togle Fog");
+   printstring(GLUT_BITMAP_TIMES_ROMAN_24, "f - Toggle Fog");
    glRasterPos2i(60, 300);
-   printstring(GLUT_BITMAP_TIMES_ROMAN_24, "m - Togle strips");
+   printstring(GLUT_BITMAP_TIMES_ROMAN_24, "m - Toggle strips");
    glRasterPos2i(60, 270);
-   printstring(GLUT_BITMAP_TIMES_ROMAN_24, "b - Togle Back face culling");
+   printstring(GLUT_BITMAP_TIMES_ROMAN_24, "b - Toggle Back face culling");
    glRasterPos2i(60, 240);
    printstring(GLUT_BITMAP_TIMES_ROMAN_24, "Arrow Keys - Rotate");
    glRasterPos2i(60, 210);
@@ -299,7 +327,7 @@ printhelp(void)
    glRasterPos2i(60, 150);
    if (joyavailable)
       printstring(GLUT_BITMAP_TIMES_ROMAN_24,
-                 "j - Togle jostick control (Joystick control available)");
+                 "j - Toggle jostick control (Joystick control available)");
    else
       printstring(GLUT_BITMAP_TIMES_ROMAN_24,
                  "(No Joystick control available)");
@@ -356,6 +384,11 @@ draw(void)
    int i;
    float base, offset;
 
+   if (NiceFog)
+      glHint(GL_FOG_HINT, GL_NICEST);
+   else
+      glHint(GL_FOG_HINT, GL_DONT_CARE);
+
    dojoy();
 
    glClear(GL_COLOR_BUFFER_BIT);
@@ -506,5 +539,6 @@ main(int ac, char **av)
 
    glutMainLoop();
 
+   cleanup();
    return 0;
 }