1 /* $Id: multiarb.c,v 1.10 2001/06/20 19:12:30 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.10 2001/06/20 19:12:30 brianp
16 * also print GL_MAX_TEXTURE_SIZE
18 * Revision 1.9 2001/06/13 14:33:16 brianp
19 * moved glTexEnvi calls to better logical locations
21 * Revision 1.8 2000/12/24 22:53:54 pesco
22 * * demos/Makefile.am (INCLUDES): Added -I$(top_srcdir)/util.
23 * * demos/Makefile.X11, demos/Makefile.BeOS-R4, demos/Makefile.cygnus:
24 * Essentially the same.
25 * Program files updated to include "readtex.c", not "../util/readtex.c".
26 * * demos/reflect.c: Likewise for "showbuffer.c".
29 * * Makefile.am (EXTRA_DIST): Added top-level regular files.
31 * * include/GL/Makefile.am (INC_X11): Added glxext.h.
34 * * src/GGI/include/ggi/mesa/Makefile.am (EXTRA_HEADERS): Include
35 * Mesa GGI headers in dist even if HAVE_GGI is not given.
37 * * configure.in: Look for GLUT and demo source dirs in $srcdir.
39 * * src/swrast/Makefile.am (libMesaSwrast_la_SOURCES): Set to *.[ch].
40 * More source list updates in various Makefile.am's.
42 * * Makefile.am (dist-hook): Remove CVS directory from distribution.
43 * (DIST_SUBDIRS): List all possible subdirs here.
44 * (SUBDIRS): Only list subdirs selected for build again.
45 * The above two applied to all subdir Makefile.am's also.
47 * Revision 1.7 2000/11/01 16:02:01 brianp
48 * print number of texture units
50 * Revision 1.6 2000/05/23 23:21:00 brianp
51 * set default window pos
53 * Revision 1.5 2000/02/02 17:31:45 brianp
56 * Revision 1.4 2000/02/02 01:07:21 brianp
57 * limit Drift to [0, 1]
59 * Revision 1.3 1999/10/21 16:40:32 brianp
60 * added -info command line option
62 * Revision 1.2 1999/10/13 12:02:13 brianp
63 * use texture objects now
65 * Revision 1.1.1.1 1999/08/19 00:55:40 jtg
68 * Revision 1.3 1999/03/28 18:20:49 brianp
71 * Revision 1.2 1998/11/05 04:34:04 brianp
72 * moved image files to ../images/ directory
74 * Revision 1.1 1998/11/03 01:36:33 brianp
86 #include "readtex.c" /* I know, this is a hack. */
88 #define TEXTURE_1_FILE "../images/girl.rgb"
89 #define TEXTURE_2_FILE "../images/reflect.rgb"
97 static GLboolean Animate
= GL_TRUE
;
99 static GLfloat Drift
= 0.0;
100 static GLfloat Xrot
= 20.0, Yrot
= 30.0, Zrot
= 0.0;
104 static void Idle( void )
111 #ifdef GL_ARB_multitexture
112 glActiveTextureARB(GL_TEXTURE0_ARB
);
114 glMatrixMode(GL_TEXTURE
);
116 glTranslatef(Drift
, 0.0, 0.0);
117 glMatrixMode(GL_MODELVIEW
);
119 #ifdef GL_ARB_multitexture
120 glActiveTextureARB(GL_TEXTURE1_ARB
);
122 glMatrixMode(GL_TEXTURE
);
124 glTranslatef(0.0, Drift
, 0.0);
125 glMatrixMode(GL_MODELVIEW
);
132 static void DrawObject(void)
136 #ifdef GL_ARB_multitexture
137 glMultiTexCoord2fARB(GL_TEXTURE0_ARB
, 0.0, 0.0);
138 glMultiTexCoord2fARB(GL_TEXTURE1_ARB
, 0.0, 0.0);
139 glVertex2f(-1.0, -1.0);
141 glMultiTexCoord2fARB(GL_TEXTURE0_ARB
, 2.0, 0.0);
142 glMultiTexCoord2fARB(GL_TEXTURE1_ARB
, 1.0, 0.0);
143 glVertex2f(1.0, -1.0);
145 glMultiTexCoord2fARB(GL_TEXTURE0_ARB
, 2.0, 2.0);
146 glMultiTexCoord2fARB(GL_TEXTURE1_ARB
, 1.0, 1.0);
147 glVertex2f(1.0, 1.0);
149 glMultiTexCoord2fARB(GL_TEXTURE0_ARB
, 0.0, 2.0);
150 glMultiTexCoord2fARB(GL_TEXTURE1_ARB
, 0.0, 1.0);
151 glVertex2f(-1.0, 1.0);
153 glTexCoord2f(0.0, 0.0);
154 glVertex2f(-1.0, -1.0);
156 glTexCoord2f(1.0, 0.0);
157 glVertex2f(1.0, -1.0);
159 glTexCoord2f(1.0, 1.0);
160 glVertex2f(1.0, 1.0);
162 glTexCoord2f(0.0, 1.0);
163 glVertex2f(-1.0, 1.0);
171 static void Display( void )
173 glClear( GL_COLOR_BUFFER_BIT
);
176 glRotatef(Xrot
, 1.0, 0.0, 0.0);
177 glRotatef(Yrot
, 0.0, 1.0, 0.0);
178 glRotatef(Zrot
, 0.0, 0.0, 1.0);
179 glScalef(5.0, 5.0, 5.0);
187 static void Reshape( int width
, int height
)
189 glViewport( 0, 0, width
, height
);
190 glMatrixMode( GL_PROJECTION
);
192 glFrustum( -1.0, 1.0, -1.0, 1.0, 10.0, 100.0 );
193 /*glOrtho( -6.0, 6.0, -6.0, 6.0, 10.0, 100.0 );*/
194 glMatrixMode( GL_MODELVIEW
);
196 glTranslatef( 0.0, 0.0, -70.0 );
200 static void ModeMenu(int entry
)
202 GLboolean enable0
= GL_FALSE
, enable1
= GL_FALSE
;
206 else if (entry
==TEX1
) {
209 else if (entry
==TEXBOTH
) {
213 else if (entry
==ANIMATE
) {
216 else if (entry
==QUIT
) {
220 if (entry
!= ANIMATE
) {
221 #ifdef GL_ARB_multitexture
222 glActiveTextureARB(GL_TEXTURE0_ARB
);
225 glEnable(GL_TEXTURE_2D
);
228 glDisable(GL_TEXTURE_2D
);
230 #ifdef GL_ARB_multitexture
231 glActiveTextureARB(GL_TEXTURE1_ARB
);
234 glEnable(GL_TEXTURE_2D
);
237 glDisable(GL_TEXTURE_2D
);
244 static void Key( unsigned char key
, int x
, int y
)
257 static void SpecialKey( int key
, int x
, int y
)
281 static void Init( int argc
, char *argv
[] )
286 const char *exten
= (const char *) glGetString(GL_EXTENSIONS
);
287 if (!strstr(exten
, "GL_ARB_multitexture")) {
288 printf("Sorry, GL_ARB_multitexture not supported by this renderer.\n");
292 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB
, &units
);
293 printf("%d texture units supported\n", units
);
295 glGetIntegerv(GL_MAX_TEXTURE_SIZE
, &size
);
296 printf("%d x %d max texture size\n", size
, size
);
298 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
300 /* allocate two texture objects */
301 glGenTextures(2, texObj
);
303 /* setup texture obj 0 */
304 glBindTexture(GL_TEXTURE_2D
, texObj
[0]);
306 /* linear filtering looks much nicer but is much slower for Mesa */
307 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
308 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
310 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
311 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
313 if (!LoadRGBMipmaps(TEXTURE_1_FILE
, GL_RGB
)) {
314 printf("Error: couldn't load texture image\n");
319 /* setup texture obj 1 */
320 glBindTexture(GL_TEXTURE_2D
, texObj
[1]);
322 /* linear filtering looks much nicer but is much slower for Mesa */
323 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
324 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
326 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
327 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
329 if (!LoadRGBMipmaps(TEXTURE_2_FILE
, GL_RGB
)) {
330 printf("Error: couldn't load texture image\n");
335 /* now bind the texture objects to the respective texture units */
336 #ifdef GL_ARB_multitexture
337 glActiveTextureARB(GL_TEXTURE0_ARB
);
338 glBindTexture(GL_TEXTURE_2D
, texObj
[0]);
339 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_MODULATE
);
340 glActiveTextureARB(GL_TEXTURE1_ARB
);
341 glBindTexture(GL_TEXTURE_2D
, texObj
[1]);
342 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_MODULATE
);
345 glShadeModel(GL_FLAT
);
346 glClearColor(0.3, 0.3, 0.4, 1.0);
350 if (argc
> 1 && strcmp(argv
[1], "-info")==0) {
351 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
352 printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION
));
353 printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR
));
354 printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS
));
359 int main( int argc
, char *argv
[] )
361 glutInit( &argc
, argv
);
362 glutInitWindowSize( 300, 300 );
363 glutInitWindowPosition( 0, 0 );
364 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
);
365 glutCreateWindow(argv
[0] );
369 glutReshapeFunc( Reshape
);
370 glutKeyboardFunc( Key
);
371 glutSpecialFunc( SpecialKey
);
372 glutDisplayFunc( Display
);
373 glutIdleFunc( Idle
);
375 glutCreateMenu(ModeMenu
);
376 glutAddMenuEntry("Texture 0", TEX0
);
377 glutAddMenuEntry("Texture 1", TEX1
);
378 glutAddMenuEntry("Multi-texture", TEXBOTH
);
379 glutAddMenuEntry("Toggle Animation", ANIMATE
);
380 glutAddMenuEntry("Quit", QUIT
);
381 glutAttachMenu(GLUT_RIGHT_BUTTON
);