blob: e58f071ea4bd3da154afa2bd103c4448e0791a2c [file] [log] [blame]
Brian Paul976c26c2001-08-20 16:07:10 +00001
2/* uglline.c - WindML/Mesa example program */
3
4/*
5 * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc.
6 *
7 * Permission to use, copy, modify, distribute, and sell this software and
8 * its documentation for any purpose is hereby granted without fee, provided
9 * that (i) the above copyright notices and this permission notice appear in
10 * all copies of the software and related documentation, and (ii) the name of
11 * Silicon Graphics may not be used in any advertising or
12 * publicity relating to the software without the specific, prior written
13 * permission of Silicon Graphics.
14 *
15 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF
16 * ANY KIND,
17 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
18 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
19 *
20 * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR
21 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
22 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
23 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
24 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
25 * OF THIS SOFTWARE.
26 */
27
28/*
29modification history
30--------------------
3101a,jun01,sra Ported to UGL/Mesa and modifications
32*/
33
34/*
35DESCRIPTION
36Draw circular lines
37*/
38
39#include <stdio.h>
40#include <math.h>
41
42#include <ugl/ugl.h>
43#include <ugl/uglucode.h>
44#include <ugl/uglevent.h>
45#include <ugl/uglinput.h>
46
47#include <GL/uglmesa.h>
48#include <GL/glu.h>
49
50#define BLACK (0)
51#define YELLOW (1)
52#define GREEN (2)
53#define BLUE (3)
54#define CI_OFFSET 4
55
56UGL_LOCAL GLuint rgb;
57UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId;
58UGL_LOCAL UGL_EVENT_Q_ID qId;
59UGL_LOCAL volatile UGL_BOOL stopWex;
60UGL_LOCAL UGL_MESA_CONTEXT umc;
61
62UGL_LOCAL GLboolean mode1, mode2;
63UGL_LOCAL GLint size;
64
65UGL_LOCAL GLfloat pntA[3] = {
66 -10.0, 0.0, 0.0
67};
68UGL_LOCAL GLfloat pntB[3] = {
69 -5.0, 0.0, 0.0
70};
71
72UGL_LOCAL GLint angleA;
73
74UGL_LOCAL void initGL (void)
75 {
76 GLint i;
77
78 uglMesaSetColor(BLACK, 0.0, 0.0, 0.0);
79 uglMesaSetColor(YELLOW, 1.0, 1.0, 0.0);
80 uglMesaSetColor(GREEN, 0.0, 1.0, 0.0);
81 uglMesaSetColor(BLUE, 0.0, 0.0, 1.0);
82
83 for (i = 0; i < 16; i++)
84 {
85 uglMesaSetColor(CI_OFFSET+i, i/15.0, i/15.0, 0.0);
86 }
87
88 glClearColor(0.0, 0.0, 0.0, 0.0);
89 glClearIndex(BLACK);
90
91 glMatrixMode(GL_PROJECTION);
92 glLoadIdentity();
93 glOrtho(-10, 10, -10, 10, -10.0, 10.0);
94
95 glMatrixMode(GL_MODELVIEW);
96
97 glLineStipple(1, 0xF0E0);
98 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
99
100 mode1 = GL_FALSE;
101 mode2 = GL_FALSE;
102 size = 1;
103 }
104
105UGL_LOCAL void drawGL (void)
106 {
107
108 GLint ci, i;
109
110 glClear(GL_COLOR_BUFFER_BIT);
111
112 glLineWidth(size);
113
114 if (mode1) {
115 glEnable(GL_LINE_STIPPLE);
116 } else {
117 glDisable(GL_LINE_STIPPLE);
118 }
119
120 if (mode2) {
121 ci = CI_OFFSET;
122 glEnable(GL_LINE_SMOOTH);
123 glEnable(GL_BLEND);
124 } else {
125 ci = YELLOW;
126 glDisable(GL_LINE_SMOOTH);
127 glDisable(GL_BLEND);
128 }
129
130 glPushMatrix();
131
132 glRotatef(angleA, 1, 0, 1);
133 angleA = angleA++ % 360;
134
135 for (i = 0; i < 360; i += 5) {
136 glRotatef(5.0, 0, 0, 1);
137
138 glColor3f(1.0, 1.0, 0.0);
139 glBegin(GL_LINE_STRIP);
140 glVertex3fv(pntA);
141 glVertex3fv(pntB);
142 glEnd();
143
144 glPointSize(1);
145
146 glColor3f(0.0, 1.0, 0.0);
147 glBegin(GL_POINTS);
148 glVertex3fv(pntA);
149 glVertex3fv(pntB);
150 glEnd();
151 }
152
153 glPopMatrix();
154
155 glFlush();
156
157 uglMesaSwapBuffers();
158
159 }
160
161UGL_LOCAL void echoUse(void)
162 {
163 printf("tLine keys:\n");
164 printf(" b Blending/antialiasing\n");
165 printf(" n Line stipple\n");
166 printf(" Up/Down Pixel size\n");
167 printf(" ESC Exit\n");
168 }
169
170UGL_LOCAL void readKey (UGL_WCHAR key)
171 {
172 switch(key)
173 {
174 case 'n':
175 mode1 = (mode1) ? GL_FALSE: GL_TRUE;
176 break;
177 case 'b':
178 mode2 = (mode2) ? GL_FALSE: GL_TRUE;
179 break;
180 case UGL_UNI_DOWN_ARROW:
181 if(size>0)
182 size--;
183 break;
184 case UGL_UNI_UP_ARROW:
185 size++;
186 break;
187 case UGL_UNI_ESCAPE:
188 stopWex = UGL_TRUE;
189 break;
190 }
191 }
192
193UGL_LOCAL void loopEvent(void)
194 {
195 UGL_EVENT event;
196 UGL_INPUT_EVENT * pInputEvent;
197
198 UGL_FOREVER
199 {
200 if (uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT)
201 != UGL_STATUS_Q_EMPTY)
202 {
203 pInputEvent = (UGL_INPUT_EVENT *)&event;
204
205 if (pInputEvent->header.type == UGL_EVENT_TYPE_KEYBOARD &&
206 pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN)
207 readKey(pInputEvent->type.keyboard.key);
208 }
209
210 drawGL();
211 if (stopWex)
212 break;
213 }
214 }
215
Brian Paul30693302001-09-10 19:21:13 +0000216void windMLLine (UGL_BOOL windMLMode);
Brian Paul976c26c2001-08-20 16:07:10 +0000217
218void uglline (void)
219 {
220 taskSpawn("tLine", 210, VX_FP_TASK, 100000, (FUNCPTR)windMLLine,
Brian Paul30693302001-09-10 19:21:13 +0000221 UGL_FALSE,1,2,3,4,5,6,7,8,9);
Brian Paul976c26c2001-08-20 16:07:10 +0000222 }
223
224
Brian Paul30693302001-09-10 19:21:13 +0000225void windMLLine(UGL_BOOL windMLMode)
Brian Paul976c26c2001-08-20 16:07:10 +0000226 {
227
228 UGL_INPUT_DEVICE_ID keyboardDevId;
229
230 angleA = 0;
231
232 uglInitialize();
233
234 uglDriverFind (UGL_KEYBOARD_TYPE, 0, (UGL_UINT32 *)&keyboardDevId);
235
236 uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, (UGL_UINT32 *)&eventServiceId);
237
238 qId = uglEventQCreate (eventServiceId, 100);
239
240 /* Double buffer */
241
Brian Paul30693302001-09-10 19:21:13 +0000242 if (windMLMode)
243 umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE
244 | UGL_MESA_WINDML_EXCLUSIVE, NULL);
245 else
246 umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE, NULL);
Brian Paul976c26c2001-08-20 16:07:10 +0000247
248 if (umc == NULL)
249 {
250 uglDeinitialize();
251 return;
252 }
253
254 /* Fullscreen */
255
256 uglMesaMakeCurrentContext(umc, 0, 0, UGL_MESA_FULLSCREEN_WIDTH,
257 UGL_MESA_FULLSCREEN_HEIGHT);
258
259 uglMesaGetIntegerv(UGL_MESA_RGB, &rgb);
260
261 initGL();
262
263 echoUse();
264
265 stopWex = UGL_FALSE;
266 loopEvent();
267
268 uglEventQDestroy(eventServiceId, qId);
269
270 uglMesaDestroyContext();
271 uglDeinitialize();
272
273 return;
274 }