progs/tests: also test stencil INCR_WRAP mode if supported
[mesa.git] / progs / tests / texline.c
index 1f5cd3f31f000095b5dee6dc603cc3d7d5155da3..1803832b47e6ddadc75d9dd44080def92042856d 100644 (file)
@@ -1,4 +1,3 @@
-/* $Id: texline.c,v 1.1 2000/09/30 18:48:33 brianp Exp $ */
 
 /*
  * Test textured lines.
@@ -7,23 +6,25 @@
  * September 2000
  */
 
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <math.h>
+#include <GL/glew.h>
 #include <GL/glut.h>
 #include "../util/readtex.c"   /* I know, this is a hack. */
 
 #define TEXTURE_FILE "../images/girl.rgb"
 
 static GLboolean Antialias = GL_FALSE;
-static GLboolean Animate = GL_TRUE;
-static GLboolean Texture = GL_TRUE;
+static GLboolean Animate = GL_FALSE;
+static GLint Texture = 1;
+static GLboolean Stipple = GL_FALSE;
 static GLfloat LineWidth = 1.0;
 
 static GLfloat Xrot = -60.0, Yrot = 0.0, Zrot = 0.0;
 static GLfloat DYrot = 1.0;
-
+static GLboolean Points = GL_FALSE;
+static GLfloat Scale = 1.0;
 
 static void Idle( void )
 {
@@ -36,7 +37,7 @@ static void Idle( void )
 
 static void Display( void )
 {
-   GLfloat x, t;
+   GLfloat x, y, s, t;
 
    glClear( GL_COLOR_BUFFER_BIT );
 
@@ -44,15 +45,43 @@ static void Display( void )
    glRotatef(Xrot, 1.0, 0.0, 0.0);
    glRotatef(Yrot, 0.0, 1.0, 0.0);
    glRotatef(Zrot, 0.0, 0.0, 1.0);
-
-   glColor3f(1, 1, 1);
-   glBegin(GL_LINES);
-   for (t = 0.0; t <= 1.0; t += 0.0125) {
-      x = t * 2.0 - 1.0;
-      glTexCoord2f(t, 0.0);  glVertex2f(x, -1.0);
-      glTexCoord2f(t, 1.0);  glVertex2f(x, 1.0);
+   glScalef(Scale, Scale, Scale);
+
+   if (Texture)
+      glColor3f(1, 1, 1);
+
+   if (Points) {
+      glBegin(GL_POINTS);
+      for (t = 0.0; t <= 1.0; t += 0.025) {
+         for (s = 0.0; s <= 1.0; s += 0.025) {
+            x = s * 2.0 - 1.0;
+            y = t * 2.0 - 1.0;
+            if (!Texture)
+               glColor3f(1, 0, 1);
+            glMultiTexCoord2fARB(GL_TEXTURE1_ARB, t, s);
+            glTexCoord2f(s, t);
+            glVertex2f(x, y);
+         }
+      }
+      glEnd();
+   }
+   else {
+      glBegin(GL_LINES);
+      for (t = 0.0; t <= 1.0; t += 0.025) {
+         x = t * 2.0 - 1.0;
+         if (!Texture)
+            glColor3f(1, 0, 1);
+         glTexCoord2f(t, 0.0);
+         glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0, t);
+         glVertex2f(x, -1.0);
+         if (!Texture)
+            glColor3f(0, 1, 0);
+         glTexCoord2f(t, 1.0);
+         glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0, t);
+         glVertex2f(x, 1.0);
+      }
+      glEnd();
    }
-   glEnd();
 
    glPopMatrix();
 
@@ -82,32 +111,62 @@ static void Key( unsigned char key, int x, int y )
          Antialias = !Antialias;
          if (Antialias) {
             glEnable(GL_LINE_SMOOTH);
+            glEnable(GL_POINT_SMOOTH);
             glEnable(GL_BLEND);
             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
          }
          else {
             glDisable(GL_LINE_SMOOTH);
+            glDisable(GL_POINT_SMOOTH);
             glDisable(GL_BLEND);
          }
          break;
       case 't':
-         Texture = !Texture;
-         if (Texture)
+         Texture++;
+         if (Texture > 2)
+            Texture = 0;
+         if (Texture == 0) {
+            glActiveTextureARB(GL_TEXTURE0_ARB);
+            glDisable(GL_TEXTURE_2D);
+            glActiveTextureARB(GL_TEXTURE1_ARB);
+            glDisable(GL_TEXTURE_2D);
+         }
+         else if (Texture == 1) {
+            glActiveTextureARB(GL_TEXTURE0_ARB);
             glEnable(GL_TEXTURE_2D);
-         else
+            glActiveTextureARB(GL_TEXTURE1_ARB);
             glDisable(GL_TEXTURE_2D);
+         }
+         else {
+            glActiveTextureARB(GL_TEXTURE0_ARB);
+            glEnable(GL_TEXTURE_2D);
+            glActiveTextureARB(GL_TEXTURE1_ARB);
+            glEnable(GL_TEXTURE_2D);
+         }
          break;
       case 'w':
          LineWidth -= 0.25;
          if (LineWidth < 0.25)
             LineWidth = 0.25;
          glLineWidth(LineWidth);
+         glPointSize(LineWidth);
          break;
       case 'W':
          LineWidth += 0.25;
          if (LineWidth > 8.0)
             LineWidth = 8.0;
          glLineWidth(LineWidth);
+         glPointSize(LineWidth);
+         break;
+      case 'p':
+         Points = !Points;
+         break;
+      case 's':
+         Stipple = !Stipple;
+         if (Stipple)
+            glEnable(GL_LINE_STIPPLE);
+         else
+            glDisable(GL_LINE_STIPPLE);
          break;
       case ' ':
          Animate = !Animate;
@@ -120,7 +179,7 @@ static void Key( unsigned char key, int x, int y )
          exit(0);
          break;
    }
