Convert libGL and DRI drivers to require libdrm.
[mesa-demos.git] / src / tests / yuvrect.c
blobacef406097020ea07ec72937b35947a0c60c88b1
1 /*
2 * Test the GL_NV_texture_rectangle and GL_MESA_ycrcb_texture extensions.
4 * Brian Paul 13 September 2002
5 */
7 #include <assert.h>
8 #include <math.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #define GL_GLEXT_PROTOTYPES
13 #include <GL/glut.h>
15 #include "../util/readtex.c" /* I know, this is a hack. */
17 #define TEXTURE_FILE "../images/girl.rgb"
19 static GLfloat Xrot = 0, Yrot = 0, Zrot = 0;
20 static GLint ImgWidth, ImgHeight;
21 static GLushort *ImageYUV = NULL;
24 static void DrawObject(void)
26 glBegin(GL_QUADS);
28 glTexCoord2f(0, 0);
29 glVertex2f(-1.0, -1.0);
31 glTexCoord2f(ImgWidth, 0);
32 glVertex2f(1.0, -1.0);
34 glTexCoord2f(ImgWidth, ImgHeight);
35 glVertex2f(1.0, 1.0);
37 glTexCoord2f(0, ImgHeight);
38 glVertex2f(-1.0, 1.0);
40 glEnd();
44 static void Display( void )
46 glClear( GL_COLOR_BUFFER_BIT );
48 glPushMatrix();
49 glRotatef(Xrot, 1.0, 0.0, 0.0);
50 glRotatef(Yrot, 0.0, 1.0, 0.0);
51 glRotatef(Zrot, 0.0, 0.0, 1.0);
52 DrawObject();
53 glPopMatrix();
55 glutSwapBuffers();
59 static void Reshape( int width, int height )
61 glViewport( 0, 0, width, height );
62 glMatrixMode( GL_PROJECTION );
63 glLoadIdentity();
64 glFrustum( -1.0, 1.0, -1.0, 1.0, 10.0, 100.0 );
65 glMatrixMode( GL_MODELVIEW );
66 glLoadIdentity();
67 glTranslatef( 0.0, 0.0, -15.0 );
71 static void Key( unsigned char key, int x, int y )
73 (void) x;
74 (void) y;
75 switch (key) {
76 case 27:
77 exit(0);
78 break;
80 glutPostRedisplay();
84 static void SpecialKey( int key, int x, int y )
86 float step = 3.0;
87 (void) x;
88 (void) y;
90 switch (key) {
91 case GLUT_KEY_UP:
92 Xrot += step;
93 break;
94 case GLUT_KEY_DOWN:
95 Xrot -= step;
96 break;
97 case GLUT_KEY_LEFT:
98 Yrot += step;
99 break;
100 case GLUT_KEY_RIGHT:
101 Yrot -= step;
102 break;
104 glutPostRedisplay();
109 static void Init( int argc, char *argv[] )
111 GLuint texObj = 100;
112 const char *file;
114 if (!glutExtensionSupported("GL_NV_texture_rectangle")) {
115 printf("Sorry, GL_NV_texture_rectangle is required\n");
116 exit(0);
119 if (!glutExtensionSupported("GL_MESA_ycbcr_texture")) {
120 printf("Sorry, GL_MESA_ycbcr_texture is required\n");
121 exit(0);
124 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
126 glBindTexture(GL_TEXTURE_RECTANGLE_NV, texObj);
127 #ifdef LINEAR_FILTER
128 /* linear filtering looks much nicer but is much slower for Mesa */
129 glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
130 glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
131 #else
132 glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
133 glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
134 #endif
136 if (argc > 1)
137 file = argv[1];
138 else
139 file = TEXTURE_FILE;
141 ImageYUV = LoadYUVImage(file, &ImgWidth, &ImgHeight);
142 if (!ImageYUV) {
143 printf("Couldn't read %s\n", TEXTURE_FILE);
144 exit(0);
147 printf("Image: %dx%d\n", ImgWidth, ImgHeight);
149 glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0,
150 GL_YCBCR_MESA, ImgWidth, ImgHeight, 0,
151 GL_YCBCR_MESA, GL_UNSIGNED_SHORT_8_8_MESA, ImageYUV);
153 assert(glGetError() == GL_NO_ERROR);
154 glTexSubImage2D(GL_TEXTURE_RECTANGLE_NV, 0,
155 0, 0, ImgWidth, ImgHeight,
156 GL_YCBCR_MESA, GL_UNSIGNED_SHORT_8_8_MESA, ImageYUV);
158 assert(glGetError() == GL_NO_ERROR);
160 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
162 glEnable(GL_TEXTURE_RECTANGLE_NV);
164 glShadeModel(GL_FLAT);
165 glClearColor(0.3, 0.3, 0.4, 1.0);
167 if (argc > 1 && strcmp(argv[1], "-info")==0) {
168 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
169 printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
170 printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
171 printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
176 int main( int argc, char *argv[] )
178 glutInit( &argc, argv );
179 glutInitWindowSize( 300, 300 );
180 glutInitWindowPosition( 0, 0 );
181 glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
182 glutCreateWindow(argv[0] );
184 Init( argc, argv );
186 glutReshapeFunc( Reshape );
187 glutKeyboardFunc( Key );
188 glutSpecialFunc( SpecialKey );
189 glutDisplayFunc( Display );
191 glutMainLoop();
192 return 0;