tri-edgeflag-array.c revision 32001f49
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 30static GLenum frontface = GL_CCW; 31 32 33static void 34Init(void) 35{ 36 fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); 37 fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); 38 fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); 39 fflush(stderr); 40} 41 42 43static void 44Reshape(int width, int height) 45{ 46 glViewport(0, 0, (GLint)width, (GLint)height); 47 glMatrixMode(GL_PROJECTION); 48 glLoadIdentity(); 49 glMatrixMode(GL_MODELVIEW); 50} 51 52 53static void 54Key(unsigned char key, int x, int y) 55{ 56 switch (key) { 57 case 'f': 58 frontface = (frontface == GL_CCW) ? GL_CW : GL_CCW; 59 glFrontFace(frontface); 60 break; 61 case 27: 62 exit(1); 63 default: 64 return; 65 } 66 glutPostRedisplay(); 67} 68 69 70static void 71Draw(void) 72{ 73 static GLboolean flags[3] = { 1, 0, 1}; 74 static GLfloat color[3][3] = { 75 { 0.3, 0.3, 0.9 }, 76 { 0.8, 0.0, 0.0 }, 77 { 0.0, 0.9, 0.0 } 78 }; 79 static GLfloat vert[3][3] = { 80 { 0.9, -0.9, 0.0 }, 81 { 0.9, 0.9, 0.0 }, 82 { -0.9, 0.0, 0.0 } 83 }; 84 85 glClear(GL_COLOR_BUFFER_BIT); 86 glPolygonMode(GL_FRONT, GL_LINE); 87 glPolygonMode(GL_BACK, GL_POINT); 88 89 glVertexPointer(3, GL_FLOAT, 0, vert); 90 glColorPointer(3, GL_FLOAT, 0, color); 91 glEdgeFlagPointer(0, flags); 92 glEnableClientState(GL_VERTEX_ARRAY); 93 glEnableClientState(GL_COLOR_ARRAY); 94 glEnableClientState(GL_EDGE_FLAG_ARRAY); 95 96 glDrawArrays(GL_TRIANGLES, 0, 3); 97 98 glutSwapBuffers(); 99} 100 101 102int 103main(int argc, char **argv) 104{ 105 glutInit(&argc, argv); 106 107 glutInitWindowPosition(0, 0); 108 glutInitWindowSize( 250, 250); 109 glutInitDisplayMode(GLUT_RGB | GLUT_ALPHA | GLUT_DOUBLE); 110 if (!glutCreateWindow(*argv)) { 111 exit(1); 112 } 113 glutReshapeFunc(Reshape); 114 glutKeyboardFunc(Key); 115 glutDisplayFunc(Draw); 116 Init(); 117 glutMainLoop(); 118 return 0; 119} 120