1 /* $Id: multiarb.c,v 1.8 2000/12/24 22:53:54 pesco 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.8 2000/12/24 22:53:54 pesco
16 * * demos/Makefile.am (INCLUDES): Added -I$(top_srcdir)/util.
17 * * demos/Makefile.X11, demos/Makefile.BeOS-R4, demos/Makefile.cygnus:
18 * Essentially the same.
19 * Program files updated to include "readtex.c", not "../util/readtex.c".
20 * * demos/reflect.c: Likewise for "showbuffer.c".
23 * * Makefile.am (EXTRA_DIST): Added top-level regular files.
25 * * include/GL/Makefile.am (INC_X11): Added glxext.h.
28 * * src/GGI/include/ggi/mesa/Makefile.am (EXTRA_HEADERS): Include
29 * Mesa GGI headers in dist even if HAVE_GGI is not given.
31 * * configure.in: Look for GLUT and demo source dirs in $srcdir.
33 * * src/swrast/Makefile.am (libMesaSwrast_la_SOURCES): Set to *.[ch].
34 * More source list updates in various Makefile.am's.
36 * * Makefile.am (dist-hook): Remove CVS directory from distribution.
37 * (DIST_SUBDIRS): List all possible subdirs here.
38 * (SUBDIRS): Only list subdirs selected for build again.
39 * The above two applied to all subdir Makefile.am's also.
41 * Revision 1.7 2000/11/01 16:02:01 brianp
42 * print number of texture units
44 * Revision 1.6 2000/05/23 23:21:00 brianp
45 * set default window pos
47 * Revision 1.5 2000/02/02 17:31:45 brianp
50 * Revision 1.4 2000/02/02 01:07:21 brianp
51 * limit Drift to [0, 1]
53 * Revision 1.3 1999/10/21 16:40:32 brianp
54 * added -info command line option
56 * Revision 1.2 1999/10/13 12:02:13 brianp
57 * use texture objects now
59 * Revision 1.1.1.1 1999/08/19 00:55:40 jtg
62 * Revision 1.3 1999/03/28 18:20:49 brianp
65 * Revision 1.2 1998/11/05 04:34:04 brianp
66 * moved image files to ../images/ directory
68 * Revision 1.1 1998/11/03 01:36:33 brianp
80 #include "readtex.c" /* I know, this is a hack. */
82 #define TEXTURE_1_FILE "../images/girl.rgb"
83 #define TEXTURE_2_FILE "../images/reflect.rgb"
91 static GLboolean Animate
= GL_TRUE
;
93 static GLfloat Drift
= 0.0;
94 static GLfloat Xrot
= 20.0, Yrot
= 30.0, Zrot
= 0.0;
98 static void Idle( void )
105 #ifdef GL_ARB_multitexture
106 glActiveTextureARB(GL_TEXTURE0_ARB
);
108 glMatrixMode(GL_TEXTURE
);
110 glTranslatef(Drift
, 0.0, 0.0);
111 glMatrixMode(GL_MODELVIEW
);
113 #ifdef GL_ARB_multitexture
114 glActiveTextureARB(GL_TEXTURE1_ARB
);
116 glMatrixMode(GL_TEXTURE
);
118 glTranslatef(0.0, Drift
, 0.0);
119 glMatrixMode(GL_MODELVIEW
);
126 static void DrawObject(void)
130 #ifdef GL_ARB_multitexture
131 glMultiTexCoord2fARB(GL_TEXTURE0_ARB
, 0.0, 0.0);
132 glMultiTexCoord2fARB(GL_TEXTURE1_ARB
, 0.0, 0.0);
133 glVertex2f(-1.0, -1.0);
135 glMultiTexCoord2fARB(GL_TEXTURE0_ARB
, 2.0, 0.0);
136 glMultiTexCoord2fARB(GL_TEXTURE1_ARB
, 1.0, 0.0);
137 glVertex2f(1.0, -1.0);
139 glMultiTexCoord2fARB(GL_TEXTURE0_ARB
, 2.0, 2.0);
140 glMultiTexCoord2fARB(GL_TEXTURE1_ARB
, 1.0, 1.0);
141 glVertex2f(1.0, 1.0);
143 glMultiTexCoord2fARB(GL_TEXTURE0_ARB
, 0.0, 2.0);
144 glMultiTexCoord2fARB(GL_TEXTURE1_ARB
, 0.0, 1.0);
145 glVertex2f(-1.0, 1.0);
147 glTexCoord2f(0.0, 0.0);
148 glVertex2f(-1.0, -1.0);
150 glTexCoord2f(1.0, 0.0);
151 glVertex2f(1.0, -1.0);
153 glTexCoord2f(1.0, 1.0);
154 glVertex2f(1.0, 1.0);
156 glTexCoord2f(0.0, 1.0);
157 glVertex2f(-1.0, 1.0);
165 static void Display( void )
167 glClear( GL_COLOR_BUFFER_BIT
);
170 glRotatef(Xrot
, 1.0, 0.0, 0.0);
171 glRotatef(Yrot
, 0.0, 1.0, 0.0);
172 glRotatef(Zrot
, 0.0, 0.0, 1.0);
173 glScalef(5.0, 5.0, 5.0);
181 static void Reshape( int width
, int height
)
183 glViewport( 0, 0, width
, height
);
184 glMatrixMode( GL_PROJECTION
);
186 glFrustum( -1.0, 1.0, -1.0, 1.0, 10.0, 100.0 );
187 /*glOrtho( -6.0, 6.0, -6.0, 6.0, 10.0, 100.0 );*/
188 glMatrixMode( GL_MODELVIEW
);
190 glTranslatef( 0.0, 0.0, -70.0 );
194 static void ModeMenu(int entry
)
196 GLboolean enable0
= GL_FALSE
, enable1
= GL_FALSE
;
200 else if (entry
==TEX1
) {
203 else if (entry
==TEXBOTH
) {
207 else if (entry
==ANIMATE
) {
210 else if (entry
==QUIT
) {
214 if (entry
!= ANIMATE
) {
215 #ifdef GL_ARB_multitexture
216 glActiveTextureARB(GL_TEXTURE0_ARB
);
219 glEnable(GL_TEXTURE_2D
);
222 glDisable(GL_TEXTURE_2D
);
224 #ifdef GL_ARB_multitexture
225 glActiveTextureARB(GL_TEXTURE1_ARB
);
228 glEnable(GL_TEXTURE_2D
);
231 glDisable(GL_TEXTURE_2D
);
238 static void Key( unsigned char key
, int x
, int y
)
251 static void SpecialKey( int key
, int x
, int y
)
275 static void Init( int argc
, char *argv
[] )
280 const char *exten
= (const char *) glGetString(GL_EXTENSIONS
);
281 if (!strstr(exten
, "GL_ARB_multitexture")) {
282 printf("Sorry, GL_ARB_multitexture not supported by this renderer.\n");
286 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB
, &units
);
287 printf("%d texture units supported\n", units
);
289 /* allocate two texture objects */
290 glGenTextures(2, texObj
);
292 /* setup texture obj 0 */
293 glBindTexture(GL_TEXTURE_2D
, texObj
[0]);
295 /* linear filtering looks much nicer but is much slower for Mesa */
296 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
297 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
299 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
300 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
303 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_MODULATE
);
305 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
307 if (!LoadRGBMipmaps(TEXTURE_1_FILE
, GL_RGB
)) {
308 printf("Error: couldn't load texture image\n");
313 /* setup texture obj 1 */
314 glBindTexture(GL_TEXTURE_2D
, texObj
[1]);
316 /* linear filtering looks much nicer but is much slower for Mesa */
317 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
318 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
320 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
321 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
324 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_MODULATE
);
326 if (!LoadRGBMipmaps(TEXTURE_2_FILE
, GL_RGB
)) {
327 printf("Error: couldn't load texture image\n");
332 /* now bind the texture objects to the respective texture units */
333 #ifdef GL_ARB_multitexture
334 glActiveTextureARB(GL_TEXTURE0_ARB
);
335 glBindTexture(GL_TEXTURE_2D
, texObj
[0]);
336 glActiveTextureARB(GL_TEXTURE1_ARB
);
337 glBindTexture(GL_TEXTURE_2D
, texObj
[1]);
340 glShadeModel(GL_FLAT
);
341 glClearColor(0.3, 0.3, 0.4, 1.0);
345 if (argc
> 1 && strcmp(argv
[1], "-info")==0) {
346 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
347 printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION
));
348 printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR
));
349 printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS
));
354 int main( int argc
, char *argv
[] )
356 glutInit( &argc
, argv
);
357 glutInitWindowSize( 300, 300 );
358 glutInitWindowPosition( 0, 0 );
359 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
);
360 glutCreateWindow(argv
[0] );
364 glutReshapeFunc( Reshape
);
365 glutKeyboardFunc( Key
);
366 glutSpecialFunc( SpecialKey
);
367 glutDisplayFunc( Display
);
368 glutIdleFunc( Idle
);
370 glutCreateMenu(ModeMenu
);
371 glutAddMenuEntry("Texture 0", TEX0
);
372 glutAddMenuEntry("Texture 1", TEX1
);
373 glutAddMenuEntry("Multi-texture", TEXBOTH
);
374 glutAddMenuEntry("Toggle Animation", ANIMATE
);
375 glutAddMenuEntry("Quit", QUIT
);
376 glutAttachMenu(GLUT_RIGHT_BUTTON
);