2 * Mesa 3-D graphics library
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
26 * Linux Magazine July 2001
27 * Conversion to UGL/Mesa from GLUT by Stephane Raimbault, 2001
35 #include <ugl/uglevent.h>
36 #include <ugl/uglinput.h>
37 #include <ugl/uglucode.h>
39 #include <GL/uglmesa.h>
42 /* Need GLUT_SHAPES */
44 #include <GL/uglglutshapes.h>
50 UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId
;
51 UGL_LOCAL UGL_EVENT_Q_ID qId
;
52 UGL_LOCAL UGL_MESA_CONTEXT umc
;
53 UGL_LOCAL
volatile UGL_BOOL stopWex
;
55 UGL_LOCAL GLint angle
;
56 UGL_LOCAL GLfloat Sin
[360], Cos
[360];
57 UGL_LOCAL GLfloat L0pos
[]={0.0, 2.0, -1.0};
58 UGL_LOCAL GLfloat L0dif
[]={0.3, 0.3, 0.8};
59 UGL_LOCAL GLfloat L1pos
[]={2.0, 2.0, 2.0};
60 UGL_LOCAL GLfloat L1dif
[]={0.5, 0.5, 0.5};
61 UGL_LOCAL GLfloat Mspec
[3];
62 UGL_LOCAL GLfloat Mshiny
;
63 UGL_LOCAL GLuint theTeapot
;
65 UGL_LOCAL
void calcTableCosSin()
69 Cos
[i
] = cos(((float)i
)/180.0*PI
);
70 Sin
[i
] = sin(((float)i
)/180.0*PI
);
74 UGL_LOCAL
void initGL(void)
76 glClearColor(0.0, 0.0, 0.0, 0.0);
77 glColor3f(1.0, 0.0, 0.0);
78 glEnable(GL_DEPTH_TEST
);
80 glShadeModel(GL_SMOOTH
);
81 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER
, GL_TRUE
);
82 glEnable(GL_LIGHTING
);
85 glLightfv(GL_LIGHT0
, GL_DIFFUSE
, L0dif
);
86 glLightfv(GL_LIGHT0
, GL_SPECULAR
, L0dif
);
87 glLightfv(GL_LIGHT1
, GL_DIFFUSE
, L1dif
);
88 glLightfv(GL_LIGHT1
, GL_SPECULAR
, L1dif
);
90 glMaterialfv(GL_FRONT_AND_BACK
, GL_SPECULAR
, Mspec
);
91 glMaterialf(GL_FRONT_AND_BACK
, GL_SHININESS
, Mshiny
);
93 glMatrixMode(GL_PROJECTION
);
95 gluPerspective(45.0, 1.0, 0.1, 10.0);
96 glMatrixMode(GL_MODELVIEW
);
98 theTeapot
= glGenLists(1);
99 glNewList(theTeapot
, GL_COMPILE
);
100 glutSolidTeapot(1.0);
105 UGL_LOCAL
void drawGL()
107 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
111 gluLookAt(4.5*Cos
[angle
], 2.0,4.5*Sin
[angle
],0.0,0.0,0.0,0.0,
113 glLightfv(GL_LIGHT0
, GL_POSITION
, L0pos
);
114 glLightfv(GL_LIGHT1
, GL_POSITION
, L1pos
);
116 glCallList(theTeapot
);
120 uglMesaSwapBuffers();
123 UGL_LOCAL
void echoUse(void)
125 printf("tTeapot keys:\n");
126 printf(" Left Counter clockwise rotation (y-axis)\n");
127 printf(" Right Clockwise rotation (y-axis)\n");
128 printf(" j Enable/disable Light0\n");
129 printf(" k Enable/disable Light1\n");
130 printf(" m Add specular\n");
131 printf(" l Remove specular\n");
132 printf(" o Add shininess\n");
133 printf(" p Remove shininess\n");
134 printf(" ESC Exit\n");
138 UGL_LOCAL
void readKey (UGL_WCHAR key
)
142 case UGL_UNI_RIGHT_ARROW
:
147 case UGL_UNI_LEFT_ARROW
:
153 glIsEnabled(GL_LIGHT0
) ?
154 glDisable(GL_LIGHT0
) : glEnable(GL_LIGHT0
);
157 glIsEnabled(GL_LIGHT1
) ?
158 glDisable(GL_LIGHT1
) : glEnable(GL_LIGHT1
);
170 glMaterialfv(GL_FRONT_AND_BACK
, GL_SPECULAR
, Mspec
);
182 glMaterialfv(GL_FRONT_AND_BACK
, GL_SPECULAR
, Mspec
);
188 glMaterialf(GL_FRONT_AND_BACK
, GL_SHININESS
, Mshiny
);
194 glMaterialf(GL_FRONT_AND_BACK
, GL_SHININESS
, Mshiny
);
202 UGL_LOCAL
void loopEvent(void)
205 UGL_INPUT_EVENT
* pInputEvent
;
209 if (uglEventGet (qId
, &event
, sizeof (event
), UGL_NO_WAIT
)
210 != UGL_STATUS_Q_EMPTY
)
212 pInputEvent
= (UGL_INPUT_EVENT
*)&event
;
214 if (pInputEvent
->header
.type
== UGL_EVENT_TYPE_KEYBOARD
&&
215 pInputEvent
->modifiers
& UGL_KEYBOARD_KEYDOWN
)
216 readKey(pInputEvent
->type
.keyboard
.key
);
225 void windMLTeapot (UGL_BOOL windMLMode
);
227 void uglteapot (void)
229 taskSpawn ("tTeapot", 210, VX_FP_TASK
, 100000, (FUNCPTR
)windMLTeapot
,
230 UGL_FALSE
,1,2,3,4,5,6,7,8,9);
233 void windMLTeapot (UGL_BOOL windMLMode
)
235 UGL_INPUT_DEVICE_ID keyboardDevId
;
236 GLsizei displayWidth
, displayHeight
;
247 uglDriverFind (UGL_KEYBOARD_TYPE
, 0,
248 (UGL_UINT32
*)&keyboardDevId
);
250 uglDriverFind (UGL_EVENT_SERVICE_TYPE
, 0, (UGL_UINT32
*)&eventServiceId
);
252 qId
= uglEventQCreate (eventServiceId
, 100);
254 /* Double buffering */
256 umc
= uglMesaCreateNewContext(UGL_MESA_DOUBLE
257 | UGL_MESA_WINDML_EXCLUSIVE
, NULL
);
259 umc
= uglMesaCreateNewContext(UGL_MESA_DOUBLE
, NULL
);
267 uglMesaMakeCurrentContext (umc
, 0, 0, 1, 1);
269 uglMesaGetIntegerv(UGL_MESA_DISPLAY_WIDTH
, &displayWidth
);
270 uglMesaGetIntegerv(UGL_MESA_DISPLAY_HEIGHT
, &displayHeight
);
272 h
= (displayHeight
*2)/3;
274 x
= (displayWidth
-w
)/2;
275 y
= (displayHeight
-h
)/2;
277 uglMesaMoveToWindow(x
, y
);
278 uglMesaResizeToWindow(w
, h
);
289 uglEventQDestroy (eventServiceId
, qId
);
291 uglMesaDestroyContext();