-   printf("Width %f\n", LineWidth);
+   printf("LineWidth, PointSize = %f\n", LineWidth);
    glutPostRedisplay();
 }
 
@@ -151,37 +210,61 @@ static void SpecialKey( int key, int x, int y )
 
 static void Init( int argc, char *argv[] )
 {
-   glEnable(GL_TEXTURE_2D);
-   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-
-   glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-
-   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
-   if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) {
-      printf("Error: couldn't load texture image\n");
-      exit(1);
+   GLfloat r[2];
+   GLuint u;
+
+   for (u = 0; u < 2; u++) {
+      glActiveTextureARB(GL_TEXTURE0_ARB + u);
+      glBindTexture(GL_TEXTURE_2D, 10+u);
+      if (u == 0)
+         glEnable(GL_TEXTURE_2D);
+      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+      if (u == 0)
+         glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+      else
+         glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD);
+
+      glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+      if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) {
+         printf("Error: couldn't load texture image\n");
+         exit(1);
+      }
    }
 
+   glLineStipple(1, 0xff);
+
    if (argc > 1 && strcmp(argv[1], "-info")==0) {
       printf("GL_RENDERER   = %s\n", (char *) glGetString(GL_RENDERER));
       printf("GL_VERSION    = %s\n", (char *) glGetString(GL_VERSION));
       printf("GL_VENDOR     = %s\n", (char *) glGetString(GL_VENDOR));
       printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
    }
+
+   glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, r);
+   printf("Non-smooth point size range: %g .. %g\n", r[0], r[1]);
+   glGetFloatv(GL_POINT_SIZE_RANGE, r);
+   printf("Smoothed point size range: %g .. %g\n", r[0], r[1]);
+   glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, r);
+   printf("Non-smooth line width range: %g .. %g\n", r[0], r[1]);
+   glGetFloatv(GL_LINE_WIDTH_RANGE, r);
+   printf("Smoothed line width range: %g .. %g\n", r[0], r[1]);
 }
 
 
 int main( int argc, char *argv[] )
 {
    glutInit( &argc, argv );
+   glutInitWindowPosition(0, 0);
    glutInitWindowSize( 400, 300 );
 
    glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
 
    glutCreateWindow(argv[0] );
+   glewInit();
 
    Init(argc, argv);
 
@@ -189,7 +272,8 @@ int main( int argc, char *argv[] )
    glutKeyboardFunc( Key );
    glutSpecialFunc( SpecialKey );
    glutDisplayFunc( Display );
-   glutIdleFunc( Idle );
+   if (Animate)
+      glutIdleFunc( Idle );
 
    glutMainLoop();
    return 0;