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 = 1; 36int win; 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.3, 0.1, 0.3, 0.0); 46} 47 48static void Reshape(int width, int height) 49{ 50 glViewport(0, 0, (GLint)width, (GLint)height); 51 52 glMatrixMode(GL_PROJECTION); 53 glLoadIdentity(); 54 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); 55 glMatrixMode(GL_MODELVIEW); 56} 57 58static void Clear(void) 59{ 60 fprintf(stderr, "::clearing\n"); 61 fflush(stderr); 62 63 glClear(GL_COLOR_BUFFER_BIT); 64} 65 66static void DrawTri(void) 67{ 68 fprintf(stderr, "::drawing - tri\n"); 69 fflush(stderr); 70 71 glBegin(GL_TRIANGLES); 72 glColor3f(.8,0,0); 73 glVertex3f(-0.9, -0.9, -30.0); 74 glColor3f(0,.9,0); 75 glVertex3f( 0.9, -0.9, -30.0); 76 glColor3f(0,0,.7); 77 glVertex3f( 0.0, 0.9, -30.0); 78 glEnd(); 79} 80 81static void DrawClipTri(void) 82{ 83 fprintf(stderr, "::drawing - tri clipped\n"); 84 fflush(stderr); 85 86 glBegin(GL_TRIANGLES); 87 glColor3f(.8,0,0); 88 glVertex3f(-0.9, 0.9, -30.0); 89 glColor3f(0,.9,0); 90 glVertex3f( 0.9, 0.9, -30.0); 91 glColor3f(0,0,.7); 92 glVertex3f( 0.0, -1.9, -30.0); 93 glEnd(); 94} 95 96static void Swap(void) 97{ 98 fprintf(stderr, "::swapping\n"); 99 fflush(stderr); 100 101 glutSwapBuffers(); 102} 103 104static void Flush(void) 105{ 106 fprintf(stderr, "::flush\n"); 107 fflush(stderr); 108 109 glFlush(); 110} 111 112static void Key(unsigned char key, int x, int y) 113{ 114 switch (key) { 115 case 27: 116 glutDestroyWindow(win); 117 exit(0); 118 case 't': 119 DrawTri(); 120 break; 121 case 'T': 122 DrawClipTri(); 123 break; 124 case 'f': 125 Flush(); 126 break; 127 case 's': 128 Swap(); 129 Clear(); 130 break; 131 default: 132 return; 133 } 134} 135 136static void Draw(void) 137{ 138 Clear(); 139 DrawTri(); 140 DrawClipTri(); 141 Swap(); 142 Clear(); 143} 144 145static void 146Usage(void) 147{ 148 printf("usage:\n"); 149 printf(" t/T draw a triangle (caps for clipped)\n"); 150 printf(" f flush\n"); 151 printf(" s swap\n"); 152} 153 154int main(int argc, char **argv) 155{ 156 GLenum type; 157 158 glutInit(&argc, argv); 159 160 glutInitWindowPosition(0, 0); 161 glutInitWindowSize(250, 250); 162 163 type = GLUT_RGB | GLUT_ALPHA | GLUT_DOUBLE; 164 glutInitDisplayMode(type); 165 166 win = glutCreateWindow(*argv); 167 if (!win) { 168 exit(1); 169 } 170 171 Init(); 172 173 Usage(); 174 175 glutReshapeFunc(Reshape); 176 glutKeyboardFunc(Key); 177 glutDisplayFunc(Draw); 178 glutMainLoop(); 179 return 0; 180} 181