2 * Test the GL_NV_texture_rectangle and GL_MESA_ycrcb_texture extensions.
4 * Brian Paul 13 September 2002
15 #include "../util/readtex.c" /* I know, this is a hack. */
17 #define TEXTURE_FILE "../images/tile.rgb"
19 static GLfloat Xrot
= 0, Yrot
= 0, Zrot
= 0;
20 static GLint ImgWidth
, ImgHeight
;
21 static GLushort
*ImageYUV
= NULL
;
22 static GLubyte
*ImageRGB
= NULL
;
23 static const GLuint yuvObj
= 100;
24 static const GLuint rgbObj
= 101;
27 static void DrawObject(void)
32 glVertex2f(-1.0, -1.0);
35 glVertex2f(1.0, -1.0);
41 glVertex2f(-1.0, 1.0);
47 static void Display( void )
49 glClear( GL_COLOR_BUFFER_BIT
);
52 glTranslatef( -1.1, 0.0, -15.0 );
53 glRotatef(Xrot
, 1.0, 0.0, 0.0);
54 glRotatef(Yrot
, 0.0, 1.0, 0.0);
55 glRotatef(Zrot
, 0.0, 0.0, 1.0);
56 glBindTexture(GL_TEXTURE_2D
, yuvObj
);
61 glTranslatef( 1.1, 0.0, -15.0 );
62 glRotatef(Xrot
, 1.0, 0.0, 0.0);
63 glRotatef(Yrot
, 0.0, 1.0, 0.0);
64 glRotatef(Zrot
, 0.0, 0.0, 1.0);
65 glBindTexture(GL_TEXTURE_2D
, rgbObj
);
73 static void Reshape( int width
, int height
)
75 glViewport( 0, 0, width
, height
);
76 glMatrixMode( GL_PROJECTION
);
78 glFrustum( -1.1, 1.1, -1.1, 1.1, 10.0, 100.0 );
79 glMatrixMode( GL_MODELVIEW
);
81 glTranslatef( 0.0, 0.0, -15.0 );
85 static void Key( unsigned char key
, int x
, int y
)
98 static void SpecialKey( int key
, int x
, int y
)
122 #define CLAMP( X, MIN, MAX ) ( (X)<(MIN) ? (MIN) : ((X)>(MAX) ? (MAX) : (X)) )
126 /* #define LINEAR_FILTER */
128 static void Init( int argc
, char *argv
[] )
133 if (!glutExtensionSupported("GL_MESA_ycbcr_texture")) {
134 printf("Sorry, GL_MESA_ycbcr_texture is required\n");
138 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
145 /* First load the texture as YCbCr.
148 glBindTexture(GL_TEXTURE_2D
, yuvObj
);
149 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
150 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
152 ImageYUV
= LoadYUVImage(file
, &ImgWidth
, &ImgHeight
);
154 printf("Couldn't read %s\n", TEXTURE_FILE
);
158 printf("Image: %dx%d\n", ImgWidth
, ImgHeight
);
161 glTexImage2D(GL_TEXTURE_2D
, 0,
163 ImgWidth
, ImgHeight
, 0,
165 GL_UNSIGNED_SHORT_8_8_MESA
, ImageYUV
);
167 glEnable(GL_TEXTURE_2D
);
169 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_MODULATE
);
173 /* Now load the texture as RGB.
176 glBindTexture(GL_TEXTURE_2D
, rgbObj
);
177 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
178 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
180 ImageRGB
= LoadRGBImage(file
, &ImgWidth
, &ImgHeight
, &format
);
182 printf("Couldn't read %s\n", TEXTURE_FILE
);
186 printf("Image: %dx%d\n", ImgWidth
, ImgHeight
);
189 glTexImage2D(GL_TEXTURE_2D
, 0,
191 ImgWidth
, ImgHeight
, 0,
193 GL_UNSIGNED_BYTE
, ImageRGB
);
195 glEnable(GL_TEXTURE_2D
);
197 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_MODULATE
);
201 glShadeModel(GL_FLAT
);
202 glClearColor(0.3, 0.3, 0.4, 1.0);
204 if (argc
> 1 && strcmp(argv
[1], "-info")==0) {
205 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
206 printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION
));
207 printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR
));
208 printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS
));
211 printf( "Both images should appear the same.\n" );
215 int main( int argc
, char *argv
[] )
217 glutInit( &argc
, argv
);
218 glutInitWindowSize( 300, 300 );
219 glutInitWindowPosition( 0, 0 );
220 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
);
221 glutCreateWindow(argv
[0] );
226 glutReshapeFunc( Reshape
);
227 glutKeyboardFunc( Key
);
228 glutSpecialFunc( SpecialKey
);
229 glutDisplayFunc( Display
);