progs/glsl: Fix vsraytrace GLSL compilation error.
[mesa.git] / progs / tests / ext422square.c
index d1c168773091f0adefc2f28398763c7153a17707..89e99f02926ea82fa7138d4bc12f477f904c5cca 100644 (file)
@@ -12,7 +12,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#define GL_GLEXT_PROTOTYPES
+#include <GL/glew.h>
 #include <GL/glut.h>
 #include <assert.h>
 
@@ -24,6 +24,7 @@ static GLfloat Xrot = 0, Yrot = 0, Zrot = 0;
 static GLint ImgWidth, ImgHeight;
 static GLushort *ImageYUV = NULL;
 static const GLuint yuvObj = 100;
+static const GLuint rgbObj = 101;
 
 static void Init( int argc, char *argv[] );
 
@@ -59,11 +60,12 @@ static void Display( void )
    glBindTexture(GL_TEXTURE_2D, yuvObj);
 
    glPushMatrix();
-      glEnable(GL_FRAGMENT_PROGRAM_ARB);
+      glEnable(GL_FRAGMENT_PROGRAM_ARB); 
       glTranslatef( -1.1, 0.0, -15.0 );
       glRotatef(Xrot, 1.0, 0.0, 0.0);
       glRotatef(Yrot, 0.0, 1.0, 0.0);
       glRotatef(Zrot, 0.0, 0.0, 1.0);
+      glBindTexture(GL_TEXTURE_2D, yuvObj);
       DrawObject();
    glPopMatrix();
 
@@ -73,6 +75,7 @@ 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);
+      glBindTexture(GL_TEXTURE_2D, rgbObj);
       DrawObject();
    glPopMatrix();
 
@@ -136,6 +139,12 @@ static void SpecialKey( int key, int x, int y )
 static void Init( int argc, char *argv[] )
 {
    const char *file;
+   const GLfloat yuvtorgb[16] = {
+      1.164,   1.164,    1.164,      0,
+      0,       -.391,    2.018,      0,
+      1.596,   -.813,    0.0,        0,
+      (-.0625*1.164 + -.5*1.596),     (-.0625*1.164 + -.5*-.813 + -.5*-.391),     (-.0625*1.164 + -.5*2.018),      1  
+   };
 
    if (!glutExtensionSupported("GL_ARB_fragment_program")) {
       printf("Error: GL_ARB_fragment_program not supported!\n");
@@ -204,6 +213,30 @@ static void Init( int argc, char *argv[] )
 
    }
 
+   /* Now the same, but use a color matrix to do the conversion at
+    * upload time:
+    */
+   glBindTexture(GL_TEXTURE_2D, rgbObj);
+   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+   glMatrixMode( GL_COLOR_MATRIX );
+   glLoadMatrixf( yuvtorgb );
+   
+   glTexImage2D(GL_TEXTURE_2D, 0,
+                GL_RGB,
+               ImgWidth, ImgHeight, 0,
+                GL_422_EXT,
+               GL_UNSIGNED_BYTE, ImageYUV);
+
+   glLoadIdentity();
+   glMatrixMode( GL_MODELVIEW );
+
+   glEnable(GL_TEXTURE_2D);
+
+   glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+
+
    glShadeModel(GL_FLAT);
    glClearColor(0.3, 0.3, 0.4, 1.0);
 }
@@ -216,6 +249,7 @@ int main( int argc, char *argv[] )
    glutInitWindowPosition( 0, 0 );
    glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
    glutCreateWindow(argv[0] );
+   glewInit();
    glutReshapeFunc( Reshape );
    glutKeyboardFunc( Key );
    glutSpecialFunc( SpecialKey );