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 <string.h> 27#include <stdlib.h> 28#include "glut_wrap.h" 29 30 31#define CI_OFFSET_1 16 32#define CI_OFFSET_2 32 33 34 35GLenum rgb, doubleBuffer; 36 37GLenum antiAlias, stipple; 38GLubyte stippleBits[32*4] = { 39 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 40 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 41 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 42 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 43 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 44 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 45 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 46 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 47 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 48 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 49 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 50 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 51 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 52 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 53 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 54 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 55}; 56 57 58#include "tkmap.c" 59 60static void Init(void) 61{ 62 GLint i; 63 64 glClearColor(0.0, 0.0, 0.0, 0.0); 65 glClearIndex(0.0); 66 67 if (!rgb) { 68 for (i = 0; i < 16; i++) { 69 glutSetColor(i+CI_OFFSET_1, 0.0, 0.0, i/15.0); 70 glutSetColor(i+CI_OFFSET_2, 0.0, i/15.0, 0.0); 71 } 72 } 73 74 glPolygonStipple(stippleBits); 75 76 antiAlias = GL_FALSE; 77 stipple = GL_FALSE; 78} 79 80static void Reshape(int width, int height) 81{ 82 83 glViewport(0, 0, (GLint)width, (GLint)height); 84 85 glMatrixMode(GL_PROJECTION); 86 glLoadIdentity(); 87 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); 88 glMatrixMode(GL_MODELVIEW); 89} 90 91static void Key(unsigned char key, int x, int y) 92{ 93 94 switch (key) { 95 case 27: 96 exit(1); 97 case '1': 98 antiAlias = !antiAlias; 99 break; 100 case '2': 101 stipple = !stipple; 102 break; 103 default: 104 return; 105 } 106 107 glutPostRedisplay(); 108} 109 110static void Draw(void) 111{ 112 GLint ci1, ci2; 113 114 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); 115 116 if (antiAlias) { 117 ci1 = CI_OFFSET_1; 118 ci2 = CI_OFFSET_2; 119 glBlendFunc(GL_SRC_ALPHA, GL_ONE); 120 glEnable(GL_BLEND); 121 glEnable(GL_POLYGON_SMOOTH); 122 glDisable(GL_DEPTH_TEST); 123 } else { 124 ci1 = COLOR_BLUE; 125 ci2 = COLOR_GREEN; 126 glDisable(GL_BLEND); 127 glDisable(GL_POLYGON_SMOOTH); 128 glEnable(GL_DEPTH_TEST); 129 } 130 131 if (stipple) { 132 glEnable(GL_POLYGON_STIPPLE); 133 } else { 134 glDisable(GL_POLYGON_STIPPLE); 135 } 136 137 glBegin(GL_TRIANGLES); 138 (rgb) ? glColor3fv(RGBMap[COLOR_BLUE]) : glIndexi(ci1); 139 glVertex3f( 0.9, -0.9, -30.0); 140 glVertex3f( 0.9, 0.9, -30.0); 141 glVertex3f(-0.9, 0.0, -30.0); 142 (rgb) ? glColor3fv(RGBMap[COLOR_GREEN]) : glIndexi(ci2); 143 glVertex3f(-0.9, -0.9, -40.0); 144 glVertex3f(-0.9, 0.9, -40.0); 145 glVertex3f( 0.9, 0.0, -25.0); 146 glEnd(); 147 148 glFlush(); 149 150 if (doubleBuffer) { 151 glutSwapBuffers(); 152 } 153} 154 155static GLenum Args(int argc, char **argv) 156{ 157 GLint i; 158 159 rgb = GL_TRUE; 160 doubleBuffer = GL_FALSE; 161 162 for (i = 1; i < argc; i++) { 163 if (strcmp(argv[i], "-ci") == 0) { 164 rgb = GL_FALSE; 165 } else if (strcmp(argv[i], "-rgb") == 0) { 166 rgb = GL_TRUE; 167 } else if (strcmp(argv[i], "-sb") == 0) { 168 doubleBuffer = GL_FALSE; 169 } else if (strcmp(argv[i], "-db") == 0) { 170 doubleBuffer = GL_TRUE; 171 } else { 172 printf("%s (Bad option).\n", argv[i]); 173 return GL_FALSE; 174 } 175 } 176 return GL_TRUE; 177} 178 179int main(int argc, char **argv) 180{ 181 GLenum type; 182 183 glutInit(&argc, argv); 184 185 if (Args(argc, argv) == GL_FALSE) { 186 exit(1); 187 } 188 189 glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300); 190 191 type = GLUT_DEPTH; 192 type |= (rgb) ? GLUT_RGB : GLUT_INDEX; 193 type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; 194 glutInitDisplayMode(type); 195 196 if (glutCreateWindow("Depth Test") == GL_FALSE) { 197 exit(1); 198 } 199 200 InitMap(); 201 202 Init(); 203 204 glutReshapeFunc(Reshape); 205 glutKeyboardFunc(Key); 206 glutDisplayFunc(Draw); 207 glutMainLoop(); 208 return 0; 209} 210