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
31 #define CI_OFFSET_1 16
32 #define CI_OFFSET_2 32
35 GLenum rgb
, doubleBuffer
;
37 GLenum antiAlias
, stipple
;
38 GLubyte stippleBits
[32*4] = {
39 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
40 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
41 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
42 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
43 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
44 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
45 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
46 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
47 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
48 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
49 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
50 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
51 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
52 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
53 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
54 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
60 static void Init(void)
64 glClearColor(0.0, 0.0, 0.0, 0.0);
68 for (i
= 0; i
< 16; i
++) {
69 glutSetColor(i
+CI_OFFSET_1
, 0.0, 0.0, i
/15.0);
70 glutSetColor(i
+CI_OFFSET_2
, 0.0, i
/15.0, 0.0);
74 glPolygonStipple(stippleBits
);
80 static void Reshape(int width
, int height
)
83 glViewport(0, 0, (GLint
)width
, (GLint
)height
);
85 glMatrixMode(GL_PROJECTION
);
87 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
88 glMatrixMode(GL_MODELVIEW
);
91 static void Key(unsigned char key
, int x
, int y
)
98 antiAlias
= !antiAlias
;
110 static void Draw(void)
114 glClear(GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
119 glBlendFunc(GL_SRC_ALPHA
, GL_ONE
);
121 glEnable(GL_POLYGON_SMOOTH
);
122 glDisable(GL_DEPTH_TEST
);
127 glDisable(GL_POLYGON_SMOOTH
);
128 glEnable(GL_DEPTH_TEST
);
132 glEnable(GL_POLYGON_STIPPLE
);
134 glDisable(GL_POLYGON_STIPPLE
);
137 glBegin(GL_TRIANGLES
);
138 (rgb
) ? glColor3fv(RGBMap
[COLOR_BLUE
]) : glIndexi(ci1
);
139 glVertex3f( 0.9, -0.9, -30.0);
140 glVertex3f( 0.9, 0.9, -30.0);
141 glVertex3f(-0.9, 0.0, -30.0);
142 (rgb
) ? glColor3fv(RGBMap
[COLOR_GREEN
]) : glIndexi(ci2
);
143 glVertex3f(-0.9, -0.9, -40.0);
144 glVertex3f(-0.9, 0.9, -40.0);
145 glVertex3f( 0.9, 0.0, -25.0);
155 static GLenum
Args(int argc
, char **argv
)
160 doubleBuffer
= GL_FALSE
;
162 for (i
= 1; i
< argc
; i
++) {
163 if (strcmp(argv
[i
], "-ci") == 0) {
165 } else if (strcmp(argv
[i
], "-rgb") == 0) {
167 } else if (strcmp(argv
[i
], "-sb") == 0) {
168 doubleBuffer
= GL_FALSE
;
169 } else if (strcmp(argv
[i
], "-db") == 0) {
170 doubleBuffer
= GL_TRUE
;
172 printf("%s (Bad option).\n", argv
[i
]);
179 int main(int argc
, char **argv
)
183 glutInit(&argc
, argv
);
185 if (Args(argc
, argv
) == GL_FALSE
) {
189 glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300);
192 type
|= (rgb
) ? GLUT_RGB
: GLUT_INDEX
;
193 type
|= (doubleBuffer
) ? GLUT_DOUBLE
: GLUT_SINGLE
;
194 glutInitDisplayMode(type
);
196 if (glutCreateWindow("Depth Test") == GL_FALSE
) {
204 glutReshapeFunc(Reshape
);
205 glutKeyboardFunc(Key
);
206 glutDisplayFunc(Draw
);