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 "glut_wrap.h" 30 31 32static void Init(void) 33{ 34 glShadeModel(GL_FLAT); 35 glClearColor(0.0, 0.0, 0.0, 0.0); 36 37 glClearStencil(0); 38 glStencilMask(1); 39 glEnable(GL_STENCIL_TEST); 40} 41 42static void Reshape(int width, int height) 43{ 44 45 glViewport(0, 0, (GLint)width, (GLint)height); 46 47 glMatrixMode(GL_PROJECTION); 48 glLoadIdentity(); 49 glOrtho(-5.0, 5.0, -5.0, 5.0, -5.0, 5.0); 50 glMatrixMode(GL_MODELVIEW); 51} 52 53static void Key(unsigned char key, int x, int y) 54{ 55 56 switch (key) { 57 case 27: 58 exit(1); 59 } 60} 61 62static void Draw(void) 63{ 64 65 glClear(GL_COLOR_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); 66 67 glStencilFunc(GL_ALWAYS, 1, 1); 68 glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); 69 70 glColor3ub(200, 0, 0); 71 glBegin(GL_POLYGON); 72 glVertex3i(-4, -4, 0); 73 glVertex3i( 4, -4, 0); 74 glVertex3i( 0, 4, 0); 75 glEnd(); 76 77 glStencilFunc(GL_EQUAL, 1, 1); 78 glStencilOp(GL_INCR, GL_KEEP, GL_DECR); 79 80 glColor3ub(0, 200, 0); 81 glBegin(GL_POLYGON); 82 glVertex3i(3, 3, 0); 83 glVertex3i(-3, 3, 0); 84 glVertex3i(-3, -3, 0); 85 glVertex3i(3, -3, 0); 86 glEnd(); 87 88 glStencilFunc(GL_EQUAL, 1, 1); 89 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); 90 91 glColor3ub(0, 0, 200); 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 99 glFlush(); 100} 101 102static GLenum Args(int argc, char **argv) 103{ 104 GLint i; 105 106 107 for (i = 1; i < argc; i++) { 108 if (strcmp(argv[i], "-dr") == 0) { 109 } else { 110 printf("%s (Bad option).\n", argv[i]); 111 return GL_FALSE; 112 } 113 } 114 return GL_TRUE; 115} 116 117int main(int argc, char **argv) 118{ 119 GLenum type; 120 121 glutInit(&argc, argv); 122 123 if (Args(argc, argv) == GL_FALSE) { 124 exit(1); 125 } 126 127 glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300); 128 129 type = GLUT_RGB | GLUT_SINGLE | GLUT_STENCIL; 130 glutInitDisplayMode(type); 131 132 if (glutCreateWindow("Stencil Test") == GL_FALSE) { 133 exit(1); 134 } 135 136 Init(); 137 138 glutReshapeFunc(Reshape); 139 glutKeyboardFunc(Key); 140 glutDisplayFunc(Draw); 141 glutMainLoop(); 142 return 0; 143} 144