progs/fp: close file (bug 26559)
[mesa.git] / progs / fp / fp-tri.c
index b695901bcddf443d5797f54b96d3bd66820e819b..e45a799a00eb639d47c367616c7fd99538d1853d 100644 (file)
 #include <GL/glew.h>
 #include <GL/glut.h>
 
+#include "readtex.c"
+
+
+#define TEXTURE_FILE "../images/bw.rgb"
+
 unsigned show_fps = 0;
 unsigned int frame_cnt = 0;
 void alarmhandler(int);
@@ -65,9 +70,10 @@ static void args(int argc, char *argv[])
 
 static void Init( void )
 {
+   GLuint Texture;
    GLint errno;
    GLuint prognum;
-   char buf[4096];
+   char buf[50000];
    GLuint sz;
    FILE *f;
 
@@ -83,7 +89,7 @@ static void Init( void )
    }
    fprintf(stderr, "%.*s\n", sz, buf);
 
-   if (!glutExtensionSupported("GL_ARB_fragment_program")) {
+   if (!GLEW_ARB_fragment_program) {
       printf("Error: GL_ARB_fragment_program not supported!\n");
       exit(1);
    }
@@ -107,7 +113,82 @@ static void Init( void )
    }
    glEnable(GL_FRAGMENT_PROGRAM_ARB);
 
-   glClearColor(.3, .3, .3, 0);
+
+   /* Load texture */
+   glGenTextures(1, &Texture);
+   glBindTexture(GL_TEXTURE_2D, Texture);
+   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+   if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) {
+      printf("Error: couldn't load texture image file %s\n", TEXTURE_FILE);
+      exit(1);
+   }
+
+
+   glGenTextures(1, &Texture);
+   glActiveTextureARB(GL_TEXTURE0_ARB + 1);
+   glBindTexture(GL_TEXTURE_2D, Texture);
+   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+
+   {
+      GLubyte data[32][32];
+      int width = 32;
+      int height = 32;
+      int i;
+      int j;
+
+      for (i = 0; i < 32; i++)
+         for (j = 0; j < 32; j++)
+        {
+           /**
+            ** +-----------+
+            ** |     W     |
+            ** |  +-----+  |
+            ** |  |     |  |
+            ** |  |  B  |  |
+            ** |  |     |  |
+            ** |  +-----+  |
+            ** |           |
+            ** +-----------+
+            **/
+           int i2 = i - height / 2;
+           int j2 = j - width / 2;
+           int h8 = height / 8;
+           int w8 = width / 8;
+           if ( -h8 <= i2 && i2 <= h8 && -w8 <= j2 && j2 <= w8 ) {
+              data[i][j] = 0x00;
+           } else if ( -2 * h8 <= i2 && i2 <= 2 * h8 && -2 * w8 <= j2 && j2 <= 2 * w8 ) {
+              data[i][j] = 0x55;
+           } else if ( -3 * h8 <= i2 && i2 <= 3 * h8 && -3 * w8 <= j2 && j2 <= 3 * w8 ) {
+              data[i][j] = 0xaa;
+           } else {
+              data[i][j] = 0xff;
+           }
+        }
+
+      glTexImage2D( GL_TEXTURE_2D, 0,
+                    GL_ALPHA8,
+                    32, 32, 0,
+                    GL_ALPHA, GL_UNSIGNED_BYTE, data );
+   }
+
+
+   {
+      const float Ambient[4] = { 0.0, 1.0, 0.0, 0.0 };
+      const float Diffuse[4] = { 1.0, 0.0, 0.0, 0.0 };
+      const float Specular[4] = { 0.0, 0.0, 1.0, 0.0 };
+      const float Emission[4] = { 0.0, 0.0, 0.0, 1.0 };
+      glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, Ambient);
+      glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, Diffuse);
+      glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, Specular);
+      glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, Emission);
+   }
+
+   glClearColor(.1, .3, .5, 0);
+   fclose(f);
 }
 
 static void Reshape(int width, int height)
@@ -128,7 +209,7 @@ static void Key(unsigned char key, int x, int y)
       case 27:
        exit(1);
       default:
-       return;
+       break;
     }
 
     glutPostRedisplay();
@@ -141,11 +222,17 @@ static void Display(void)
    glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 0, 1.0, 1.0, 0.0, 0.0);
    glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 1, 0.0, 0.0, 1.0, 1.0);
    glBegin(GL_TRIANGLES);
+
    glColor3f(0,0,1);
+   glTexCoord3f(1,1,0);
    glVertex3f( 0.9, -0.9, -30.0);
+
    glColor3f(1,0,0);
+   glTexCoord3f(1,-1,0);
    glVertex3f( 0.9,  0.9, -30.0);
+
    glColor3f(0,1,0);
+   glTexCoord3f(-1,0,0);
    glVertex3f(-0.9,  0.0, -30.0);
    glEnd();