blob: 9f68bca9149f95339600eee36c4099c08e1a0377 [file] [log] [blame]
Keith Whitwellb1399a52007-11-25 15:06:54 +00001/*
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
32static void Init(void)
33{
34}
35
36static 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
47static void Key(unsigned char key, int x, int y)
48{
49
50 switch (key) {
51 case 27:
Robert Ellison711f8a12008-10-30 15:24:23 -060052 printf("Exiting...\n");
Keith Whitwellb1399a52007-11-25 15:06:54 +000053 exit(1);
Robert Ellison711f8a12008-10-30 15:24:23 -060054 case 'r':
55 printf("Redisplaying...\n");
56 glutPostRedisplay();
57 break;
58 default:
59 printf("No such key '%c'...\n", key);
60 break;
Keith Whitwellb1399a52007-11-25 15:06:54 +000061 }
62}
63
64static void Draw(void)
65{
66 glShadeModel(GL_FLAT);
67
68 {
69 glClearColor(0.0, 0.0, 0.0, 0.0);
70 glClearStencil(0);
71 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
72 }
73
74
75 glStencilMask(1);
76 glEnable(GL_STENCIL_TEST);
77 glStencilFunc(GL_ALWAYS, 1, 1);
78 glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
79
80 glColor3ub(200, 0, 0);
81 glBegin(GL_POLYGON);
82 glVertex3i(-4, -4, 0);
83 glVertex3i( 4, -4, 0);
84 glVertex3i( 0, 4, 0);
85 glEnd();
86
87#if 1
88 glStencilFunc(GL_EQUAL, 1, 1);
89 glStencilOp(GL_INCR, GL_KEEP, GL_DECR);
90
91 glColor3ub(0, 200, 0);
92 glBegin(GL_POLYGON);
93 glVertex3i(3, 3, 0);
94 glVertex3i(-3, 3, 0);
95 glVertex3i(-3, -3, 0);
96 glVertex3i(3, -3, 0);
97 glEnd();
98#endif
99
Robert Ellison711f8a12008-10-30 15:24:23 -0600100#if 1
Keith Whitwellb1399a52007-11-25 15:06:54 +0000101 glStencilFunc(GL_EQUAL, 1, 1);
102 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
103
104 glColor3ub(0, 0, 200);
105 glBegin(GL_POLYGON);
106 glVertex3f(2.5, 2.5, 0);
107 glVertex3f(-2.5, 2.5, 0);
108 glVertex3f(-2.5, -2.5, 0);
109 glVertex3f(2.5, -2.5, 0);
110 glEnd();
111#endif
112
113 glFlush();
114}
115
116static GLenum Args(int argc, char **argv)
117{
118 GLint i;
119
120
121 for (i = 1; i < argc; i++) {
122 if (strcmp(argv[i], "-dr") == 0) {
123 } else {
124 printf("%s (Bad option).\n", argv[i]);
125 return GL_FALSE;
126 }
127 }
128 return GL_TRUE;
129}
130
131int main(int argc, char **argv)
132{
133 GLenum type;
134
135 glutInit(&argc, argv);
136
137 if (Args(argc, argv) == GL_FALSE) {
138 exit(1);
139 }
140
Robert Ellison711f8a12008-10-30 15:24:23 -0600141 glutInitWindowPosition(0, 0);
142 glutInitWindowSize( 300, 300);
Keith Whitwellb1399a52007-11-25 15:06:54 +0000143
144 type = GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH | GLUT_STENCIL;
145 glutInitDisplayMode(type);
146
Jakob Bornecrantz4e37f102009-02-19 22:48:21 +0100147 if (glutCreateWindow(*argv) == GL_FALSE) {
Keith Whitwellb1399a52007-11-25 15:06:54 +0000148 exit(1);
149 }
150
151 Init();
152
153 glutReshapeFunc(Reshape);
154 glutKeyboardFunc(Key);
155 glutDisplayFunc(Draw);
156 glutMainLoop();
157 return 0;
158}