r300-gallium: Properly emit indexbufs.
[mesa.git] / progs / trivial / quad-tex-2d.c
index 70b9fbf8c6172bd9a9458ccbb96e483659d8e48c..8a886ef578c9c4db15ffdcd93cd83970f0f60448 100644 (file)
 #include <stdlib.h>
 #include <GL/glut.h>
 
-
-#define CI_OFFSET_1 16
-#define CI_OFFSET_2 32
-
+static GLenum Target = GL_TEXTURE_2D;
+static GLenum Filter = GL_NEAREST;
 GLenum doubleBuffer;
+static float Rot = 0;
+static int win = 0;
 
 static void Init(void)
 {
    fprintf(stderr, "GL_RENDERER   = %s\n", (char *) glGetString(GL_RENDERER));
    fprintf(stderr, "GL_VERSION    = %s\n", (char *) glGetString(GL_VERSION));
    fprintf(stderr, "GL_VENDOR     = %s\n", (char *) glGetString(GL_VENDOR));
+   fflush(stderr);
 
    glClearColor(0.0, 0.0, 1.0, 0.0);
 
-#define SIZE 16
+#define SIZE 32
    {
       GLubyte tex2d[SIZE][SIZE][3];
       GLint s, t;
@@ -60,59 +61,77 @@ static void Init(void)
         }
       }
 
+      glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+
+      if (Target == GL_TEXTURE_1D)
+         glTexImage1D(Target, 0, 3, SIZE, 0, GL_RGB, GL_UNSIGNED_BYTE, tex2d);
+      else
+         glTexImage2D(Target, 0, 3, SIZE, SIZE, 0,
+                      GL_RGB, GL_UNSIGNED_BYTE, tex2d);
+
+      glEnable(Target);
       glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
-      glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT);
-      glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-      glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+      glTexParameterf(Target, GL_TEXTURE_WRAP_R, GL_REPEAT);
+      glTexParameterf(Target, GL_TEXTURE_MIN_FILTER, Filter);
+      glTexParameterf(Target, GL_TEXTURE_MAG_FILTER, Filter);
 
-      glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
-      glTexImage2D(GL_TEXTURE_2D, 0, 3, SIZE, SIZE, 0,
-                  GL_RGB, GL_UNSIGNED_BYTE, tex2d);
       glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
-      glEnable(GL_TEXTURE_2D);
    }
-
 }
 
 static void Reshape(int width, int height)
 {
-
-    glViewport(0, 0, (GLint)width, (GLint)height);
-
-    glMatrixMode(GL_PROJECTION);
-    glLoadIdentity();
-    glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
-    glMatrixMode(GL_MODELVIEW);
+   glViewport(0, 0, (GLint)width, (GLint)height);
+   glMatrixMode(GL_PROJECTION);
+   glLoadIdentity();
+#if 0
+   glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
+#else
+   glFrustum(-1, 1, -1, 1, 10, 20);
+#endif
+   glMatrixMode(GL_MODELVIEW);
+   glLoadIdentity();
+   glTranslatef(0, 0, -15);
 }
 
 static void Key(unsigned char key, int x, int y)
 {
-
-    switch (key) {
-      case 27:
-       exit(1);
-      default:
-       return;
-    }
-
-    glutPostRedisplay();
+   switch (key) {
+   case 'r':
+      Rot += 10.0;
+      break;
+   case 'R':
+      Rot -= 10.0;
+      break;
+   case 27:
+      glutDestroyWindow(win);
+      exit(0);
+   default:
+      return;
+   }
+   glutPostRedisplay();
 }
 
 static void Draw(void)
 {
    glClear(GL_COLOR_BUFFER_BIT); 
 
+   glPushMatrix();
+   glRotatef(Rot, 0, 1, 0);
+
    glBegin(GL_QUADS);
    glTexCoord2f(1,0); 
-   glVertex3f( 0.9, -0.9, -30.0);
+   glVertex3f( 0.9, -0.9, 0.0);
    glTexCoord2f(1,1); 
-   glVertex3f( 0.9,  0.9, -30.0);
+   glVertex3f( 0.9,  0.9, 0.0);
    glTexCoord2f(0,1); 
-   glVertex3f(-0.9,  0.9, -30.0);
+   glVertex3f(-0.9,  0.9, 0.0);
    glTexCoord2f(0,0); 
-   glVertex3f(-0.9,  -0.9, -30.0);
+   glVertex3f(-0.9,  -0.9, 0.0);
    glEnd();
 
+   glPopMatrix();
+
    glFlush();
 
    if (doubleBuffer) {
@@ -155,7 +174,8 @@ int main(int argc, char **argv)
     type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
     glutInitDisplayMode(type);
 
-    if (glutCreateWindow("First Tri") == GL_FALSE) {
+    win = glutCreateWindow(*argv);
+    if (!win) {
        exit(1);
     }
 
@@ -165,5 +185,5 @@ int main(int argc, char **argv)
     glutKeyboardFunc(Key);
     glutDisplayFunc(Draw);
     glutMainLoop();
-       return 0;
+    return 0;
 }