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)
34 glShadeModel(GL_FLAT
);
35 glClearColor(0.0, 0.0, 0.0, 0.0);
39 glEnable(GL_STENCIL_TEST
);
42 static void Reshape(int width
, int height
)
45 glViewport(0, 0, (GLint
)width
, (GLint
)height
);
47 glMatrixMode(GL_PROJECTION
);
49 glOrtho(-5.0, 5.0, -5.0, 5.0, -5.0, 5.0);
50 glMatrixMode(GL_MODELVIEW
);
53 static void Key(unsigned char key
, int x
, int y
)
62 static void Draw(void)
65 glClear(GL_COLOR_BUFFER_BIT
|GL_STENCIL_BUFFER_BIT
);
67 glStencilFunc(GL_ALWAYS
, 1, 1);
68 glStencilOp(GL_KEEP
, GL_KEEP
, GL_REPLACE
);
70 glColor3ub(200, 0, 0);
72 glVertex3i(-4, -4, 0);
73 glVertex3i( 4, -4, 0);
77 glStencilFunc(GL_EQUAL
, 1, 1);
78 glStencilOp(GL_INCR
, GL_KEEP
, GL_DECR
);
80 glColor3ub(0, 200, 0);
84 glVertex3i(-3, -3, 0);
88 glStencilFunc(GL_EQUAL
, 1, 1);
89 glStencilOp(GL_KEEP
, GL_KEEP
, GL_KEEP
);
91 glColor3ub(0, 0, 200);
95 glVertex3i(-3, -3, 0);
102 static GLenum
Args(int argc
, char **argv
)
107 for (i
= 1; i
< argc
; i
++) {
108 if (strcmp(argv
[i
], "-dr") == 0) {
110 printf("%s (Bad option).\n", argv
[i
]);
117 int main(int argc
, char **argv
)
121 glutInit(&argc
, argv
);
123 if (Args(argc
, argv
) == GL_FALSE
) {
127 glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300);
129 type
= GLUT_RGB
| GLUT_SINGLE
| GLUT_STENCIL
;
130 glutInitDisplayMode(type
);
132 if (glutCreateWindow("Stencil Test") == GL_FALSE
) {
138 glutReshapeFunc(Reshape
);
139 glutKeyboardFunc(Key
);
140 glutDisplayFunc(Draw
);