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 doubleBuffer; 36GLint first_list, list; 37 38static void Init(void) 39{ 40 fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); 41 fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); 42 fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); 43 fflush(stderr); 44 45 glClearColor(0.0, 0.0, 1.0, 0.0); 46 47 /* First list will disrupt state which might potentially be 48 * short-circuited in calling list: 49 */ 50 first_list = glGenLists(1); 51 glNewList(first_list, GL_COMPILE); 52 glShadeModel( GL_SMOOTH ); 53 glEndList(); 54 55 56 /* List that looks like it might have redundant state: 57 */ 58 list = glGenLists(1); 59 glNewList(list, GL_COMPILE); 60 61 glBegin(GL_TRIANGLES); 62 glColor3f(0,0,.7); 63 glVertex3f( 0.9, -0.9, -30.0); 64 glColor3f(.8,0,0); 65 glVertex3f( 0.9, 0.9, -30.0); 66 glColor3f(0,.9,0); 67 glVertex3f(-0.9, 0.0, -30.0); 68 glEnd(); 69 70 glShadeModel( GL_FLAT ); 71 glBegin(GL_TRIANGLES); 72 glColor3f(0,0,.7); 73 glVertex3f( -0.9, 0.9, -30.0); 74 glColor3f(0,.9,0); 75 glVertex3f( -0.9, -0.9, -30.0); 76 glColor3f(.8,0,0); 77 glVertex3f( 0.9, 0.0, -30.0); 78 glEnd(); 79 80 glCallList( first_list ); 81 82 /* Do a quick begin/end to ensure we are not inside a dangling 83 * primitive from the called list: 84 */ 85 glBegin( GL_POINTS ); 86 glEnd(); 87 88 /* This statechange is NOT redundant: 89 */ 90 glShadeModel( GL_FLAT ); 91 glBegin(GL_TRIANGLES); 92 glColor3f(1,0,0); 93 glVertex3f( -0.5, 0.5, -30.0); 94 glColor3f(0,1,0); 95 glVertex3f( -0.5, -0.5, -30.0); 96 glColor3f(0,0,1); 97 glVertex3f( 0.5, 0.0, -30.0); 98 glEnd(); 99 100 glEndList(); 101} 102 103static void Reshape(int width, int height) 104{ 105 106 glViewport(0, 0, (GLint)width, (GLint)height); 107 108 glMatrixMode(GL_PROJECTION); 109 glLoadIdentity(); 110 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); 111 glMatrixMode(GL_MODELVIEW); 112} 113 114static void Key(unsigned char key, int x, int y) 115{ 116 117 switch (key) { 118 case 27: 119 exit(1); 120 default: 121 break; 122 } 123 124 glutPostRedisplay(); 125} 126 127 128 129 130static void Draw(void) 131{ 132 glClear(GL_COLOR_BUFFER_BIT); 133 134 glShadeModel( GL_SMOOTH ); 135 glCallList(list); 136 137 glFlush(); 138 139 if (doubleBuffer) { 140 glutSwapBuffers(); 141 } 142} 143 144static GLenum Args(int argc, char **argv) 145{ 146 GLint i; 147 148 doubleBuffer = GL_FALSE; 149 150 for (i = 1; i < argc; i++) { 151 if (strcmp(argv[i], "-sb") == 0) { 152 doubleBuffer = GL_FALSE; 153 } else if (strcmp(argv[i], "-db") == 0) { 154 doubleBuffer = GL_TRUE; 155 } else { 156 fprintf(stderr, "%s (Bad option).\n", argv[i]); 157 return GL_FALSE; 158 } 159 } 160 return GL_TRUE; 161} 162 163int main(int argc, char **argv) 164{ 165 GLenum type; 166 167 glutInit(&argc, argv); 168 169 if (Args(argc, argv) == GL_FALSE) { 170 exit(1); 171 } 172 173 glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250); 174 175 type = GLUT_RGB | GLUT_ALPHA; 176 type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; 177 glutInitDisplayMode(type); 178 179 if (glutCreateWindow(*argv) == GL_FALSE) { 180 exit(1); 181 } 182 183 Init(); 184 185 glutReshapeFunc(Reshape); 186 glutKeyboardFunc(Key); 187 glutDisplayFunc(Draw); 188 glutMainLoop(); 189 return 0; 190} 191