2 * Test the GL_NV_texture_rectangle and GL_MESA_ycrcb_texture extensions.
4 * Brian Paul 13 September 2002
12 #define GL_GLEXT_PROTOTYPES
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)
29 glVertex2f(-1.0, -1.0);
31 glTexCoord2f(ImgWidth
, 0);
32 glVertex2f(1.0, -1.0);
34 glTexCoord2f(ImgWidth
, ImgHeight
);
37 glTexCoord2f(0, ImgHeight
);
38 glVertex2f(-1.0, 1.0);
44 static void Display( void )
46 glClear( GL_COLOR_BUFFER_BIT
);
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);
59 static void Reshape( int width
, int height
)
61 glViewport( 0, 0, width
, height
);
62 glMatrixMode( GL_PROJECTION
);
64 glFrustum( -1.0, 1.0, -1.0, 1.0, 10.0, 100.0 );
65 glMatrixMode( GL_MODELVIEW
);
67 glTranslatef( 0.0, 0.0, -15.0 );
71 static void Key( unsigned char key
, int x
, int y
)
84 static void SpecialKey( int key
, int x
, int y
)
109 static void Init( int argc
, char *argv
[] )
114 if (!glutExtensionSupported("GL_NV_texture_rectangle")) {
115 printf("Sorry, GL_NV_texture_rectangle is required\n");
119 if (!glutExtensionSupported("GL_MESA_ycbcr_texture")) {
120 printf("Sorry, GL_MESA_ycbcr_texture is required\n");
124 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
126 glBindTexture(GL_TEXTURE_RECTANGLE_NV
, texObj
);
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
);
132 glTexParameteri(GL_TEXTURE_RECTANGLE_NV
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
133 glTexParameteri(GL_TEXTURE_RECTANGLE_NV
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
141 ImageYUV
= LoadYUVImage(file
, &ImgWidth
, &ImgHeight
);
143 printf("Couldn't read %s\n", TEXTURE_FILE
);
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] );
186 glutReshapeFunc( Reshape
);
187 glutKeyboardFunc( Key
);
188 glutSpecialFunc( SpecialKey
);
189 glutDisplayFunc( Display
);