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
32 static void Init(void)
36 static void Reshape(int width
, int height
)
39 glViewport(0, 0, (GLint
)width
, (GLint
)height
);
41 glMatrixMode(GL_PROJECTION
);
43 glOrtho(-5.0, 5.0, -5.0, 5.0, -5.0, 5.0);
44 glMatrixMode(GL_MODELVIEW
);
47 static void Key(unsigned char key
, int x
, int y
)
56 static void Draw(void)
58 glShadeModel(GL_FLAT
);
61 glClearColor(0.0, 0.0, 0.0, 0.0);
63 glClear(GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
|GL_STENCIL_BUFFER_BIT
);
68 glEnable(GL_STENCIL_TEST
);
69 glStencilFunc(GL_ALWAYS
, 1, 1);
70 glStencilOp(GL_KEEP
, GL_KEEP
, GL_REPLACE
);
72 glColor3ub(200, 0, 0);
74 glVertex3i(-4, -4, 0);
75 glVertex3i( 4, -4, 0);
80 glStencilFunc(GL_EQUAL
, 1, 1);
81 glStencilOp(GL_INCR
, GL_KEEP
, GL_DECR
);
83 glColor3ub(0, 200, 0);
87 glVertex3i(-3, -3, 0);
93 glStencilFunc(GL_EQUAL
, 1, 1);
94 glStencilOp(GL_KEEP
, GL_KEEP
, GL_KEEP
);
96 glColor3ub(0, 0, 200);
98 glVertex3f(2.5, 2.5, 0);
99 glVertex3f(-2.5, 2.5, 0);
100 glVertex3f(-2.5, -2.5, 0);
101 glVertex3f(2.5, -2.5, 0);
108 static GLenum
Args(int argc
, char **argv
)
113 for (i
= 1; i
< argc
; i
++) {
114 if (strcmp(argv
[i
], "-dr") == 0) {
116 printf("%s (Bad option).\n", argv
[i
]);
123 int main(int argc
, char **argv
)
127 glutInit(&argc
, argv
);
129 if (Args(argc
, argv
) == GL_FALSE
) {
133 glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300);
135 type
= GLUT_RGB
| GLUT_SINGLE
| GLUT_DEPTH
| GLUT_STENCIL
;
136 glutInitDisplayMode(type
);
138 if (glutCreateWindow("Stencil Test") == GL_FALSE
) {
144 glutReshapeFunc(Reshape
);
145 glutKeyboardFunc(Key
);
146 glutDisplayFunc(Draw
);