2 /* GL_NV_texture_rectangle test
14 #include "glut_wrap.h"
17 #define TEXTURE_0_FILE DEMOS_DATA_DIR "girl.rgb"
18 #define TEXTURE_1_FILE DEMOS_DATA_DIR "reflect.rgb"
24 #define CLAMP_TO_EDGE 21
25 #define CLAMP_TO_BORDER 22
26 #define LINEAR_FILTER 30
27 #define NEAREST_FILTER 31
30 static GLboolean Animate
= GL_FALSE
;
31 static GLint NumUnits
= 2;
32 static GLboolean TexEnabled
[8];
33 static GLint Width
[8], Height
[8]; /* image sizes */
34 static GLenum Format
[8];
36 static GLfloat Xrot
= 00.0, Yrot
= 00.0, Zrot
= 0.0;
39 static void Idle( void )
41 Zrot
= glutGet(GLUT_ELAPSED_TIME
) * 0.01;
46 static void DrawObject(void)
49 GLfloat d
= 10; /* so we can see how borders are handled */
51 glColor3f(.1, .1, .1); /* modulate this */
55 glRotatef(Zrot
, 0, 0, 1);
59 for (i
= 0; i
< NumUnits
; i
++)
60 glMultiTexCoord2fARB(GL_TEXTURE0_ARB
+ i
, -d
, -d
);
61 glVertex2f(-1.0, -1.0);
63 for (i
= 0; i
< NumUnits
; i
++)
64 glMultiTexCoord2fARB(GL_TEXTURE0_ARB
+ i
, Width
[i
]+d
, -d
);
65 glVertex2f(1.0, -1.0);
67 for (i
= 0; i
< NumUnits
; i
++)
68 glMultiTexCoord2fARB(GL_TEXTURE0_ARB
+ i
, Width
[i
]+d
, Height
[i
]+d
);
71 for (i
= 0; i
< NumUnits
; i
++)
72 glMultiTexCoord2fARB(GL_TEXTURE0_ARB
+ i
, -d
, Height
[i
]+d
);
73 glVertex2f(-1.0, 1.0);
80 static void Display( void )
82 glClear( GL_COLOR_BUFFER_BIT
);
85 glRotatef(Xrot
, 1.0, 0.0, 0.0);
86 glRotatef(Yrot
, 0.0, 1.0, 0.0);
87 glRotatef(Zrot
, 0.0, 0.0, 1.0);
88 glScalef(5.0, 5.0, 5.0);
96 static void Reshape( int width
, int height
)
98 glViewport( 0, 0, width
, height
);
99 glMatrixMode( GL_PROJECTION
);
101 glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 100.0 );
102 glMatrixMode( GL_MODELVIEW
);
104 glTranslatef( 0.0, 0.0, -35.0 );
108 static void ModeMenu(int entry
)
111 if (entry
>= TEX0
&& entry
< TEX0
+ NumUnits
) {
114 TexEnabled
[i
] = !TexEnabled
[i
];
115 glActiveTextureARB(GL_TEXTURE0_ARB
+ i
);
117 glEnable(GL_TEXTURE_RECTANGLE_NV
);
120 glDisable(GL_TEXTURE_RECTANGLE_NV
);
123 for (i
= 0; i
< NumUnits
; i
++)
124 printf("%d ", (int) TexEnabled
[i
]);
127 else if (entry
==ANIMATE
) {
134 else if (entry
==CLAMP
) {
135 for (i
= 0; i
< NumUnits
; i
++) {
136 glActiveTextureARB(GL_TEXTURE0_ARB
+ i
);
137 glTexParameteri(GL_TEXTURE_RECTANGLE_NV
, GL_TEXTURE_WRAP_S
, GL_CLAMP
);
138 glTexParameteri(GL_TEXTURE_RECTANGLE_NV
, GL_TEXTURE_WRAP_T
, GL_CLAMP
);
141 else if (entry
==CLAMP_TO_EDGE
) {
142 for (i
= 0; i
< NumUnits
; i
++) {
143 glActiveTextureARB(GL_TEXTURE0_ARB
+ i
);
144 glTexParameteri(GL_TEXTURE_RECTANGLE_NV
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
145 glTexParameteri(GL_TEXTURE_RECTANGLE_NV
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
148 else if (entry
==CLAMP_TO_BORDER
) {
149 for (i
= 0; i
< NumUnits
; i
++) {
150 glActiveTextureARB(GL_TEXTURE0_ARB
+ i
);
151 glTexParameteri(GL_TEXTURE_RECTANGLE_NV
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_BORDER
);
152 glTexParameteri(GL_TEXTURE_RECTANGLE_NV
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_BORDER
);
155 else if (entry
==NEAREST_FILTER
) {
156 for (i
= 0; i
< NumUnits
; i
++) {
157 glActiveTextureARB(GL_TEXTURE0_ARB
+ i
);
158 glTexParameteri(GL_TEXTURE_RECTANGLE_NV
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
159 glTexParameteri(GL_TEXTURE_RECTANGLE_NV
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
162 else if (entry
==LINEAR_FILTER
) {
163 for (i
= 0; i
< NumUnits
; i
++) {
164 glActiveTextureARB(GL_TEXTURE0_ARB
+ i
);
165 glTexParameteri(GL_TEXTURE_RECTANGLE_NV
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
166 glTexParameteri(GL_TEXTURE_RECTANGLE_NV
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
170 else if (entry
==QUIT
) {
178 static void Key( unsigned char key
, int x
, int y
)
204 static void SpecialKey( int key
, int x
, int y
)
228 static void Init( int argc
, char *argv
[] )
230 const GLenum wrap
= GL_CLAMP
;
234 if (!glutExtensionSupported("GL_ARB_multitexture")) {
235 printf("Sorry, GL_ARB_multitexture needed by this program\n");
239 if (!glutExtensionSupported("GL_NV_texture_rectangle")) {
240 printf("Sorry, GL_NV_texture_rectangle needed by this program\n");
244 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB
, &NumUnits
);
245 printf("%d texture units supported, using 2.\n", NumUnits
);
249 glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE_NV
, &size
);
250 printf("%d x %d max texture rectangle size\n", size
, size
);
252 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
254 for (i
= 0; i
< NumUnits
; i
++) {
255 TexEnabled
[i
] = GL_TRUE
;
258 /* allocate two texture objects */
259 glGenTextures(NumUnits
, texObj
);
261 /* setup the texture objects */
262 for (i
= 0; i
< NumUnits
; i
++) {
264 glActiveTextureARB(GL_TEXTURE0_ARB
+ i
);
266 glBindTexture(GL_TEXTURE_RECTANGLE_NV
, texObj
[i
]);
267 glTexParameteri(GL_TEXTURE_RECTANGLE_NV
,
268 GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
269 glTexParameteri(GL_TEXTURE_RECTANGLE_NV
,
270 GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
271 glTexParameteri(GL_TEXTURE_RECTANGLE_NV
, GL_TEXTURE_WRAP_S
, wrap
);
272 glTexParameteri(GL_TEXTURE_RECTANGLE_NV
, GL_TEXTURE_WRAP_T
, wrap
);
275 GLubyte
*img
= LoadRGBImage(TEXTURE_0_FILE
, &Width
[0], &Height
[0],
278 printf("Error: couldn't load texture image\n");
281 printf("Texture %d: %s (%d x %d)\n", i
,
282 TEXTURE_0_FILE
, Width
[0], Height
[0]);
283 glTexImage2D(GL_TEXTURE_RECTANGLE_NV
, 0, GL_RGB
,
284 Width
[0], Height
[0], 0,
285 Format
[0], GL_UNSIGNED_BYTE
, img
);
288 GLubyte
*img
= LoadRGBImage(TEXTURE_1_FILE
, &Width
[1], &Height
[1],
291 printf("Error: couldn't load texture image\n");
294 printf("Texture %d: %s (%d x %d)\n", i
,
295 TEXTURE_1_FILE
, Width
[1], Height
[1]);
296 glTexImage2D(GL_TEXTURE_RECTANGLE_NV
, 0, GL_RGB
,
297 Width
[1], Height
[1], 0,
298 Format
[1], GL_UNSIGNED_BYTE
, img
);
302 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_ADD
);
304 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_ADD
);
307 glEnable(GL_TEXTURE_RECTANGLE_NV
);
310 glShadeModel(GL_FLAT
);
311 glClearColor(0.3, 0.3, 0.4, 1.0);
313 if (argc
> 1 && strcmp(argv
[1], "-info")==0) {
314 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
315 printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION
));
316 printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR
));
317 printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS
));
322 int main( int argc
, char *argv
[] )
326 glutInit( &argc
, argv
);
327 glutInitWindowSize( 300, 300 );
328 glutInitWindowPosition( 0, 0 );
329 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
);
330 glutCreateWindow(argv
[0] );
335 glutReshapeFunc( Reshape
);
336 glutKeyboardFunc( Key
);
337 glutSpecialFunc( SpecialKey
);
338 glutDisplayFunc( Display
);
340 glutIdleFunc( Idle
);
342 glutCreateMenu(ModeMenu
);
344 for (i
= 0; i
< NumUnits
; i
++) {
346 sprintf(s
, "Toggle Texture %d", i
);
347 glutAddMenuEntry(s
, TEX0
+ i
);
349 glutAddMenuEntry("Toggle Animation", ANIMATE
);
350 glutAddMenuEntry("GL_CLAMP", CLAMP
);
351 glutAddMenuEntry("GL_CLAMP_TO_EDGE", CLAMP_TO_EDGE
);
352 glutAddMenuEntry("GL_CLAMP_TO_BORDER", CLAMP_TO_BORDER
);
353 glutAddMenuEntry("GL_NEAREST", NEAREST_FILTER
);
354 glutAddMenuEntry("GL_LINEAR", LINEAR_FILTER
);
355 glutAddMenuEntry("Quit", QUIT
);
356 glutAttachMenu(GLUT_RIGHT_BUTTON
);