Merge branch '7.8'
[mesa.git] / progs / demos / stex3d.c
index 78975f777ad549158e3d1aaed7f756ff8c129419..de18480c25e6cc69221ee1146792f9281ba9e1a2 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: stex3d.c,v 1.8 2003/03/29 16:40:23 brianp Exp $ */
-
 /*----------------------------- 
  * stex3d.c GL example of the mesa 3d-texture extention to simulate procedural
  *            texturing, it uses a perlin noise and turbulence functions.
@@ -20,7 +18,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <math.h>
-#include <GL/gl.h>
+#include <GL/glew.h>
 #include <GL/glut.h>
 
 
@@ -36,9 +34,9 @@
 
 static int tex_width=64, tex_height=64, tex_depth=64;
 static float angx=0, angy=0, angz=0;
-static GLuint DList;
-static int texgen = 2, animate = 1, smooth = 1;
+static int texgen = 2, animate = 1, smooth = 1, wireframe = 0;
 static int CurTexture = NOISE_TEXTURE, CurObject = TORUS;
+static GLenum Filter = GL_LINEAR;
 
 
 static void
@@ -301,8 +299,6 @@ create3Dtexture(void)
    printf("setting up 3d texture...\n");
 
    glBindTexture(GL_TEXTURE_3D, NOISE_TEXTURE);
-   glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-   glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);
@@ -345,19 +341,19 @@ parseCmdLine(int argc, char **argv)
    GLint i;
 
    for (i = 1; i < argc; i++) {
-      if (strstr(argv[i], "-w") == 0) {
+      if (strcmp(argv[i], "-help") == 0) {
+        printHelp();
+        return GL_FALSE;
+      }
+      else if (strstr(argv[i], "-w") != NULL) {
         tex_width = atoi((argv[i]) + 2);
       }
-      else if (strstr(argv[i], "-h") == 0) {
+      else if (strstr(argv[i], "-h") != NULL) {
         tex_height = atoi((argv[i]) + 2);
       }
-      else if (strstr(argv[i], "-d") == 0) {
+      else if (strstr(argv[i], "-d") != NULL) {
         tex_depth = atoi((argv[i]) + 2);
       }
-      else if (strcmp(argv[i], "-help") == 0) {
-        printHelp();
-        return GL_FALSE;
-      }
       else {
         printf("%s (Bad option).\n", argv[i]);
         printHelp();
@@ -409,6 +405,9 @@ drawScene(void)
       glDisable(GL_TEXTURE_GEN_R);
    }
 
+   glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, Filter);
+   glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, Filter);
+
    glCallList(CurObject);
    glPopMatrix();
 
@@ -508,6 +507,12 @@ KeyHandler(unsigned char key, int x, int y)
       else
          CurObject = TORUS;
       break;
+   case 'f':
+      if (Filter == GL_LINEAR)
+         Filter = GL_NEAREST;
+      else
+         Filter = GL_LINEAR;
+      break;
    case 'i':
       if (CurTexture == NOISE_TEXTURE)
          CurTexture = GRADIENT_TEXTURE;
@@ -516,12 +521,20 @@ KeyHandler(unsigned char key, int x, int y)
       glBindTexture(GL_TEXTURE_3D, CurTexture);
       break;
    case 'a':
+   case ' ':
       animate = !animate;
       if (animate)
          glutIdleFunc(Idle);
       else
          glutIdleFunc(NULL);
       break;
+   case 'w':
+      wireframe = !wireframe;
+      if (wireframe)
+         glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+      else
+         glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+      break;
    default:
       break;
    }
@@ -529,7 +542,7 @@ KeyHandler(unsigned char key, int x, int y)
 }
 
 
-void
+static void
 create3Dgradient(void)
 {
    unsigned char *v;
@@ -555,8 +568,6 @@ create3Dgradient(void)
 
 
    glBindTexture(GL_TEXTURE_3D, GRADIENT_TEXTURE);
-   glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-   glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);
@@ -611,12 +622,15 @@ init(void)
 
    glClearColor(.5, .5, .5, 0);
 
-   /* create torus for texturing */
-   DList = glGenLists(1);
-
-   glNewList(SPHERE, GL_COMPILE);
-   glutSolidSphere(0.95, 30, 15);
-   glEndList();
+   {
+      GLUquadricObj *q;
+      q = gluNewQuadric();
+      gluQuadricTexture( q, GL_TRUE );
+      glNewList(SPHERE, GL_COMPILE);
+      gluSphere( q, 0.95, 30, 15 );
+      glEndList();
+      gluDeleteQuadric(q);
+   }
 
    BuildTorus();
 
@@ -655,6 +669,8 @@ main(int argc, char **argv)
       exit(0);
    }
 
+   glewInit();
+
    init();
 
    printHelp();