2 * Textured cylinder demo: lighting, texturing, reflection mapping.
4 * Brian Paul May 1997 This program is in the public domain.
6 * Conversion to UGL/Mesa by Stephane Raimbault
10 * Revision 1.2 2001/09/10 19:21:13 brianp
11 * WindML updates (Stephane Raimbault)
13 * Revision 1.1 2001/08/20 16:07:11 brianp
14 * WindML driver (Stephane Raimbault)
16 * Revision 1.5 2001/03/27 17:35:26 brianp
17 * set initial window pos
19 * Revision 1.4 2000/12/24 22:53:54 pesco
20 * * demos/Makefile.am (INCLUDES): Added -I$(top_srcdir)/util.
21 * * demos/Makefile.X11, demos/Makefile.BeOS-R4, demos/Makefile.cygnus:
22 * Essentially the same.
23 * Program files updated to include "readtex.c", not "../util/readtex.c".
24 * * demos/reflect.c: Likewise for "showbuffer.c".
27 * * Makefile.am (EXTRA_DIST): Added top-level regular files.
29 * * include/GL/Makefile.am (INC_X11): Added glxext.h.
32 * * src/GGI/include/ggi/mesa/Makefile.am (EXTRA_HEADERS): Include
33 * Mesa GGI headers in dist even if HAVE_GGI is not given.
35 * * configure.in: Look for GLUT and demo source dirs in $srcdir.
37 * * src/swrast/Makefile.am (libMesaSwrast_la_SOURCES): Set to *.[ch].
38 * More source list updates in various Makefile.am's.
40 * * Makefile.am (dist-hook): Remove CVS directory from distribution.
41 * (DIST_SUBDIRS): List all possible subdirs here.
42 * (SUBDIRS): Only list subdirs selected for build again.
43 * The above two applied to all subdir Makefile.am's also.
45 * Revision 1.3 2000/09/29 23:09:39 brianp
48 * Revision 1.2 1999/10/21 16:39:06 brianp
49 * added -info command line option
51 * Revision 1.1.1.1 1999/08/19 00:55:40 jtg
54 * Revision 3.3 1999/03/28 18:24:37 brianp
57 * Revision 3.2 1998/11/05 04:34:04 brianp
58 * moved image files to ../images/ directory
60 * Revision 3.1 1998/06/23 03:16:51 brianp
61 * added Point/Linear sampling menu items
63 * Revision 3.0 1998/02/14 18:42:29 brianp
75 #include <ugl/uglucode.h>
76 #include <ugl/uglevent.h>
77 #include <ugl/uglinput.h>
79 #include <GL/uglmesa.h>
82 #include "../util/readtex.h"
84 #define TEXTURE_FILE "Mesa/images/reflect.rgb"
90 #define POINT_FILTER 20
91 #define LINEAR_FILTER 21
95 UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId
;
96 UGL_LOCAL UGL_EVENT_Q_ID qId
;
97 UGL_LOCAL
volatile UGL_BOOL stopWex
;
98 UGL_LOCAL UGL_MESA_CONTEXT umc
;
100 UGL_LOCAL GLuint CylinderObj
;
101 UGL_LOCAL GLboolean Animate
;
102 UGL_LOCAL GLboolean linearFilter
;
104 UGL_LOCAL GLfloat Xrot
, Yrot
, Zrot
;
105 UGL_LOCAL GLfloat DXrot
, DYrot
;
107 UGL_LOCAL GLuint limit
;
108 UGL_LOCAL GLuint count
;
109 UGL_LOCAL GLuint tickStart
, tickStop
, tickBySec
;
111 UGL_LOCAL
void cleanUp (void);
113 UGL_LOCAL
void drawGL(void)
119 glClear( GL_COLOR_BUFFER_BIT
);
122 glRotatef(Xrot
, 1.0, 0.0, 0.0);
123 glRotatef(Yrot
, 0.0, 1.0, 0.0);
124 glRotatef(Zrot
, 0.0, 0.0, 1.0);
125 glScalef(5.0, 5.0, 5.0);
126 glCallList(CylinderObj
);
130 uglMesaSwapBuffers();
141 tickStop
= tickGet ();
142 time
= (tickStop
-tickStart
)/tickBySec
;
143 printf (" %i fps\n", count
/time
);
144 tickStart
= tickStop
;
153 UGL_LOCAL
void echoUse(void)
156 printf(" Up/Down Rotate on Y\n");
157 printf(" Left/Right Rotate on X\n");
158 printf(" a Toggle animation\n");
159 printf(" f Toggle point/linear filtered\n");
161 printf(" t Textured\n");
162 printf(" r Reflect\n");
163 printf(" ESC Exit\n");
166 UGL_LOCAL
void readKey(UGL_WCHAR key
)
177 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
,
179 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
,
184 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
,
186 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
,
189 linearFilter
= !linearFilter
;
192 glEnable(GL_LIGHTING
);
193 glDisable(GL_TEXTURE_2D
);
194 glDisable(GL_TEXTURE_GEN_S
);
195 glDisable(GL_TEXTURE_GEN_T
);
198 glDisable(GL_LIGHTING
);
199 glEnable(GL_TEXTURE_2D
);
200 glDisable(GL_TEXTURE_GEN_S
);
201 glDisable(GL_TEXTURE_GEN_T
);
204 glDisable(GL_LIGHTING
);
205 glEnable(GL_TEXTURE_2D
);
206 glEnable(GL_TEXTURE_GEN_S
);
207 glEnable(GL_TEXTURE_GEN_T
);
209 case UGL_UNI_UP_ARROW
:
212 case UGL_UNI_DOWN_ARROW
:
215 case UGL_UNI_LEFT_ARROW
:
218 case UGL_UNI_RIGHT_ARROW
:
227 UGL_LOCAL
void loopEvent(void)
230 UGL_INPUT_EVENT
* pInputEvent
;
234 if (uglEventGet (qId
, &event
, sizeof (event
), UGL_NO_WAIT
)
235 != UGL_STATUS_Q_EMPTY
)
237 pInputEvent
= (UGL_INPUT_EVENT
*)&event
;
239 if (pInputEvent
->header
.type
== UGL_EVENT_TYPE_KEYBOARD
&&
240 pInputEvent
->modifiers
& UGL_KEYBOARD_KEYDOWN
)
241 readKey(pInputEvent
->type
.keyboard
.key
);
250 UGL_LOCAL
void initGL(void)
252 GLUquadricObj
*q
= gluNewQuadric();
253 CylinderObj
= glGenLists(1);
254 glNewList(CylinderObj
, GL_COMPILE
);
256 glTranslatef(0.0, 0.0, -1.0);
259 gluQuadricNormals(q
, GL_SMOOTH
);
260 gluQuadricTexture(q
, GL_TRUE
);
261 gluCylinder(q
, 0.6, 0.6, 2.0, 24, 1);
264 glTranslatef(0.0, 0.0, 2.0);
265 gluDisk(q
, 0.0, 0.6, 24, 1);
268 glTranslatef(0.0, 0.0, -2.0);
269 gluQuadricOrientation(q
, GLU_INSIDE
);
270 gluDisk(q
, 0.0, 0.6, 24, 1);
276 glEnable(GL_LIGHTING
);
278 GLfloat gray
[4] = {0.2, 0.2, 0.2, 1.0};
279 GLfloat white
[4] = {1.0, 1.0, 1.0, 1.0};
280 GLfloat teal
[4] = { 0.0, 1.0, 0.8, 1.0 };
281 glMaterialfv(GL_FRONT
, GL_DIFFUSE
, teal
);
282 glLightfv(GL_LIGHT0
, GL_AMBIENT
, gray
);
283 glLightfv(GL_LIGHT0
, GL_DIFFUSE
, white
);
287 /* fitering = nearest, initially */
288 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
289 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
291 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_DECAL
);
292 glHint(GL_PERSPECTIVE_CORRECTION_HINT
, GL_FASTEST
);
294 glTexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, GL_SPHERE_MAP
);
295 glTexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, GL_SPHERE_MAP
);
297 if (!LoadRGBMipmaps(TEXTURE_FILE
, GL_RGB
))
299 printf("Error: couldn't load texture image\n");
304 glEnable(GL_CULL_FACE
); /* don't need Z testing for convex objects */
306 glEnable(GL_LIGHTING
);
308 glMatrixMode( GL_PROJECTION
);
310 glFrustum( -1.0, 1.0, -1.0, 1.0, 10.0, 100.0 );
311 glMatrixMode( GL_MODELVIEW
);
313 glTranslatef( 0.0, 0.0, -70.0 );
315 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
316 printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION
));
317 printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR
));
318 printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS
));
321 tickStart
= tickGet ();
322 tickBySec
= sysClkRateGet ();
327 UGL_LOCAL
void cleanUp (void)
329 uglEventQDestroy (eventServiceId
, qId
);
331 uglMesaDestroyContext();
335 void windMLTexCyl (UGL_BOOL windMLMode
);
337 void ugltexcyl (void)
339 taskSpawn ("tTexCyl", 210, VX_FP_TASK
, 100000, (FUNCPTR
)windMLTexCyl
,
340 UGL_FALSE
,1,2,3,4,5,6,7,8,9);
343 void windMLTexCyl (UGL_BOOL windMLMode
)
345 UGL_INPUT_DEVICE_ID keyboardDevId
;
346 GLsizei displayWidth
, displayHeight
;
351 linearFilter
= GL_FALSE
;
362 uglDriverFind (UGL_KEYBOARD_TYPE
, 0,
363 (UGL_UINT32
*)&keyboardDevId
);
365 uglDriverFind (UGL_EVENT_SERVICE_TYPE
, 0, (UGL_UINT32
*)&eventServiceId
);
367 qId
= uglEventQCreate (eventServiceId
, 100);
369 /* Double buffering */
371 umc
= uglMesaCreateNewContext(UGL_MESA_DOUBLE
372 | UGL_MESA_WINDML_EXCLUSIVE
, NULL
);
374 umc
= uglMesaCreateNewContext(UGL_MESA_DOUBLE
, NULL
);
382 uglMesaMakeCurrentContext (umc
, 0, 0, 1, 1);
384 uglMesaGetIntegerv(UGL_MESA_DISPLAY_WIDTH
, &displayWidth
);
385 uglMesaGetIntegerv(UGL_MESA_DISPLAY_HEIGHT
, &displayHeight
);
387 h
= (displayHeight
*3)/4;
389 x
= (displayWidth
-w
)/2;
390 y
= (displayHeight
-h
)/2;
392 uglMesaMoveToWindow(x
, y
);
393 uglMesaResizeToWindow(w
, h
);