Update git ignores.
[mesa.git] / progs / trivial / tri-stencil.c
1 /*
2 * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc.
3 *
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.
11 *
12 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF
13 * ANY KIND,
14 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
16 *
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
22 * OF THIS SOFTWARE.
23 */
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <math.h>
29 #include <GL/glut.h>
30
31
32 static void Init(void)
33 {
34 }
35
36 static void Reshape(int width, int height)
37 {
38
39 glViewport(0, 0, (GLint)width, (GLint)height);
40
41 glMatrixMode(GL_PROJECTION);
42 glLoadIdentity();
43 glOrtho(-5.0, 5.0, -5.0, 5.0, -5.0, 5.0);
44 glMatrixMode(GL_MODELVIEW);
45 }
46
47 static void Key(unsigned char key, int x, int y)
48 {
49
50 switch (key) {
51 case 27:
52 exit(1);
53 }
54 }
55
56 static void Draw(void)
57 {
58 glShadeModel(GL_FLAT);
59
60 {
61 glClearColor(0.0, 0.0, 0.0, 0.0);
62 glClearStencil(0);
63 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
64 }
65
66
67 glStencilMask(1);
68 glEnable(GL_STENCIL_TEST);
69 glStencilFunc(GL_ALWAYS, 1, 1);
70 glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
71
72 glColor3ub(200, 0, 0);
73 glBegin(GL_POLYGON);
74 glVertex3i(-4, -4, 0);
75 glVertex3i( 4, -4, 0);
76 glVertex3i( 0, 4, 0);
77 glEnd();
78
79 #if 1
80 glStencilFunc(GL_EQUAL, 1, 1);
81 glStencilOp(GL_INCR, GL_KEEP, GL_DECR);
82
83 glColor3ub(0, 200, 0);
84 glBegin(GL_POLYGON);
85 glVertex3i(3, 3, 0);
86 glVertex3i(-3, 3, 0);
87 glVertex3i(-3, -3, 0);
88 glVertex3i(3, -3, 0);
89 glEnd();
90 #endif
91
92 #if 0
93 glStencilFunc(GL_EQUAL, 1, 1);
94 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
95
96 glColor3ub(0, 0, 200);
97 glBegin(GL_POLYGON);
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);
102 glEnd();
103 #endif
104
105 glFlush();
106 }
107
108 static GLenum Args(int argc, char **argv)
109 {
110 GLint i;
111
112
113 for (i = 1; i < argc; i++) {
114 if (strcmp(argv[i], "-dr") == 0) {
115 } else {
116 printf("%s (Bad option).\n", argv[i]);
117 return GL_FALSE;
118 }
119 }
120 return GL_TRUE;
121 }
122
123 int main(int argc, char **argv)
124 {
125 GLenum type;
126
127 glutInit(&argc, argv);
128
129 if (Args(argc, argv) == GL_FALSE) {
130 exit(1);
131 }
132
133 glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300);
134
135 type = GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH | GLUT_STENCIL;
136 glutInitDisplayMode(type);
137
138 if (glutCreateWindow("Stencil Test") == GL_FALSE) {
139 exit(1);
140 }
141
142 Init();
143
144 glutReshapeFunc(Reshape);
145 glutKeyboardFunc(Key);
146 glutDisplayFunc(Draw);
147 glutMainLoop();
148 return 0;
149 }