2 * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc.
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that (i) the above copyright notices and this permission notice appear in
7 * all copies of the software and related documentation, and (ii) the name of
8 * Silicon Graphics may not be used in any advertising or
9 * publicity relating to the software without the specific, prior written
10 * permission of Silicon Graphics.
12 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF
14 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
17 * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR
18 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
21 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
36 GLenum rgb
, doubleBuffer
, windType
;
39 GLenum dithering
= GL_TRUE
;
40 GLenum showVerticies
= GL_TRUE
;
41 GLenum hideBottomTriangle
= GL_FALSE
;
42 GLenum outline
= GL_TRUE
;
43 GLenum culling
= GL_FALSE
;
44 GLenum winding
= GL_FALSE
;
45 GLenum face
= GL_FALSE
;
47 GLenum aaMode
= GL_FALSE
;
48 GLenum shade
= GL_TRUE
;
50 GLint color1
, color2
, color3
;
52 float zRotation
= 90.0;
55 float boxA
[3] = {-100, -100, 0};
56 float boxB
[3] = { 100, -100, 0};
57 float boxC
[3] = { 100, 100, 0};
58 float boxD
[3] = {-100, 100, 0};
60 float p0
[3] = {-125,-80, 0};
61 float p1
[3] = {-125, 80, 0};
62 float p2
[3] = { 172, 0, 0};
67 static void Init(void)
70 float percent1
, percent2
;
73 glClearColor(0.0, 0.0, 0.0, 0.0);
75 glLineStipple(1, 0xF0F0);
77 glEnable(GL_SCISSOR_TEST
);
80 for (j
= 0; j
<= 12; j
++) {
83 r
= 1.0 - 0.8 * percent1
;
84 g
= 0.2 + 0.8 * percent1
;
87 percent1
= (j
- 6) / 6.0;
89 g
= 1.0 - 0.8 * percent1
;
90 b
= 0.2 + 0.8 * percent1
;
92 glutSetColor(j
+18, r
, g
, b
);
93 for (i
= 0; i
< 16; i
++) {
95 glutSetColor(j
*16+1+32, r
*percent2
, g
*percent2
, b
*percent2
);
104 static void Reshape(int width
, int height
)
107 windW
= (GLint
)width
;
108 windH
= (GLint
)height
;
111 static void Key2(int key
, int x
, int y
)
128 static void Key(unsigned char key
, int x
, int y
)
144 glPolygonMode(GL_FRONT_AND_BACK
, GL_POINT
);
147 glPolygonMode(GL_FRONT_AND_BACK
, GL_LINE
);
150 glPolygonMode(GL_FRONT_AND_BACK
, GL_FILL
);
171 showVerticies
= !showVerticies
;
175 (shade
) ? glShadeModel(GL_SMOOTH
) : glShadeModel(GL_FLAT
);
178 hideBottomTriangle
= !hideBottomTriangle
;
184 dithering
= !dithering
;
189 glEnable(GL_POLYGON_SMOOTH
);
191 glBlendFunc(GL_SRC_ALPHA
, GL_ONE
);
198 glDisable(GL_POLYGON_SMOOTH
);
214 static void BeginPrim(void)
222 glBegin(GL_LINE_LOOP
);
232 static void EndPrim(void)
238 static void Draw(void)
240 float scaleX
, scaleY
;
242 glViewport(0, 0, windW
, windH
);
244 glMatrixMode(GL_PROJECTION
);
246 gluOrtho2D(-175, 175, -175, 175);
247 glMatrixMode(GL_MODELVIEW
);
249 glScissor(0, 0, windW
, windH
);
251 (culling
) ? glEnable(GL_CULL_FACE
) : glDisable(GL_CULL_FACE
);
252 (winding
) ? glFrontFace(GL_CCW
) : glFrontFace(GL_CW
);
253 (face
) ? glCullFace(GL_FRONT
) : glCullFace(GL_BACK
);
255 (dithering
) ? glEnable(GL_DITHER
) : glDisable(GL_DITHER
);
257 glClear(GL_COLOR_BUFFER_BIT
);
259 SetColor(COLOR_GREEN
);
260 glBegin(GL_LINE_LOOP
);
267 if (!hideBottomTriangle
) {
270 glScalef(zoom
, zoom
, zoom
);
271 glRotatef(zRotation
, 0, 0, 1);
273 SetColor(COLOR_BLUE
);
281 (rgb
) ? glColor3fv(RGBMap
[COLOR_RED
]) : glIndexf(color1
);
282 glRectf(p0
[0]-2, p0
[1]-2, p0
[0]+2, p0
[1]+2);
283 (rgb
) ? glColor3fv(RGBMap
[COLOR_GREEN
]) : glIndexf(color2
);
284 glRectf(p1
[0]-2, p1
[1]-2, p1
[0]+2, p1
[1]+2);
285 (rgb
) ? glColor3fv(RGBMap
[COLOR_BLUE
]) : glIndexf(color3
);
286 glRectf(p2
[0]-2, p2
[1]-2, p2
[0]+2, p2
[1]+2);
292 scaleX
= (float)(windW
- 20) / 2 / 175 * (175 - 100) + 10;
293 scaleY
= (float)(windH
- 20) / 2 / 175 * (175 - 100) + 10;
295 glViewport(scaleX
, scaleY
, windW
-2*scaleX
, windH
-2*scaleY
);
297 glMatrixMode(GL_PROJECTION
);
299 gluOrtho2D(-100, 100, -100, 100);
300 glMatrixMode(GL_MODELVIEW
);
302 glScissor(scaleX
, scaleY
, windW
-2*scaleX
, windH
-2*scaleY
);
306 glScalef(zoom
, zoom
, zoom
);
307 glRotatef(zRotation
, 0,0,1);
311 glEnable(GL_POINT_SMOOTH
);
312 glEnable(GL_LINE_STIPPLE
);
313 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
317 (rgb
) ? glColor3fv(RGBMap
[COLOR_RED
]) : glIndexf(color1
);
319 (rgb
) ? glColor3fv(RGBMap
[COLOR_GREEN
]) : glIndexf(color2
);
321 (rgb
) ? glColor3fv(RGBMap
[COLOR_BLUE
]) : glIndexf(color3
);
327 glDisable(GL_POINT_SMOOTH
);
328 glDisable(GL_LINE_STIPPLE
);
329 glBlendFunc(GL_ONE
, GL_ZERO
);
332 SetColor(COLOR_WHITE
);
333 glBegin(GL_LINE_LOOP
);
349 static GLenum
Args(int argc
, char **argv
)
354 doubleBuffer
= GL_FALSE
;
356 for (i
= 1; i
< argc
; i
++) {
357 if (strcmp(argv
[i
], "-ci") == 0) {
359 } else if (strcmp(argv
[i
], "-rgb") == 0) {
361 } else if (strcmp(argv
[i
], "-sb") == 0) {
362 doubleBuffer
= GL_FALSE
;
363 } else if (strcmp(argv
[i
], "-db") == 0) {
364 doubleBuffer
= GL_TRUE
;
366 printf("%s (Bad option).\n", argv
[i
]);
373 int main(int argc
, char **argv
)
375 glutInit(&argc
, argv
);
377 if (Args(argc
, argv
) == GL_FALSE
) {
383 glutInitWindowPosition(0, 0); glutInitWindowSize( windW
, windH
);
385 windType
= (rgb
) ? GLUT_RGB
: GLUT_INDEX
;
386 windType
|= (doubleBuffer
) ? GLUT_DOUBLE
: GLUT_SINGLE
;
387 glutInitDisplayMode(windType
);
389 if (glutCreateWindow("Triangle Test") == GL_FALSE
) {
397 glutReshapeFunc(Reshape
);
398 glutKeyboardFunc(Key
);
399 glutSpecialFunc(Key2
);
400 glutDisplayFunc(Draw
);