#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#define GL_GLEXT_PROTOTYPES
+#include <GL/glew.h>
#include <GL/glut.h>
#include <assert.h>
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[] );
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();
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();
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");
}
+ /* 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);
}
glutInitWindowPosition( 0, 0 );
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
glutCreateWindow(argv[0] );
+ glewInit();
glutReshapeFunc( Reshape );
glutKeyboardFunc( Key );
glutSpecialFunc( SpecialKey );