blob: eab255b42754cf4b87786a9f0d4034ab0efee9f7 [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;
22
23
24static void DrawObject(void)
25{
26 glBegin(GL_QUADS);
27
28 glTexCoord2f(0, 0);
29 glVertex2f(-1.0, -1.0);
30
31 glTexCoord2f(1, 0);
32 glVertex2f(1.0, -1.0);
33
34 glTexCoord2f(1, 1);
35 glVertex2f(1.0, 1.0);
36
37 glTexCoord2f(0, 1);
38 glVertex2f(-1.0, 1.0);
39
40 glEnd();
41}
42
43
44static void Display( void )
45{
46 glClear( GL_COLOR_BUFFER_BIT );
47
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();
54
55 glutSwapBuffers();
56}
57
58
59static void Reshape( int width, int height )
60{
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 );
68}
69
70
71static void Key( unsigned char key, int x, int y )
72{
73 (void) x;
74 (void) y;
75 switch (key) {
76 case 27:
77 exit(0);
78 break;
79 }
80 glutPostRedisplay();
81}
82
83
84static void SpecialKey( int key, int x, int y )
85{
86 float step = 3.0;
87 (void) x;
88 (void) y;
89
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;
103 }
104 glutPostRedisplay();
105}
106
107
108#define CLAMP( X, MIN, MAX ) ( (X)<(MIN) ? (MIN) : ((X)>(MAX) ? (MAX) : (X)) )
109
Keith Whitwelleea72ff2003-05-20 08:50:02 +0000110
111
112/* #define LINEAR_FILTER */
113
114static void Init( int argc, char *argv[] )
115{
116 GLuint texObj = 100;
117 const char *file;
118 int error;
119
120 if (!glutExtensionSupported("GL_MESA_ycbcr_texture")) {
121 printf("Sorry, GL_MESA_ycbcr_texture is required\n");
122 exit(0);
123 }
124
125 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
126
127 glBindTexture(GL_TEXTURE_2D, texObj);
128 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
129 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
130
131 if (argc > 1)
132 file = argv[1];
133 else
134 file = TEXTURE_FILE;
135
Keith Whitwell27358a22003-05-20 09:54:58 +0000136 ImageYUV = LoadYUVImage(file, &ImgWidth, &ImgHeight );
Keith Whitwelleea72ff2003-05-20 08:50:02 +0000137 if (!ImageYUV) {
138 printf("Couldn't read %s\n", TEXTURE_FILE);
139 exit(0);
140 }
141
142 printf("Image: %dx%d\n", ImgWidth, ImgHeight);
143
Keith Whitwelleea72ff2003-05-20 08:50:02 +0000144
Keith Whitwelleea72ff2003-05-20 08:50:02 +0000145 glTexImage2D(GL_TEXTURE_2D, 0,
146 GL_YCBCR_MESA,
147 ImgWidth, ImgHeight, 0,
148 GL_YCBCR_MESA,
149 GL_UNSIGNED_SHORT_8_8_MESA, ImageYUV);
Keith Whitwelleea72ff2003-05-20 08:50:02 +0000150
151 glEnable(GL_TEXTURE_2D);
152
153 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
154
155
156 glShadeModel(GL_FLAT);
157 glClearColor(0.3, 0.3, 0.4, 1.0);
158
159 if (argc > 1 && strcmp(argv[1], "-info")==0) {
160 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
161 printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
162 printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
163 printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
164 }
165}
166
167
168int main( int argc, char *argv[] )
169{
170 glutInit( &argc, argv );
171 glutInitWindowSize( 300, 300 );
172 glutInitWindowPosition( 0, 0 );
173 glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
174 glutCreateWindow(argv[0] );
175
176 Init( argc, argv );
177
178 glutReshapeFunc( Reshape );
179 glutKeyboardFunc( Key );
180 glutSpecialFunc( SpecialKey );
181 glutDisplayFunc( Display );
182
183 glutMainLoop();
184 return 0;
185}