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 * $Log: ugltexcyl.c,v $
11 * Revision 1.2 2001/09/10 19:21:13 brianp
12 * WindML updates (Stephane Raimbault)
14 * Revision 1.1 2001/08/20 16:07:11 brianp
15 * WindML driver (Stephane Raimbault)
17 * Revision 1.5 2001/03/27 17:35:26 brianp
18 * set initial window pos
20 * Revision 1.4 2000/12/24 22:53:54 pesco
21 * * demos/Makefile.am (INCLUDES): Added -I$(top_srcdir)/util.
22 * * demos/Makefile.X11, demos/Makefile.BeOS-R4, demos/Makefile.cygnus:
23 * Essentially the same.
24 * Program files updated to include "readtex.c", not "../util/readtex.c".
25 * * demos/reflect.c: Likewise for "showbuffer.c".
28 * * Makefile.am (EXTRA_DIST): Added top-level regular files.
30 * * include/GL/Makefile.am (INC_X11): Added glxext.h.
33 * * src/GGI/include/ggi/mesa/Makefile.am (EXTRA_HEADERS): Include
34 * Mesa GGI headers in dist even if HAVE_GGI is not given.
36 * * configure.in: Look for GLUT and demo source dirs in $srcdir.
38 * * src/swrast/Makefile.am (libMesaSwrast_la_SOURCES): Set to *.[ch].
39 * More source list updates in various Makefile.am's.
41 * * Makefile.am (dist-hook): Remove CVS directory from distribution.
42 * (DIST_SUBDIRS): List all possible subdirs here.
43 * (SUBDIRS): Only list subdirs selected for build again.
44 * The above two applied to all subdir Makefile.am's also.
46 * Revision 1.3 2000/09/29 23:09:39 brianp
49 * Revision 1.2 1999/10/21 16:39:06 brianp
50 * added -info command line option
52 * Revision 1.1.1.1 1999/08/19 00:55:40 jtg
55 * Revision 3.3 1999/03/28 18:24:37 brianp
58 * Revision 3.2 1998/11/05 04:34:04 brianp
59 * moved image files to ../images/ directory
61 * Revision 3.1 1998/06/23 03:16:51 brianp
62 * added Point/Linear sampling menu items
64 * Revision 3.0 1998/02/14 18:42:29 brianp
76 #include <ugl/uglucode.h>
77 #include <ugl/uglevent.h>
78 #include <ugl/uglinput.h>
80 #include <GL/uglmesa.h>
83 #include "../util/readtex.h"
85 #define TEXTURE_FILE "Mesa/images/reflect.rgb"
91 #define POINT_FILTER 20
92 #define LINEAR_FILTER 21
96 UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId
;
97 UGL_LOCAL UGL_EVENT_Q_ID qId
;
98 UGL_LOCAL
volatile UGL_BOOL stopWex
;
99 UGL_LOCAL UGL_MESA_CONTEXT umc
;
101 UGL_LOCAL GLuint CylinderObj
;
102 UGL_LOCAL GLboolean Animate
;
103 UGL_LOCAL GLboolean linearFilter
;
105 UGL_LOCAL GLfloat Xrot
, Yrot
, Zrot
;
106 UGL_LOCAL GLfloat DXrot
, DYrot
;
108 UGL_LOCAL GLuint limit
;
109 UGL_LOCAL GLuint count
;
110 UGL_LOCAL GLuint tickStart
, tickStop
, tickBySec
;
112 UGL_LOCAL
void cleanUp (void);
114 UGL_LOCAL
void drawGL(void)
120 glClear( GL_COLOR_BUFFER_BIT
);
123 glRotatef(Xrot
, 1.0, 0.0, 0.0);
124 glRotatef(Yrot
, 0.0, 1.0, 0.0);
125 glRotatef(Zrot
, 0.0, 0.0, 1.0);
126 glScalef(5.0, 5.0, 5.0);
127 glCallList(CylinderObj
);
131 uglMesaSwapBuffers();
142 tickStop
= tickGet ();
143 time
= (tickStop
-tickStart
)/tickBySec
;
144 printf (" %i fps\n", count
/time
);
145 tickStart
= tickStop
;
154 UGL_LOCAL
void echoUse(void)
157 printf(" Up/Down Rotate on Y\n");
158 printf(" Left/Right Rotate on X\n");
159 printf(" a Toggle animation\n");
160 printf(" f Toggle point/linear filtered\n");
162 printf(" t Textured\n");
163 printf(" r Reflect\n");
164 printf(" ESC Exit\n");
167 UGL_LOCAL
void readKey(UGL_WCHAR key
)
178 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
,
180 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
,
185 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
,
187 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
,
190 linearFilter
= !linearFilter
;
193 glEnable(GL_LIGHTING
);
194 glDisable(GL_TEXTURE_2D
);
195 glDisable(GL_TEXTURE_GEN_S
);
196 glDisable(GL_TEXTURE_GEN_T
);
199 glDisable(GL_LIGHTING
);
200 glEnable(GL_TEXTURE_2D
);
201 glDisable(GL_TEXTURE_GEN_S
);
202 glDisable(GL_TEXTURE_GEN_T
);
205 glDisable(GL_LIGHTING
);
206 glEnable(GL_TEXTURE_2D
);
207 glEnable(GL_TEXTURE_GEN_S
);
208 glEnable(GL_TEXTURE_GEN_T
);
210 case UGL_UNI_UP_ARROW
:
213 case UGL_UNI_DOWN_ARROW
:
216 case UGL_UNI_LEFT_ARROW
:
219 case UGL_UNI_RIGHT_ARROW
:
228 UGL_LOCAL
void loopEvent(void)
231 UGL_INPUT_EVENT
* pInputEvent
;
235 if (uglEventGet (qId
, &event
, sizeof (event
), UGL_NO_WAIT
)
236 != UGL_STATUS_Q_EMPTY
)
238 pInputEvent
= (UGL_INPUT_EVENT
*)&event
;
240 if (pInputEvent
->header
.type
== UGL_EVENT_TYPE_KEYBOARD
&&
241 pInputEvent
->modifiers
& UGL_KEYBOARD_KEYDOWN
)
242 readKey(pInputEvent
->type
.keyboard
.key
);
251 UGL_LOCAL
void initGL(void)
253 GLUquadricObj
*q
= gluNewQuadric();
254 CylinderObj
= glGenLists(1);
255 glNewList(CylinderObj
, GL_COMPILE
);
257 glTranslatef(0.0, 0.0, -1.0);
260 gluQuadricNormals(q
, GL_SMOOTH
);
261 gluQuadricTexture(q
, GL_TRUE
);
262 gluCylinder(q
, 0.6, 0.6, 2.0, 24, 1);
265 glTranslatef(0.0, 0.0, 2.0);
266 gluDisk(q
, 0.0, 0.6, 24, 1);
269 glTranslatef(0.0, 0.0, -2.0);
270 gluQuadricOrientation(q
, GLU_INSIDE
);
271 gluDisk(q
, 0.0, 0.6, 24, 1);
277 glEnable(GL_LIGHTING
);
279 GLfloat gray
[4] = {0.2, 0.2, 0.2, 1.0};
280 GLfloat white
[4] = {1.0, 1.0, 1.0, 1.0};
281 GLfloat teal
[4] = { 0.0, 1.0, 0.8, 1.0 };
282 glMaterialfv(GL_FRONT
, GL_DIFFUSE
, teal
);
283 glLightfv(GL_LIGHT0
, GL_AMBIENT
, gray
);
284 glLightfv(GL_LIGHT0
, GL_DIFFUSE
, white
);
288 /* fitering = nearest, initially */
289 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
290 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
292 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_DECAL
);
293 glHint(GL_PERSPECTIVE_CORRECTION_HINT
, GL_FASTEST
);
295 glTexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, GL_SPHERE_MAP
);
296 glTexGeni(GL_T
, GL_TEXTURE_GEN_MODE
, GL_SPHERE_MAP
);
298 if (!LoadRGBMipmaps(TEXTURE_FILE
, GL_RGB
))
300 printf("Error: couldn't load texture image\n");
305 glEnable(GL_CULL_FACE
); /* don't need Z testing for convex objects */
307 glEnable(GL_LIGHTING
);
309 glMatrixMode( GL_PROJECTION
);
311 glFrustum( -1.0, 1.0, -1.0, 1.0, 10.0, 100.0 );
312 glMatrixMode( GL_MODELVIEW
);
314 glTranslatef( 0.0, 0.0, -70.0 );
316 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
317 printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION
));
318 printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR
));
319 printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS
));
322 tickStart
= tickGet ();
323 tickBySec
= sysClkRateGet ();
328 UGL_LOCAL
void cleanUp (void)
330 uglEventQDestroy (eventServiceId
, qId
);
332 uglMesaDestroyContext();
336 void windMLTexCyl (UGL_BOOL windMLMode
);
338 void ugltexcyl (void)
340 taskSpawn ("tTexCyl", 210, VX_FP_TASK
, 100000, (FUNCPTR
)windMLTexCyl
,
341 UGL_FALSE
,1,2,3,4,5,6,7,8,9);
344 void windMLTexCyl (UGL_BOOL windMLMode
)
346 UGL_INPUT_DEVICE_ID keyboardDevId
;
347 GLsizei displayWidth
, displayHeight
;
352 linearFilter
= GL_FALSE
;
363 uglDriverFind (UGL_KEYBOARD_TYPE
, 0,
364 (UGL_UINT32
*)&keyboardDevId
);
366 uglDriverFind (UGL_EVENT_SERVICE_TYPE
, 0, (UGL_UINT32
*)&eventServiceId
);
368 qId
= uglEventQCreate (eventServiceId
, 100);
370 /* Double buffering */
372 umc
= uglMesaCreateNewContext(UGL_MESA_DOUBLE
373 | UGL_MESA_WINDML_EXCLUSIVE
, NULL
);
375 umc
= uglMesaCreateNewContext(UGL_MESA_DOUBLE
, NULL
);
383 uglMesaMakeCurrentContext (umc
, 0, 0, 1, 1);
385 uglMesaGetIntegerv(UGL_MESA_DISPLAY_WIDTH
, &displayWidth
);
386 uglMesaGetIntegerv(UGL_MESA_DISPLAY_HEIGHT
, &displayHeight
);
388 h
= (displayHeight
*3)/4;
390 x
= (displayWidth
-w
)/2;
391 y
= (displayHeight
-h
)/2;
393 uglMesaMoveToWindow(x
, y
);
394 uglMesaResizeToWindow(w
, h
);