2 /* uglpoint.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>
44 #include <ugl/uglevent.h>
45 #include <ugl/uglinput.h>
47 #include <GL/uglmesa.h>
49 #define DOUBLE_BUFFER GL_TRUE
60 UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId
;
61 UGL_LOCAL UGL_EVENT_Q_ID qId
;
62 UGL_LOCAL UGL_MESA_CONTEXT umc
;
63 UGL_LOCAL GLint angleT
;
65 UGL_LOCAL
void initGL (void)
67 /* By passed in RGB mode */
68 uglMesaSetColor(BLACK
, 0.0, 0.0, 0.0);
69 uglMesaSetColor(RED
, 1.0, 0.0, 0.0);
70 uglMesaSetColor(GREEN
, 0.0, 1.0, 0.0);
71 uglMesaSetColor(BLUE
, 0.0, 0.0, 1.0);
72 uglMesaSetColor(WHITE
, 1.0, 1.0, 1.0);
74 glOrtho(0.0, 1.0, 0.0, 1.0, -20.0, 20.0);
76 glClearColor(0.0, 0.0, 0.0, 0.0);
80 UGL_LOCAL
void drawGL (void)
85 /* Avoid blinking in single buffer */
88 glClear(GL_COLOR_BUFFER_BIT
);
93 (rgb
) ? glColor3f(1.0, 0.0, 0.0): glIndexi(RED
);
97 x
= rand() / (RAND_MAX
+1.0);
98 y
= rand() / (RAND_MAX
+1.0);
102 (rgb
) ? glColor3f(0.0, 1.0, 0.0): glIndexi(GREEN
);
104 for (i
=0; i
<150; i
++)
106 x
= (rand() / (RAND_MAX
+1.0));
107 y
= (rand() / (RAND_MAX
+1.0));
111 (rgb
) ? glColor3f(0.0, 0.0, 1.0): glIndexi(BLUE
);
114 for (i
=0; i
<150; i
++)
116 x
= rand() / (RAND_MAX
+1.0);
117 y
= rand() / (RAND_MAX
+1.0);
123 /* Smooth triangle */
126 glTranslatef(0.5, 0.5, 0);
127 glRotatef(angleT
, 1.0, -1.0, 0.0);
128 angleT
= angleT
++ % 360;
129 glBegin(GL_TRIANGLES
);
130 (rgb
) ? glColor3f(1.0, 0.0, 0.0): glIndexi(RED
);
131 glVertex2f(0.75, 0.25);
132 (rgb
) ? glColor3f(0.0, 1.0, 0.0): glIndexi(GREEN
);
133 glVertex2f(0.75, 0.75);
134 (rgb
) ? glColor3f(0.0, 0.0, 1.0): glIndexi(BLUE
);
135 glVertex2f(0.25, 0.75);
143 uglMesaSwapBuffers();
146 /************************************************************************
150 * RETURNS: true or false
156 UGL_LOCAL
int getEvent(void)
162 status
= uglEventGet (qId
, &event
, sizeof (event
), UGL_NO_WAIT
);
164 while (status
!= UGL_STATUS_Q_EMPTY
)
166 UGL_INPUT_EVENT
* pInputEvent
= (UGL_INPUT_EVENT
*)&event
;
168 if (pInputEvent
->modifiers
& UGL_KEYBOARD_KEYDOWN
)
171 status
= uglEventGet (qId
, &event
, sizeof (event
), UGL_NO_WAIT
);
177 void windMLPoint (UGL_BOOL windMLMode
);
181 taskSpawn ("tPoint", 210, VX_FP_TASK
, 100000,
182 (FUNCPTR
)windMLPoint
, UGL_FALSE
,1,2,3,4,5,6,7,8,9);
185 void windMLPoint (UGL_BOOL windMLMode
)
188 GLsizei width
, height
;
189 UGL_INPUT_DEVICE_ID keyboardDevId
;
195 uglDriverFind (UGL_KEYBOARD_TYPE
, 0, (UGL_UINT32
*)&keyboardDevId
);
197 if (uglDriverFind (UGL_EVENT_SERVICE_TYPE
, 0,
198 (UGL_UINT32
*)&eventServiceId
) == UGL_STATUS_OK
)
200 qId
= uglEventQCreate (eventServiceId
, 100);
204 eventServiceId
= UGL_NULL
;
210 umc
= uglMesaCreateNewContext(UGL_MESA_DOUBLE
211 | UGL_MESA_WINDML_EXCLUSIVE
, NULL
);
213 umc
= uglMesaCreateNewContext(UGL_MESA_DOUBLE
, NULL
);
218 umc
= uglMesaCreateNewContext(UGL_MESA_SINGLE
219 | UGL_MESA_WINDML_EXCLUSIVE
, NULL
);
221 umc
= uglMesaCreateNewContext(UGL_MESA_SINGLE
, NULL
);
232 uglMesaMakeCurrentContext(umc
, 0, 0, UGL_MESA_FULLSCREEN_WIDTH
,
233 UGL_MESA_FULLSCREEN_HEIGHT
);
237 uglMesaGetIntegerv(UGL_MESA_RGB
, &rgb
);
244 uglMesaGetIntegerv(UGL_MESA_WIDTH
, &width
);
245 uglMesaGetIntegerv(UGL_MESA_HEIGHT
, &height
);
247 printf ("glReadPixel return ");
250 glReadPixels(width
/2, height
/2,
252 GL_UNSIGNED_BYTE
, pPixels
);
254 printf ("R:%i G:%i B:%i (RGB)", pPixels
[0], pPixels
[1], pPixels
[2]);
258 glReadPixels(width
/2, height
/2,
259 1, 1, GL_COLOR_INDEX
,
260 GL_UNSIGNED_BYTE
, pPixels
);
262 if (pPixels
[0] == BLUE
)
263 printf ("BLUE (CI)");
265 printf ("%i (CI))", pPixels
[0]);
268 printf(" for %ix%i\n", width
/2, height
/2);
270 if (eventServiceId
!= UGL_NULL
)
271 uglEventQDestroy (eventServiceId
, qId
);
273 uglMesaDestroyContext();