1 /* $Id: multiarb.c,v 1.6 2000/05/23 23:21:00 brianp Exp $ */
4 * GL_ARB_multitexture demo
6 * Command line options:
7 * -info print GL implementation information
10 * Brian Paul November 1998 This program is in the public domain.
14 * $Log: multiarb.c,v $
15 * Revision 1.6 2000/05/23 23:21:00 brianp
16 * set default window pos
18 * Revision 1.5 2000/02/02 17:31:45 brianp
21 * Revision 1.4 2000/02/02 01:07:21 brianp
22 * limit Drift to [0, 1]
24 * Revision 1.3 1999/10/21 16:40:32 brianp
25 * added -info command line option
27 * Revision 1.2 1999/10/13 12:02:13 brianp
28 * use texture objects now
30 * Revision 1.1.1.1 1999/08/19 00:55:40 jtg
33 * Revision 1.3 1999/03/28 18:20:49 brianp
36 * Revision 1.2 1998/11/05 04:34:04 brianp
37 * moved image files to ../images/ directory
39 * Revision 1.1 1998/11/03 01:36:33 brianp
51 #include "../util/readtex.c" /* I know, this is a hack. */
53 #define TEXTURE_1_FILE "../images/girl.rgb"
54 #define TEXTURE_2_FILE "../images/reflect.rgb"
62 static GLboolean Animate
= GL_TRUE
;
64 static GLfloat Drift
= 0.0;
65 static GLfloat Xrot
= 20.0, Yrot
= 30.0, Zrot
= 0.0;
69 static void Idle( void )
76 #ifdef GL_ARB_multitexture
77 glActiveTextureARB(GL_TEXTURE0_ARB
);
79 glMatrixMode(GL_TEXTURE
);
81 glTranslatef(Drift
, 0.0, 0.0);
82 glMatrixMode(GL_MODELVIEW
);
84 #ifdef GL_ARB_multitexture
85 glActiveTextureARB(GL_TEXTURE1_ARB
);
87 glMatrixMode(GL_TEXTURE
);
89 glTranslatef(0.0, Drift
, 0.0);
90 glMatrixMode(GL_MODELVIEW
);
97 static void DrawObject(void)
101 #ifdef GL_ARB_multitexture
102 glMultiTexCoord2fARB(GL_TEXTURE0_ARB
, 0.0, 0.0);
103 glMultiTexCoord2fARB(GL_TEXTURE1_ARB
, 0.0, 0.0);
104 glVertex2f(-1.0, -1.0);
106 glMultiTexCoord2fARB(GL_TEXTURE0_ARB
, 2.0, 0.0);
107 glMultiTexCoord2fARB(GL_TEXTURE1_ARB
, 1.0, 0.0);
108 glVertex2f(1.0, -1.0);
110 glMultiTexCoord2fARB(GL_TEXTURE0_ARB
, 2.0, 2.0);
111 glMultiTexCoord2fARB(GL_TEXTURE1_ARB
, 1.0, 1.0);
112 glVertex2f(1.0, 1.0);
114 glMultiTexCoord2fARB(GL_TEXTURE0_ARB
, 0.0, 2.0);
115 glMultiTexCoord2fARB(GL_TEXTURE1_ARB
, 0.0, 1.0);
116 glVertex2f(-1.0, 1.0);
118 glTexCoord2f(0.0, 0.0);
119 glVertex2f(-1.0, -1.0);
121 glTexCoord2f(1.0, 0.0);
122 glVertex2f(1.0, -1.0);
124 glTexCoord2f(1.0, 1.0);
125 glVertex2f(1.0, 1.0);
127 glTexCoord2f(0.0, 1.0);
128 glVertex2f(-1.0, 1.0);
136 static void Display( void )
138 glClear( GL_COLOR_BUFFER_BIT
);
141 glRotatef(Xrot
, 1.0, 0.0, 0.0);
142 glRotatef(Yrot
, 0.0, 1.0, 0.0);
143 glRotatef(Zrot
, 0.0, 0.0, 1.0);
144 glScalef(5.0, 5.0, 5.0);
152 static void Reshape( int width
, int height
)
154 glViewport( 0, 0, width
, height
);
155 glMatrixMode( GL_PROJECTION
);
157 glFrustum( -1.0, 1.0, -1.0, 1.0, 10.0, 100.0 );
158 /*glOrtho( -6.0, 6.0, -6.0, 6.0, 10.0, 100.0 );*/
159 glMatrixMode( GL_MODELVIEW
);
161 glTranslatef( 0.0, 0.0, -70.0 );
165 static void ModeMenu(int entry
)
167 GLboolean enable0
= GL_FALSE
, enable1
= GL_FALSE
;
171 else if (entry
==TEX1
) {
174 else if (entry
==TEXBOTH
) {
178 else if (entry
==ANIMATE
) {
181 else if (entry
==QUIT
) {
185 if (entry
!= ANIMATE
) {
186 #ifdef GL_ARB_multitexture
187 glActiveTextureARB(GL_TEXTURE0_ARB
);
190 glEnable(GL_TEXTURE_2D
);
193 glDisable(GL_TEXTURE_2D
);
195 #ifdef GL_ARB_multitexture
196 glActiveTextureARB(GL_TEXTURE1_ARB
);
199 glEnable(GL_TEXTURE_2D
);
202 glDisable(GL_TEXTURE_2D
);
209 static void Key( unsigned char key
, int x
, int y
)
222 static void SpecialKey( int key
, int x
, int y
)
246 static void Init( int argc
, char *argv
[] )
250 const char *exten
= (const char *) glGetString(GL_EXTENSIONS
);
251 if (!strstr(exten
, "GL_ARB_multitexture")) {
252 printf("Sorry, GL_ARB_multitexture not supported by this renderer.\n");
256 /* allocate two texture objects */
257 glGenTextures(2, texObj
);
259 /* setup texture obj 0 */
260 glBindTexture(GL_TEXTURE_2D
, texObj
[0]);
262 /* linear filtering looks much nicer but is much slower for Mesa */
263 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
264 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
266 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
267 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
270 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_MODULATE
);
272 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
274 if (!LoadRGBMipmaps(TEXTURE_1_FILE
, GL_RGB
)) {
275 printf("Error: couldn't load texture image\n");
280 /* setup texture obj 1 */
281 glBindTexture(GL_TEXTURE_2D
, texObj
[1]);
283 /* linear filtering looks much nicer but is much slower for Mesa */
284 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
285 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
287 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
288 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
291 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_MODULATE
);
293 if (!LoadRGBMipmaps(TEXTURE_2_FILE
, GL_RGB
)) {
294 printf("Error: couldn't load texture image\n");
299 /* now bind the texture objects to the respective texture units */
300 #ifdef GL_ARB_multitexture
301 glActiveTextureARB(GL_TEXTURE0_ARB
);
302 glBindTexture(GL_TEXTURE_2D
, texObj
[0]);
303 glActiveTextureARB(GL_TEXTURE1_ARB
);
304 glBindTexture(GL_TEXTURE_2D
, texObj
[1]);
307 glShadeModel(GL_FLAT
);
308 glClearColor(0.3, 0.3, 0.4, 1.0);
312 if (argc
> 1 && strcmp(argv
[1], "-info")==0) {
313 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
314 printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION
));
315 printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR
));
316 printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS
));
321 int main( int argc
, char *argv
[] )
323 glutInit( &argc
, argv
);
324 glutInitWindowSize( 300, 300 );
325 glutInitWindowPosition( 0, 0 );
326 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
);
327 glutCreateWindow(argv
[0] );
331 glutReshapeFunc( Reshape
);
332 glutKeyboardFunc( Key
);
333 glutSpecialFunc( SpecialKey
);
334 glutDisplayFunc( Display
);
335 glutIdleFunc( Idle
);
337 glutCreateMenu(ModeMenu
);
338 glutAddMenuEntry("Texture 0", TEX0
);
339 glutAddMenuEntry("Texture 1", TEX1
);
340 glutAddMenuEntry("Multi-texture", TEXBOTH
);
341 glutAddMenuEntry("Toggle Animation", ANIMATE
);
342 glutAddMenuEntry("Quit", QUIT
);
343 glutAttachMenu(GLUT_RIGHT_BUTTON
);