Merge branch 'mesa_7_7_branch'
[mesa.git] / progs / windml / uglalldemos.c
1
2 /* uglalldemos.c - WindML/Mesa example program */
3
4 /* Copyright (C) 2001 by Wind River Systems, Inc */
5
6 /*
7 * Mesa 3-D graphics library
8 * Version: 3.5
9 *
10 * The MIT License
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:
17 *
18 * The above copyright notice and this permission notice shall be included
19 * in all copies or substantial portions of the Software.
20 *
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.
28 */
29
30 /*
31 modification history
32 --------------------
33 02a,29aug01,sra WindML mode added
34 01a,17jul01,sra written
35 */
36
37 /*
38 DESCRIPTION
39 Show all the UGL/Mesa demos
40 */
41
42 #include <stdio.h>
43 #include <vxWorks.h>
44 #include <taskLib.h>
45 #include <ugl/ugl.h>
46 #include <ugl/uglinput.h>
47 #include <ugl/uglevent.h>
48 #include <ugl/uglfont.h>
49
50 #define BLACK 0
51 #define RED 1
52
53 struct _colorStruct
54 {
55 UGL_RGB rgbColor;
56 UGL_COLOR uglColor;
57 }
58 colorTable[] =
59 {
60 { UGL_MAKE_RGB(0, 0, 0), 0},
61 { UGL_MAKE_RGB(255, 0, 0), 0},
62 };
63
64 void windMLPoint (UGL_BOOL windMLMode);
65 void windMLLine (UGL_BOOL windMLMode);
66 void windMLFlip (UGL_BOOL windMLMode);
67 void windMLCube (UGL_BOOL windMLMode);
68 void windMLBounce (UGL_BOOL windMLMode);
69 void windMLGears (UGL_BOOL windMLMode);
70 void windMLIcoTorus (UGL_BOOL windMLMode);
71 void windMLOlympic (UGL_BOOL windMLMode);
72 void windMLTexCube (UGL_BOOL windMLMode);
73 void windMLTexCyl (UGL_BOOL windMLMode);
74 void windMLTeapot (UGL_BOOL windMLMode);
75 void windMLStencil (UGL_BOOL windMLMode);
76 void windMLDrawPix (UGL_BOOL windMLMode);
77 void windMLAccum (UGL_BOOL windMLMode);
78 void windMLAllDemos (void);
79
80 void uglalldemos (void)
81 {
82 taskSpawn("tAllDemos", 210, VX_FP_TASK, 200000,
83 (FUNCPTR)windMLAllDemos, 0,1,2,3,4,5,6,7,8,9);
84 }
85
86 void windMLAllDemos(void)
87 {
88 UGL_BOOL windMLFlag = UGL_FALSE;
89 UGL_FB_INFO fbInfo;
90 UGL_EVENT event;
91 UGL_EVENT_SERVICE_ID eventServiceId;
92 UGL_EVENT_Q_ID qId;
93 UGL_INPUT_EVENT * pInputEvent;
94 UGL_INPUT_DEVICE_ID keyboardDevId;
95 UGL_DEVICE_ID devId;
96 UGL_GC_ID gc;
97 UGL_FONT_ID fontId;
98 UGL_FONT_DEF fontDef;
99 UGL_FONT_DRIVER_ID fontDrvId;
100 UGL_ORD textOrigin = UGL_FONT_TEXT_UPPER_LEFT;
101 int displayHeight, displayWidth;
102 int textWidth, textHeight;
103 static UGL_CHAR * message =
104 "Do you want to use WindML exclusively ? (y/n) ";
105
106 uglInitialize();
107
108 uglDriverFind (UGL_DISPLAY_TYPE, 0, (UGL_UINT32 *)&devId);
109 uglDriverFind (UGL_KEYBOARD_TYPE, 0, (UGL_UINT32 *)&keyboardDevId);
110 uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, (UGL_UINT32 *)&eventServiceId);
111 qId = uglEventQCreate (eventServiceId, 100);
112
113 gc = uglGcCreate(devId);
114
115 uglDriverFind (UGL_FONT_ENGINE_TYPE, 0, (UGL_UINT32 *)&fontDrvId);
116 uglFontDriverInfo(fontDrvId, UGL_FONT_TEXT_ORIGIN, &textOrigin);
117
118 uglFontFindString(fontDrvId, "familyName=Helvetica; pixelSize = 18",
119 &fontDef);
120
121 if ((fontId = uglFontCreate(fontDrvId, &fontDef)) == UGL_NULL)
122 {
123 printf("Font not found. Exiting.\n");
124 return;
125 }
126
127 uglInfo(devId, UGL_FB_INFO_REQ, &fbInfo);
128 displayWidth = fbInfo.width;
129 displayHeight = fbInfo.height;
130
131 uglColorAlloc (devId, &colorTable[BLACK].rgbColor, UGL_NULL,
132 &colorTable[BLACK].uglColor, 1);
133 uglColorAlloc(devId, &colorTable[RED].rgbColor, UGL_NULL,
134 &colorTable[RED].uglColor, 1);
135
136 uglBackgroundColorSet(gc, colorTable[BLACK].uglColor);
137 uglForegroundColorSet(gc, colorTable[RED].uglColor);
138 uglFontSet(gc, fontId);
139 uglTextSizeGet(fontId, &textWidth, &textHeight, -1, message);
140 uglTextDraw(gc, (displayWidth - textWidth) / 2,
141 (displayHeight - textHeight) / 2 - textHeight, -1, message);
142 /* flushQ();
143 */
144 if (uglEventGet (qId, &event, sizeof (event), UGL_WAIT_FOREVER)
145 != UGL_STATUS_Q_EMPTY)
146 {
147 pInputEvent = (UGL_INPUT_EVENT *)&event;
148
149 if (pInputEvent->header.type == UGL_EVENT_TYPE_KEYBOARD &&
150 pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN)
151 {
152 switch(pInputEvent->type.keyboard.key)
153 {
154 case 'Y':
155 case 'y':
156 windMLFlag = UGL_TRUE;
157 break;
158 default:
159 windMLFlag = UGL_FALSE;
160 }
161 }
162 }
163
164 uglFontDestroy (fontId);
165 uglGcDestroy (gc);
166 uglEventQDestroy (eventServiceId, qId);
167 uglDeinitialize();
168
169 windMLPoint(windMLFlag);
170
171 windMLLine(windMLFlag);
172
173 windMLFlip(windMLFlag);
174
175 windMLCube(windMLFlag);
176
177 windMLBounce(windMLFlag);
178
179 windMLGears(windMLFlag);
180
181 windMLIcoTorus(windMLFlag);
182
183 windMLOlympic(windMLFlag);
184
185 windMLTexCube(windMLFlag);
186
187 windMLTexCyl(windMLFlag);
188
189 windMLTeapot(windMLFlag);
190
191 windMLStencil(windMLFlag);
192
193 windMLDrawPix(windMLFlag);
194
195 windMLAccum(windMLFlag);
196
197 return;
198 }