2
/* uglflip.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>
37
Draw a triangle and flip the screen
44
#include <ugl/uglucode.h>
45
#include <ugl/uglevent.h>
46
#include <ugl/uglinput.h>
48
#include <GL/uglmesa.h>
58
UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId;
59
UGL_LOCAL UGL_EVENT_Q_ID qId;
60
UGL_LOCAL volatile UGL_BOOL stopWex;
62
UGL_LOCAL UGL_MESA_CONTEXT umc;
64
UGL_LOCAL void initGL (void)
66
uglMesaSetColor(BLACK, 0.0, 0.0, 0.0);
67
uglMesaSetColor(RED, 1.0, 0.3, 0.3);
68
uglMesaSetColor(GREEN, 0.3, 1.0, 0.3);
69
uglMesaSetColor(BLUE, 0.3, 0.3, 1.0);
71
glClearColor(0.0, 0.0, 0.0, 0.0);
74
glMatrixMode(GL_PROJECTION);
76
glMatrixMode(GL_MODELVIEW);
79
UGL_LOCAL void drawGL (void)
81
glClear(GL_COLOR_BUFFER_BIT);
83
glBegin(GL_TRIANGLES);
84
(rgb) ? glColor3f(1.0, 0.3, 0.3) : glIndexi(RED);
85
glVertex2f(0.75, -0.50);
86
(rgb) ? glColor3f(0.3, 1.0, 0.3) : glIndexi(GREEN);
87
glVertex2f(0.0, 0.75);
88
(rgb) ? glColor3f(0.3, 0.3, 1.0) : glIndexi(BLUE);
89
glVertex2f(-0.75, -0.50);
93
(rgb) ? glColor3f(1.0, 0.3, 0.3) : glIndexi(RED);
94
glVertex2f(-1.0, 1.0);
95
(rgb) ? glColor3f(0.3, 0.3, 1.0) : glIndexi(BLUE);
96
glVertex2f(1.0, -1.0);
101
uglMesaSwapBuffers();
104
UGL_LOCAL void echoUse(void)
106
printf("tFlip keys:\n");
107
printf(" d Toggle dithering\n");
108
printf(" up Reduce the window\n");
109
printf(" down Enlarge the window\n");
110
printf(" page up Y==0 is the bottom line and increases upward\n");
111
printf(" page down Y==0 is the bottom line and increases downward\n");
112
printf(" ESC Exit\n");
115
UGL_LOCAL void readKey (UGL_WCHAR key)
120
case UGL_UNI_UP_ARROW:
121
uglMesaResizeWindow(8, 8);
123
case UGL_UNI_DOWN_ARROW:
124
glDrawBuffer(GL_FRONT_LEFT);
125
glClear(GL_COLOR_BUFFER_BIT);
126
glDrawBuffer(GL_BACK_LEFT);
127
uglMesaResizeWindow(-8, -8);
129
case UGL_UNI_PAGE_UP:
130
uglMesaPixelStore(UGL_MESA_Y_UP, GL_TRUE);
132
case UGL_UNI_PAGE_DOWN:
133
uglMesaPixelStore(UGL_MESA_Y_UP, GL_FALSE);
139
if (glIsEnabled(GL_DITHER))
140
glDisable(GL_DITHER);
147
UGL_LOCAL void loopEvent(void)
150
UGL_INPUT_EVENT * pInputEvent;
156
if (uglEventGet (qId, &event, sizeof (event), UGL_WAIT_FOREVER)
157
!= UGL_STATUS_Q_EMPTY)
159
pInputEvent = (UGL_INPUT_EVENT *)&event;
161
if (pInputEvent->header.type == UGL_EVENT_TYPE_KEYBOARD &&
162
pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN)
164
readKey(pInputEvent->type.keyboard.key);
174
void windMLFlip (UGL_BOOL windMLMode);
178
taskSpawn ("tFlip", 210, VX_FP_TASK, 100000, (FUNCPTR)windMLFlip,
179
UGL_FALSE,1,2,3,4,5,6,7,8,9);
182
void windMLFlip (UGL_BOOL windMLMode)
185
UGL_INPUT_DEVICE_ID keyboardDevId;
189
uglDriverFind (UGL_KEYBOARD_TYPE, 0, (UGL_UINT32 *)&keyboardDevId);
191
uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, (UGL_UINT32 *)&eventServiceId);
193
qId = uglEventQCreate (eventServiceId, 100);
196
umc = uglMesaCreateNewContext(UGL_MESA_SINGLE
197
| UGL_MESA_WINDML_EXCLUSIVE, NULL);
199
umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE_SOFTWARE, NULL);
207
uglMesaMakeCurrentContext(umc, 0, 0, UGL_MESA_FULLSCREEN_WIDTH,
208
UGL_MESA_FULLSCREEN_HEIGHT);
210
uglMesaGetIntegerv(UGL_MESA_RGB, &rgb);
218
uglEventQDestroy (eventServiceId, qId);
220
uglMesaDestroyContext();