2 /* Copyright (c) Mark J. Kilgard, 1994. */
5 * (c) Copyright 1993, Silicon Graphics, Inc.
7 * Permission to use, copy, modify, and distribute this software for
8 * any purpose and without fee is hereby granted, provided that the above
9 * copyright notice appear in all copies and that both the copyright notice
10 * and this permission notice appear in supporting documentation, and that
11 * the name of Silicon Graphics, Inc. not be used in advertising
12 * or publicity pertaining to distribution of the software without specific,
13 * written prior permission.
15 * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
16 * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
18 * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19 * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
20 * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
21 * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
22 * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
23 * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
24 * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
25 * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
26 * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
28 * US Government Users Restricted Rights
29 * Use, duplication, or disclosure by the Government is subject to
30 * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
31 * (c)(1)(ii) of the Rights in Technical Data and Computer Software
32 * clause at DFARS 252.227-7013 and/or in similar or successor
33 * clauses in the FAR or the DOD or NASA FAR Supplement.
34 * Unpublished-- rights reserved under the copyright laws of the
35 * United States. Contractor/manufacturer is Silicon Graphics,
36 * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
38 * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
41 /* Original name: accanti.c
43 * Conversion to UGL/Mesa by Stephane Raimbault
50 #include <ugl/uglevent.h>
51 #include <ugl/uglinput.h>
53 #include <GL/uglmesa.h>
54 #include <GL/uglglutshapes.h>
56 #include "../book/jitter.h"
58 UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId
;
59 UGL_LOCAL UGL_EVENT_Q_ID qId
;
60 UGL_LOCAL UGL_MESA_CONTEXT umc
;
62 /* Initialize lighting and other values.
64 UGL_LOCAL
void initGL(GLsizei w
, GLsizei h
)
66 GLfloat mat_ambient
[] = { 1.0, 1.0, 1.0, 1.0 };
67 GLfloat mat_specular
[] = { 1.0, 1.0, 1.0, 1.0 };
68 GLfloat light_position
[] = { 0.0, 0.0, 10.0, 1.0 };
69 GLfloat lm_ambient
[] = { 0.2, 0.2, 0.2, 1.0 };
71 glMaterialfv(GL_FRONT
, GL_AMBIENT
, mat_ambient
);
72 glMaterialfv(GL_FRONT
, GL_SPECULAR
, mat_specular
);
73 glMaterialf(GL_FRONT
, GL_SHININESS
, 50.0);
74 glLightfv(GL_LIGHT0
, GL_POSITION
, light_position
);
75 glLightModelfv(GL_LIGHT_MODEL_AMBIENT
, lm_ambient
);
77 glEnable(GL_LIGHTING
);
80 glEnable(GL_DEPTH_TEST
);
81 glShadeModel (GL_FLAT
);
83 glClearColor(0.0, 0.0, 0.0, 0.0);
84 glClearAccum(0.0, 0.0, 0.0, 0.0);
86 glMatrixMode(GL_PROJECTION
);
89 glOrtho (-2.25, 2.25, -2.25*h
/w
, 2.25*h
/w
, -10.0, 10.0);
91 glOrtho (-2.25*w
/h
, 2.25*w
/h
, -2.25, 2.25, -10.0, 10.0);
92 glMatrixMode(GL_MODELVIEW
);
95 UGL_LOCAL
void displayObjects(void)
97 GLfloat torus_diffuse
[] = { 0.7, 0.7, 0.0, 1.0 };
98 GLfloat cube_diffuse
[] = { 0.0, 0.7, 0.7, 1.0 };
99 GLfloat sphere_diffuse
[] = { 0.7, 0.0, 0.7, 1.0 };
100 GLfloat octa_diffuse
[] = { 0.7, 0.4, 0.4, 1.0 };
103 glRotatef (30.0, 1.0, 0.0, 0.0);
106 glTranslatef (-0.80, 0.35, 0.0);
107 glRotatef (100.0, 1.0, 0.0, 0.0);
108 glMaterialfv(GL_FRONT
, GL_DIFFUSE
, torus_diffuse
);
109 glutSolidTorus (0.275, 0.85, 16, 16);
113 glTranslatef (-0.75, -0.50, 0.0);
114 glRotatef (45.0, 0.0, 0.0, 1.0);
115 glRotatef (45.0, 1.0, 0.0, 0.0);
116 glMaterialfv(GL_FRONT
, GL_DIFFUSE
, cube_diffuse
);
121 glTranslatef (0.75, 0.60, 0.0);
122 glRotatef (30.0, 1.0, 0.0, 0.0);
123 glMaterialfv(GL_FRONT
, GL_DIFFUSE
, sphere_diffuse
);
124 glutSolidSphere (1.0, 16, 16);
128 glTranslatef (0.70, -0.90, 0.25);
129 glMaterialfv(GL_FRONT
, GL_DIFFUSE
, octa_diffuse
);
130 glutSolidOctahedron ();
138 UGL_LOCAL
void drawGL(void)
143 glGetIntegerv (GL_VIEWPORT
, viewport
);
145 glClear(GL_ACCUM_BUFFER_BIT
);
146 for (jitter
= 0; jitter
< ACSIZE
; jitter
++)
148 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
150 /* Note that 4.5 is the distance in world space between
151 * left and right and bottom and top.
152 * This formula converts fractional pixel movement to
155 glTranslatef (j8
[jitter
].x
*4.5/viewport
[2],
156 j8
[jitter
].y
*4.5/viewport
[3], 0.0);
159 glAccum(GL_ACCUM
, 1.0/ACSIZE
);
161 glAccum (GL_RETURN
, 1.0);
164 uglMesaSwapBuffers();
167 UGL_LOCAL
int getEvent(void)
173 status
= uglEventGet (qId
, &event
, sizeof (event
), UGL_NO_WAIT
);
175 while (status
!= UGL_STATUS_Q_EMPTY
)
177 UGL_INPUT_EVENT
* pInputEvent
= (UGL_INPUT_EVENT
*)&event
;
179 if (pInputEvent
->modifiers
& UGL_KEYBOARD_KEYDOWN
)
182 status
= uglEventGet (qId
, &event
, sizeof (event
), UGL_NO_WAIT
);
188 void windMLAccum (UGL_BOOL windMLMode
);
192 taskSpawn("tAccum", 210, VX_FP_TASK
, 100000,
193 (FUNCPTR
)windMLAccum
,UGL_FALSE
,1,2,3,4,5,6,7,8,9);
196 void windMLAccum (UGL_BOOL windMLMode
)
198 UGL_INPUT_DEVICE_ID keyboardDevId
;
199 GLsizei width
, height
;
203 uglDriverFind (UGL_KEYBOARD_TYPE
, 0, (UGL_UINT32
*)&keyboardDevId
);
205 uglDriverFind (UGL_EVENT_SERVICE_TYPE
, 0, (UGL_UINT32
*)&eventServiceId
);
207 qId
= uglEventQCreate (eventServiceId
, 100);
210 umc
= uglMesaCreateNewContextExt(UGL_MESA_DOUBLE
211 | UGL_MESA_WINDML_EXCLUSIVE
,
217 umc
= uglMesaCreateNewContextExt(UGL_MESA_DOUBLE
,
231 uglMesaMakeCurrentContext(umc
, 0, 0,
232 UGL_MESA_FULLSCREEN_WIDTH
,
233 UGL_MESA_FULLSCREEN_HEIGHT
);
235 uglMesaGetIntegerv(UGL_MESA_WIDTH
, &width
);
236 uglMesaGetIntegerv(UGL_MESA_HEIGHT
, &height
);
238 initGL(width
, height
);
244 uglEventQDestroy (eventServiceId
, qId
);
246 uglMesaDestroyContext();