1 /* uglicotorus.c - WindML/Mesa example program */
3 /* Copyright (C) 2001 by Wind River Systems, Inc */
6 * Mesa 3-D graphics library
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * THE AUTHORS OR COPYRIGHT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 * DEALINGS IN THE SOFTWARE.
38 #include <ugl/uglevent.h>
39 #include <ugl/uglinput.h>
40 #include <ugl/uglucode.h>
42 #include <GL/uglmesa.h>
45 /* Need GLUT_SHAPES */
47 #include <GL/uglglutshapes.h>
49 UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId
;
50 UGL_LOCAL UGL_EVENT_Q_ID qId
;
51 UGL_LOCAL UGL_MESA_CONTEXT umc
;
52 UGL_LOCAL
volatile UGL_BOOL stopWex
;
54 UGL_LOCAL GLfloat angle
;
55 UGL_LOCAL GLboolean chaos_on
;
56 UGL_LOCAL GLboolean color_on
;
58 UGL_LOCAL GLuint theIco
, theTorus
, theSphere
, theCube
;
66 glViewport(0,0,(GLsizei
)w
,(GLsizei
)h
);
67 glMatrixMode(GL_PROJECTION
);
69 gluPerspective(60.0,(GLfloat
)w
/(GLfloat
)h
,1.0,60.0);
71 glMatrixMode(GL_MODELVIEW
);
73 gluLookAt(0.0,0.0,25.0,0.0,0.0,0.0,0.0,1.0,0.0);
75 glClearColor(0.0,0.0,0.0,0.0);
77 glEnable(GL_DEPTH_TEST
);
78 glEnable(GL_LIGHTING
);
81 glEnable(GL_COLOR_MATERIAL
);
83 theIco
= glGenLists(1);
84 glNewList(theIco
, GL_COMPILE
);
85 glutSolidIcosahedron();
88 theTorus
= glGenLists(1);
89 glNewList(theTorus
, GL_COMPILE
);
90 glutSolidTorus(0.2,1.0,10,10);
93 theSphere
= glGenLists(1);
94 glNewList(theSphere
, GL_COMPILE
);
95 glutSolidSphere(2.5,20,20);
98 theCube
= glGenLists(1);
99 glNewList(theCube
, GL_COMPILE
);
105 UGL_LOCAL
void createIcoToruses
111 glRotatef(angle
,1.0,1.0,1.0);
117 glColor3f(1.0,0.0,0.0);
120 glColor3f(1.0,0.1,0.7);
123 glColor3f(1.0,0.0,1.0);
126 glColor3f(0.0,0.0,1.0);
129 glColor3f(0.0,0.5,1.0);
132 glColor3f(0.0,1.0,0.7);
135 glColor3f(0.0,1.0,0.0);
138 glColor3f(0.5,1.0,0.0);
141 glColor3f(1.0,1.0,0.0);
144 glColor3f(1.0,0.5,0.0);
148 glRotatef(angle
,1.0,1.0,1.0);
149 glCallList(theTorus
);
150 glRotatef(-2*angle
,1.0,1.0,1.0);
151 glCallList(theTorus
);
155 UGL_LOCAL
void drawGL (void)
160 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
162 glClear(GL_DEPTH_BUFFER_BIT
);
167 glRotatef(angle
,1.0,1.0,1.0);
170 glRotatef(angle
,1.0,1.0,1.0);
171 glColor3f(1.0,0.5,0.0);
172 glCallList(theSphere
);
173 glColor3f(1.0,0.0,0.0);
177 glRotatef(-angle
,0.0,0.0,1.0);
179 /* draw ten icosahedrons */
180 for (i
= 0; i
< 10; i
++)
183 glRotatef(36*i
,0.0,0.0,1.0);
184 glTranslatef(10.0,0.0,0.0);
185 glRotatef(2*angle
,0.0,1.0,0.0);
186 glTranslatef(0.0,0.0,2.0);
195 uglMesaSwapBuffers();
201 UGL_LOCAL
void echoUse(void)
203 printf("tIcoTorus keys:\n");
204 printf(" c Toggle color buffer clear\n");
205 printf(" SPACE Toggle chaos mode\n");
206 printf(" ESC Exit\n");
209 UGL_LOCAL
void readKey (UGL_WCHAR key
)
215 color_on
= !color_on
;
218 chaos_on
= !chaos_on
;
226 UGL_LOCAL
void loopEvent(void)
229 UGL_INPUT_EVENT
* pInputEvent
;
233 if (uglEventGet (qId
, &event
, sizeof (event
), UGL_NO_WAIT
)
234 != UGL_STATUS_Q_EMPTY
)
236 pInputEvent
= (UGL_INPUT_EVENT
*)&event
;
238 if (pInputEvent
->header
.type
== UGL_EVENT_TYPE_KEYBOARD
&&
239 pInputEvent
->modifiers
& UGL_KEYBOARD_KEYDOWN
)
240 readKey(pInputEvent
->type
.keyboard
.key
);
249 void windMLIcoTorus (UGL_BOOL windMLMode
);
251 void uglicotorus (void)
253 taskSpawn ("tIcoTorus", 210, VX_FP_TASK
, 100000, (FUNCPTR
)windMLIcoTorus
,
254 UGL_FALSE
,1,2,3,4,5,6,7,8,9);
257 void windMLIcoTorus (UGL_BOOL windMLMode
)
259 GLsizei width
, height
;
260 UGL_INPUT_DEVICE_ID keyboardDevId
;
268 uglDriverFind (UGL_KEYBOARD_TYPE
, 0,
269 (UGL_UINT32
*)&keyboardDevId
);
271 if (uglDriverFind (UGL_EVENT_SERVICE_TYPE
, 0,
272 (UGL_UINT32
*)&eventServiceId
) == UGL_STATUS_OK
)
274 qId
= uglEventQCreate (eventServiceId
, 100);
278 eventServiceId
= UGL_NULL
;
281 /* Double buffering */
283 umc
= uglMesaCreateNewContext(UGL_MESA_DOUBLE
284 | UGL_MESA_WINDML_EXCLUSIVE
, NULL
);
286 umc
= uglMesaCreateNewContext(UGL_MESA_DOUBLE
, NULL
);
294 uglMesaMakeCurrentContext (umc
, 0, 0, UGL_MESA_FULLSCREEN_WIDTH
,
295 UGL_MESA_FULLSCREEN_HEIGHT
);
297 uglMesaGetIntegerv(UGL_MESA_WIDTH
, &width
);
298 uglMesaGetIntegerv(UGL_MESA_HEIGHT
, &height
);
300 initGL (width
, height
);
307 if (eventServiceId
!= UGL_NULL
)
308 uglEventQDestroy (eventServiceId
, qId
);
310 uglMesaDestroyContext ();