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 * This program draws two rotated tori in a window.
42 * A diamond in the center of the window masks out part
43 * of the scene. Within this mask, a different model
44 * (a sphere) is drawn in a different color.
48 * Conversion to UGL/Mesa by Stephane Raimbault, 2001
55 #include <ugl/uglevent.h>
56 #include <ugl/uglinput.h>
58 #include <GL/uglmesa.h>
60 #include <GL/uglglutshapes.h>
65 UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId
;
66 UGL_LOCAL UGL_EVENT_Q_ID qId
;
67 UGL_LOCAL UGL_MESA_CONTEXT umc
;
69 UGL_LOCAL
void initGL (GLsizei w
, GLsizei h
)
71 GLfloat yellow_diffuse
[] = { 0.7, 0.7, 0.0, 1.0 };
72 GLfloat yellow_specular
[] = { 1.0, 1.0, 1.0, 1.0 };
74 GLfloat blue_diffuse
[] = { 0.1, 0.1, 0.7, 1.0 };
75 GLfloat blue_specular
[] = { 0.1, 1.0, 1.0, 1.0 };
77 GLfloat position_one
[] = { 1.0, 1.0, 1.0, 0.0 };
79 glNewList(YELLOWMAT
, GL_COMPILE
);
80 glMaterialfv(GL_FRONT
, GL_DIFFUSE
, yellow_diffuse
);
81 glMaterialfv(GL_FRONT
, GL_SPECULAR
, yellow_specular
);
82 glMaterialf(GL_FRONT
, GL_SHININESS
, 64.0);
85 glNewList(BLUEMAT
, GL_COMPILE
);
86 glMaterialfv(GL_FRONT
, GL_DIFFUSE
, blue_diffuse
);
87 glMaterialfv(GL_FRONT
, GL_SPECULAR
, blue_specular
);
88 glMaterialf(GL_FRONT
, GL_SHININESS
, 45.0);
91 glLightfv(GL_LIGHT0
, GL_POSITION
, position_one
);
94 glEnable(GL_LIGHTING
);
96 glEnable(GL_DEPTH_TEST
);
99 glEnable(GL_STENCIL_TEST
);
101 glClear(GL_STENCIL_BUFFER_BIT
);
103 /* create a diamond shaped stencil area */
104 glMatrixMode(GL_PROJECTION
);
106 glOrtho(-3.0, 3.0, -3.0, 3.0, -1.0, 1.0);
107 glMatrixMode(GL_MODELVIEW
);
110 glStencilFunc (GL_ALWAYS
, 0x1, 0x1);
111 glStencilOp (GL_REPLACE
, GL_REPLACE
, GL_REPLACE
);
113 glVertex3f (-1.0, 0.0, 0.0);
114 glVertex3f (0.0, 1.0, 0.0);
115 glVertex3f (1.0, 0.0, 0.0);
116 glVertex3f (0.0, -1.0, 0.0);
119 glMatrixMode(GL_PROJECTION
);
121 gluPerspective(45.0, (GLfloat
) w
/(GLfloat
) h
, 3.0, 7.0);
122 glMatrixMode(GL_MODELVIEW
);
124 glTranslatef(0.0, 0.0, -5.0);
127 /* Draw a sphere in a diamond-shaped section in the
128 * middle of a window with 2 tori.
130 UGL_LOCAL
void drawGL(void)
132 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
134 glStencilOp (GL_KEEP
, GL_KEEP
, GL_KEEP
);
136 /* draw blue sphere where the stencil is 1 */
137 glStencilFunc (GL_EQUAL
, 0x1, 0x1);
138 glCallList (BLUEMAT
);
139 glutSolidSphere (0.5, 15, 15);
141 /* draw the tori where the stencil is not 1 */
142 glStencilFunc (GL_NOTEQUAL
, 0x1, 0x1);
144 glRotatef (45.0, 0.0, 0.0, 1.0);
145 glRotatef (45.0, 0.0, 1.0, 0.0);
146 glCallList (YELLOWMAT
);
147 glutSolidTorus (0.275, 0.85, 15, 15);
149 glRotatef (90.0, 1.0, 0.0, 0.0);
150 glutSolidTorus (0.275, 0.85, 15, 15);
156 uglMesaSwapBuffers();
159 UGL_LOCAL
int getEvent(void)
165 status
= uglEventGet (qId
, &event
, sizeof (event
), UGL_NO_WAIT
);
167 while (status
!= UGL_STATUS_Q_EMPTY
)
169 UGL_INPUT_EVENT
* pInputEvent
= (UGL_INPUT_EVENT
*)&event
;
171 if (pInputEvent
->modifiers
& UGL_KEYBOARD_KEYDOWN
)
174 status
= uglEventGet (qId
, &event
, sizeof (event
), UGL_NO_WAIT
);
180 void windMLStencil (UGL_BOOL windMLMode
);
182 void uglstencil (void)
184 taskSpawn("tStencil", 210, VX_FP_TASK
, 100000,
185 (FUNCPTR
)windMLStencil
,UGL_FALSE
,1,2,3,4,5,6,7,8,9);
188 void windMLStencil(UGL_BOOL windMLMode
)
190 UGL_INPUT_DEVICE_ID keyboardDevId
;
191 GLsizei width
, height
;
195 uglDriverFind (UGL_KEYBOARD_TYPE
, 0, (UGL_UINT32
*)&keyboardDevId
);
197 uglDriverFind (UGL_EVENT_SERVICE_TYPE
, 0, (UGL_UINT32
*)&eventServiceId
);
199 qId
= uglEventQCreate (eventServiceId
, 100);
202 umc
= uglMesaCreateNewContextExt(UGL_MESA_SINGLE
203 | UGL_MESA_WINDML_EXCLUSIVE
,
209 umc
= uglMesaCreateNewContextExt(UGL_MESA_SINGLE
,
223 uglMesaMakeCurrentContext(umc
, 0, 0, UGL_MESA_FULLSCREEN_WIDTH
,
224 UGL_MESA_FULLSCREEN_HEIGHT
);
226 uglMesaGetIntegerv(UGL_MESA_WIDTH
, &width
);
227 uglMesaGetIntegerv(UGL_MESA_HEIGHT
, &height
);
229 initGL(width
, height
);
235 uglEventQDestroy (eventServiceId
, qId
);
237 uglMesaDestroyContext();