blob: 494586776a062d66d97566323b1ab77d3b8121a9 [file] [log] [blame]
Keith Whitwelleea72ff2003-05-20 08:50:02 +00001/*
2 * Test the GL_NV_texture_rectangle and GL_MESA_ycrcb_texture extensions.
3 *
4 * Brian Paul 13 September 2002
5 */
6
7
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>
14
15#include "../util/readtex.c" /* I know, this is a hack. */
16
17#define TEXTURE_FILE "../images/tile.rgb"
18
19static GLfloat Xrot = 0, Yrot = 0, Zrot = 0;
20static GLint ImgWidth, ImgHeight;
Keith Whitwelleea72ff2003-05-20 08:50:02 +000021static GLushort *ImageYUV = NULL;
Brian Paulf98921d2003-05-30 15:36:04 +000022static GLubyte *ImageRGB = NULL;
23static const GLuint yuvObj = 100;
24static const GLuint rgbObj = 101;
Keith Whitwelleea72ff2003-05-20 08:50:02 +000025
26
27static void DrawObject(void)
28{
29 glBegin(GL_QUADS);
30
31 glTexCoord2f(0, 0);
32 glVertex2f(-1.0, -1.0);
33
34 glTexCoord2f(1, 0);
35 glVertex2f(1.0, -1.0);
36
37 glTexCoord2f(1, 1);
38 glVertex2f(1.0, 1.0);
39
40 glTexCoord2f(0, 1);
41 glVertex2f(-1.0, 1.0);
42
43 glEnd();
44}
45
46
47static void Display( void )
48{
49 glClear( GL_COLOR_BUFFER_BIT );
50
51 glPushMatrix();
Brian Paulf98921d2003-05-30 15:36:04 +000052 glTranslatef( -1.1, 0.0, -15.0 );
Keith Whitwelleea72ff2003-05-20 08:50:02 +000053 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);
Brian Paulf98921d2003-05-30 15:36:04 +000056 glBindTexture(GL_TEXTURE_2D, yuvObj);
57 DrawObject();
58 glPopMatrix();
59
60 glPushMatrix();
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);
Keith Whitwelleea72ff2003-05-20 08:50:02 +000066 DrawObject();
67 glPopMatrix();
68
69 glutSwapBuffers();
70}
71
72
73static void Reshape( int width, int height )
74{
75 glViewport( 0, 0, width, height );
76 glMatrixMode( GL_PROJECTION );
77 glLoadIdentity();
Brian Paulf98921d2003-05-30 15:36:04 +000078 glFrustum( -1.1, 1.1, -1.1, 1.1, 10.0, 100.0 );
Keith Whitwelleea72ff2003-05-20 08:50:02 +000079 glMatrixMode( GL_MODELVIEW );
80 glLoadIdentity();
81 glTranslatef( 0.0, 0.0, -15.0 );
82}
83
84
85static void Key( unsigned char key, int x, int y )
86{
87 (void) x;
88 (void) y;
89 switch (key) {
90 case 27:
91 exit(0);
92 break;
93 }
94 glutPostRedisplay();
95}
96
97
98static void SpecialKey( int key, int x, int y )
99{
100 float step = 3.0;
101 (void) x;
102 (void) y;
103
104 switch (key) {
105 case GLUT_KEY_UP:
106 Xrot += step;
107 break;
108 case GLUT_KEY_DOWN:
109 Xrot -= step;
110 break;
111 case GLUT_KEY_LEFT:
112 Yrot += step;
113 break;
114 case GLUT_KEY_RIGHT:
115 Yrot -= step;
116 break;
117 }
118 glutPostRedisplay();
119}
120
121
122#define CLAMP( X, MIN, MAX ) ( (X)<(MIN) ? (MIN) : ((X)>(MAX) ? (MAX) : (X)) )
123
Keith Whitwelleea72ff2003-05-20 08:50:02 +0000124
125
126/* #define LINEAR_FILTER */
127
128static void Init( int argc, char *argv[] )
129{
Keith Whitwelleea72ff2003-05-20 08:50:02 +0000130 const char *file;
131 int error;
Brian Paulf98921d2003-05-30 15:36:04 +0000132 GLenum format;
Keith Whitwelleea72ff2003-05-20 08:50:02 +0000133
134 if (!glutExtensionSupported("GL_MESA_ycbcr_texture")) {
135 printf("Sorry, GL_MESA_ycbcr_texture is required\n");
136 exit(0);
137 }
138
139 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
140
Keith Whitwelleea72ff2003-05-20 08:50:02 +0000141 if (argc > 1)
142 file = argv[1];
143 else
144 file = TEXTURE_FILE;
145
Brian Paulf98921d2003-05-30 15:36:04 +0000146 /* First load the texture as YCbCr.
147 */
148
149 glBindTexture(GL_TEXTURE_2D, yuvObj);
150 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
151 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
152
Keith Whitwell27358a22003-05-20 09:54:58 +0000153 ImageYUV = LoadYUVImage(file, &ImgWidth, &ImgHeight );
Keith Whitwelleea72ff2003-05-20 08:50:02 +0000154 if (!ImageYUV) {
155 printf("Couldn't read %s\n", TEXTURE_FILE);
156 exit(0);
157 }
158
159 printf("Image: %dx%d\n", ImgWidth, ImgHeight);
160
Keith Whitwelleea72ff2003-05-20 08:50:02 +0000161
Keith Whitwelleea72ff2003-05-20 08:50:02 +0000162 glTexImage2D(GL_TEXTURE_2D, 0,
163 GL_YCBCR_MESA,
164 ImgWidth, ImgHeight, 0,
165 GL_YCBCR_MESA,
166 GL_UNSIGNED_SHORT_8_8_MESA, ImageYUV);
Keith Whitwelleea72ff2003-05-20 08:50:02 +0000167
168 glEnable(GL_TEXTURE_2D);
169
170 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
171
Brian Paulf98921d2003-05-30 15:36:04 +0000172
173
174 /* Now load the texture as RGB.
175 */
176
177 glBindTexture(GL_TEXTURE_2D, rgbObj);
178 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
179 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
180
181 ImageRGB = LoadRGBImage(file, &ImgWidth, &ImgHeight, &format );
182 if (!ImageRGB) {
183 printf("Couldn't read %s\n", TEXTURE_FILE);
184 exit(0);
185 }
186
187 printf("Image: %dx%d\n", ImgWidth, ImgHeight);
188
189
190 glTexImage2D(GL_TEXTURE_2D, 0,
191 format,
192 ImgWidth, ImgHeight, 0,
193 format,
194 GL_UNSIGNED_BYTE, ImageRGB);
195
196 glEnable(GL_TEXTURE_2D);
197
198 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
199
200
Keith Whitwelleea72ff2003-05-20 08:50:02 +0000201
202 glShadeModel(GL_FLAT);
203 glClearColor(0.3, 0.3, 0.4, 1.0);
204
205 if (argc > 1 && strcmp(argv[1], "-info")==0) {
206 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
207 printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
208 printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
209 printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
210 }
Brian Paulf98921d2003-05-30 15:36:04 +0000211
212 printf( "Both images should appear the same.\n" );
Keith Whitwelleea72ff2003-05-20 08:50:02 +0000213}
214
215
216int main( int argc, char *argv[] )
217{
218 glutInit( &argc, argv );
219 glutInitWindowSize( 300, 300 );
220 glutInitWindowPosition( 0, 0 );
221 glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
222 glutCreateWindow(argv[0] );
223
224 Init( argc, argv );
225
226 glutReshapeFunc( Reshape );
227 glutKeyboardFunc( Key );
228 glutSpecialFunc( SpecialKey );
229 glutDisplayFunc( Display );
230
231 glutMainLoop();
232 return 0;
233}