2 /* ugltexcube.c - WindML/Mesa example program */
4 /* Copyright (C) 2001 by Wind River Systems, Inc */
7 * Mesa 3-D graphics library
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included
19 * in all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 * THE AUTHORS OR COPYRIGHT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 * DEALINGS IN THE SOFTWARE.
32 * Stephane Raimbault <stephane.raimbault@windriver.com>
45 #include <ugl/uglevent.h>
46 #include <ugl/uglinput.h>
47 #include <GL/uglmesa.h>
50 #include "../util/readtex.h"
52 #define IMAGE_FILE "Mesa/images/wrs_logo.rgb"
54 UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId
;
55 UGL_LOCAL UGL_EVENT_Q_ID qId
;
56 UGL_LOCAL UGL_MESA_CONTEXT umc
;
58 UGL_LOCAL GLfloat xrot
, yrot
, zrot
;
59 UGL_LOCAL GLuint texture
[1];
60 UGL_LOCAL GLuint theTexCube
;
68 UGL_LOCAL
void cleanUp (void);
70 UGL_LOCAL
void loadGLTexture()
72 TEX_IMAGE
* texImage
=NULL
;
74 texImage
= (TEX_IMAGE
*) malloc(sizeof(TEX_IMAGE
));
78 printf("Error allocating space for image");
83 texImage
->data
= LoadRGBImage(IMAGE_FILE
, &texImage
->width
,
84 &texImage
->height
, &texImage
->format
);
87 printf("Couldn't read %s\n", IMAGE_FILE
);
94 glGenTextures(1, &texture
[0]);
95 glBindTexture(GL_TEXTURE_2D
, texture
[0]);
96 glTexImage2D(GL_TEXTURE_2D
, 0, 3,
97 texImage
->width
, texImage
->height
,
98 0, GL_RGB
, GL_UNSIGNED_BYTE
, texImage
->data
);
100 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
101 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
103 free(texImage
->data
);
107 UGL_LOCAL
void initGL(int width
, int height
)
110 /* Load the texture(s) */
113 /* Enable texture mapping */
114 glEnable(GL_TEXTURE_2D
);
116 /* Clear the background color to black */
117 glClearColor(0.0f
, 0.0f
, 0.0f
, 0.0f
);
119 glEnable(GL_CULL_FACE
);
121 /* Enables smooth color shading */
122 glShadeModel(GL_SMOOTH
);
124 /* glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); */
125 /* glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); */
127 theTexCube
= glGenLists(1);
128 glNewList(theTexCube
, GL_COMPILE
);
130 /* Choose the texture to use */
131 glBindTexture(GL_TEXTURE_2D
, texture
[0]);
133 /* Begin drawing a cube */
136 /* Front face (note that the texture's corners have to match the
139 /* Bottom left of the texture and quad */
140 glTexCoord2f(0.0f
, 0.0f
);
141 glVertex3f(-1.0f
, -1.0f
, 1.0f
);
143 /* Bottom Right Of The Texture and Quad */
144 glTexCoord2f(1.0f
, 0.0f
);
145 glVertex3f(1.0f
, -1.0f
, 1.0f
);
147 /* Top Right Of The Texture and Quad */
148 glTexCoord2f(1.0f
, 1.0f
);
149 glVertex3f(1.0f
, 1.0f
, 1.0f
);
150 /* Top Left Of The Texture and Quad */
151 glTexCoord2f(0.0f
, 1.0f
);
152 glVertex3f(-1.0f
, 1.0f
, 1.0f
);
156 /* Bottom Right Of The Texture and Quad */
157 glTexCoord2f(1.0f
, 0.0f
);
158 glVertex3f(-1.0f
, -1.0f
, -1.0f
);
160 /* Top Right Of The Texture and Quad */
161 glTexCoord2f(1.0f
, 1.0f
);
162 glVertex3f(-1.0f
, 1.0f
, -1.0f
);
164 /* Top Left Of The Texture and Quad */
165 glTexCoord2f(0.0f
, 1.0f
);
166 glVertex3f(1.0f
, 1.0f
, -1.0f
);
168 /* Bottom Left Of The Texture and Quad */
169 glTexCoord2f(0.0f
, 0.0f
);
170 glVertex3f(1.0f
, -1.0f
, -1.0f
);
175 /* Top Left Of The Texture and Quad */
176 glTexCoord2f(0.0f
, 1.0f
);
177 glVertex3f(-1.0f
, 1.0f
, -1.0f
);
179 /* Bottom Left Of The Texture and Quad */
180 glTexCoord2f(0.0f
, 0.0f
);
181 glVertex3f(-1.0f
, 1.0f
, 1.0f
);
183 /* Bottom Right Of The Texture and Quad */
184 glTexCoord2f(1.0f
, 0.0f
);
185 glVertex3f(1.0f
, 1.0f
, 1.0f
);
187 /* Top Right Of The Texture and Quad */
188 glTexCoord2f(1.0f
, 1.0f
);
189 glVertex3f(1.0f
, 1.0f
, -1.0f
);
193 /* Top Right Of The Texture and Quad */
194 glTexCoord2f(1.0f
, 1.0f
);
195 glVertex3f(-1.0f
, -1.0f
, -1.0f
);
197 /* Top Left Of The Texture and Quad */
198 glTexCoord2f(0.0f
, 1.0f
);
199 glVertex3f(1.0f
, -1.0f
, -1.0f
);
201 /* Bottom Left Of The Texture and Quad */
202 glTexCoord2f(0.0f
, 0.0f
);
203 glVertex3f(1.0f
, -1.0f
, 1.0f
);
205 /* Bottom Right Of The Texture and Quad */
206 glTexCoord2f(1.0f
, 0.0f
);
207 glVertex3f(-1.0f
, -1.0f
, 1.0f
);
211 /* Bottom Right Of The Texture and Quad */
212 glTexCoord2f(1.0f
, 0.0f
);
213 glVertex3f(1.0f
, -1.0f
, -1.0f
);
215 /* Top Right Of The Texture and Quad */
216 glTexCoord2f(1.0f
, 1.0f
);
217 glVertex3f(1.0f
, 1.0f
, -1.0f
);
219 /* Top Left Of The Texture and Quad */
220 glTexCoord2f(0.0f
, 1.0f
);
221 glVertex3f(1.0f
, 1.0f
, 1.0f
);
223 /* Bottom Left Of The Texture and Quad */
224 glTexCoord2f(0.0f
, 0.0f
);
225 glVertex3f(1.0f
, -1.0f
, 1.0f
);
229 /* Bottom Left Of The Texture and Quad */
230 glTexCoord2f(0.0f
, 0.0f
);
231 glVertex3f(-1.0f
, -1.0f
, -1.0f
);
233 /* Bottom Right Of The Texture and Quad */
234 glTexCoord2f(1.0f
, 0.0f
);
235 glVertex3f(-1.0f
, -1.0f
, 1.0f
);
237 /* Top Right Of The Texture and Quad */
238 glTexCoord2f(1.0f
, 1.0f
);
239 glVertex3f(-1.0f
, 1.0f
, 1.0f
);
241 /* Top Left Of The Texture and Quad */
242 glTexCoord2f(0.0f
, 1.0f
);
243 glVertex3f(-1.0f
, 1.0f
, -1.0f
);
245 glEnd(); /* done with the polygon */
248 glDisable(GL_DITHER
);
249 glMatrixMode(GL_PROJECTION
);
250 /* Reset the projection matrix */
252 /* Calculate the aspect ratio of the window */
253 gluPerspective(45.0f
, (GLfloat
) width
/ (GLfloat
) height
, 0.1f
, 100.0f
);
255 glMatrixMode(GL_MODELVIEW
);
259 UGL_LOCAL
void drawGL()
261 glClear(GL_COLOR_BUFFER_BIT
);
266 /* Move 8 units into the screen */
267 glTranslatef(0.0f
, 0.0f
, -8.0f
);
269 /* Rotate on the X axis */
270 glRotatef(xrot
, 1.0f
, 0.0f
, 0.0f
);
272 /* Rotate on the Y axis */
273 glRotatef(yrot
, 0.0f
, 1.0f
, 0.0f
);
275 /* Rotate On The Z Axis */
276 glRotatef(zrot
, 0.0f
, 0.0f
, 1.0f
);
278 glCallList(theTexCube
);
282 uglMesaSwapBuffers();
291 UGL_LOCAL
int getEvent(void)
297 status
= uglEventGet (qId
, &event
, sizeof (event
), UGL_NO_WAIT
);
299 while (status
!= UGL_STATUS_Q_EMPTY
)
301 UGL_INPUT_EVENT
* pInputEvent
= (UGL_INPUT_EVENT
*)&event
;
303 if (pInputEvent
->modifiers
& UGL_KEYBOARD_KEYDOWN
)
306 status
= uglEventGet (qId
, &event
, sizeof (event
), UGL_NO_WAIT
);
312 UGL_LOCAL
void cleanUp (void)
314 if (eventServiceId
!= UGL_NULL
)
315 uglEventQDestroy (eventServiceId
, qId
);
317 uglMesaDestroyContext();
321 void windMLTexCube (UGL_BOOL windMLMode
);
323 void ugltexcube (void)
325 taskSpawn("tTexCube", 210, VX_FP_TASK
, 100000, (FUNCPTR
)windMLTexCube
,
326 UGL_FALSE
,1,2,3,4,5,6,7,8,9);
330 void windMLTexCube(UGL_BOOL windMLMode
)
332 GLuint width
, height
;
333 UGL_INPUT_DEVICE_ID keyboardDevId
;
337 uglDriverFind (UGL_KEYBOARD_TYPE
, 0, (UGL_UINT32
*)&keyboardDevId
);
339 if (uglDriverFind (UGL_EVENT_SERVICE_TYPE
, 0,
340 (UGL_UINT32
*)&eventServiceId
) == UGL_STATUS_OK
)
342 qId
= uglEventQCreate (eventServiceId
, 100);
346 eventServiceId
= UGL_NULL
;
350 umc
= uglMesaCreateNewContext(UGL_MESA_DOUBLE
351 | UGL_MESA_WINDML_EXCLUSIVE
, NULL
);
353 umc
= uglMesaCreateNewContext(UGL_MESA_DOUBLE
, NULL
);
361 uglMesaMakeCurrentContext(umc
, 0, 0,
362 UGL_MESA_FULLSCREEN_WIDTH
,
363 UGL_MESA_FULLSCREEN_HEIGHT
);
366 uglMesaGetIntegerv(UGL_MESA_WIDTH
, &width
);
367 uglMesaGetIntegerv(UGL_MESA_HEIGHT
, &height
);
369 initGL(width
, height
);