1 2/* Copyright (c) Mark J. Kilgard, 1994. */ 3 4/* 5 * (c) Copyright 1993, Silicon Graphics, Inc. 6 * ALL RIGHTS RESERVED 7 * Permission to use, copy, modify, and distribute this software for 8 * any purpose and without fee is hereby granted, provided that the above 9 * copyright notice appear in all copies and that both the copyright notice 10 * and this permission notice appear in supporting documentation, and that 11 * the name of Silicon Graphics, Inc. not be used in advertising 12 * or publicity pertaining to distribution of the software without specific, 13 * written prior permission. 14 * 15 * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" 16 * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, 17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR 18 * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON 19 * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, 20 * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY 21 * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, 22 * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF 23 * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN 24 * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON 25 * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE 26 * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. 27 * 28 * US Government Users Restricted Rights 29 * Use, duplication, or disclosure by the Government is subject to 30 * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph 31 * (c)(1)(ii) of the Rights in Technical Data and Computer Software 32 * clause at DFARS 252.227-7013 and/or in similar or successor 33 * clauses in the FAR or the DOD or NASA FAR Supplement. 34 * Unpublished-- rights reserved under the copyright laws of the 35 * United States. Contractor/manufacturer is Silicon Graphics, 36 * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. 37 * 38 * OpenGL(TM) is a trademark of Silicon Graphics, Inc. 39 */ 40/* 41 * polys.c 42 * This program demonstrates polygon stippling. 43 */ 44#include <stdlib.h> 45#include "glut_wrap.h" 46 47static int win; 48 49static void display(void) 50{ 51 GLubyte fly[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 520x03, 0x80, 0x01, 0xC0, 0x06, 0xC0, 0x03, 0x60, 0x04, 0x60, 0x06, 0x20, 530x04, 0x30, 0x0C, 0x20, 0x04, 0x18, 0x18, 0x20, 0x04, 0x0C, 0x30, 0x20, 540x04, 0x06, 0x60, 0x20, 0x44, 0x03, 0xC0, 0x22, 0x44, 0x01, 0x80, 0x22, 550x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22, 560x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22, 0x66, 0x01, 0x80, 0x66, 570x33, 0x01, 0x80, 0xCC, 0x19, 0x81, 0x81, 0x98, 0x0C, 0xC1, 0x83, 0x30, 580x07, 0xe1, 0x87, 0xe0, 0x03, 0x3f, 0xfc, 0xc0, 0x03, 0x31, 0x8c, 0xc0, 590x03, 0x33, 0xcc, 0xc0, 0x06, 0x64, 0x26, 0x60, 0x0c, 0xcc, 0x33, 0x30, 600x18, 0xcc, 0x33, 0x18, 0x10, 0xc4, 0x23, 0x08, 0x10, 0x63, 0xC6, 0x08, 610x10, 0x30, 0x0c, 0x08, 0x10, 0x18, 0x18, 0x08, 0x10, 0x00, 0x00, 0x08}; 62 63 GLubyte halftone[] = { 640xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 650x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 660xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 670x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 680xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 690x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 700xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 710x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 720xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 730x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 740xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55}; 75 76 glClear (GL_COLOR_BUFFER_BIT); 77 78/* draw all polygons in white */ 79 glColor3f (1.0, 1.0, 1.0); 80 81/* draw one solid, unstippled rectangle, */ 82/* then two stippled rectangles */ 83 glRectf (25.0, 25.0, 125.0, 125.0); 84 glEnable (GL_POLYGON_STIPPLE); 85 glPolygonStipple (fly); 86 glRectf (125.0, 25.0, 225.0, 125.0); 87 glPolygonStipple (halftone); 88 glRectf (225.0, 25.0, 325.0, 125.0); 89 glDisable (GL_POLYGON_STIPPLE); 90 91 glFlush (); 92} 93 94static void myinit (void) 95{ 96/* clear background to black */ 97 glClearColor (0.0, 0.0, 0.0, 0.0); 98 glShadeModel (GL_FLAT); 99} 100 101static void reshape(GLsizei w, GLsizei h) 102{ 103 glViewport(0, 0, w, h); 104 glMatrixMode(GL_PROJECTION); 105 glLoadIdentity(); 106 glOrtho(0.0, (GLdouble)w, 0.0, (GLdouble)h, -1.0, 1.0); 107 glMatrixMode(GL_MODELVIEW); 108 glLoadIdentity(); 109} 110 111static void 112key(unsigned char k, int x, int y) 113{ 114 switch (k) { 115 case 27: /* Escape */ 116 glutDestroyWindow(win); 117 exit(0); 118 break; 119 default: 120 break; 121 } 122 glutPostRedisplay(); 123} 124 125/* Main Loop 126 * Open window with initial window size, title bar, 127 * RGBA display mode, and handle input events. 128 */ 129int main(int argc, char** argv) 130{ 131 glutInit(&argc, argv); 132 glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); 133 glutInitWindowSize (350, 150); 134 win = glutCreateWindow (argv[0]); 135 myinit (); 136 glutDisplayFunc(display); 137 glutReshapeFunc(reshape); 138 glutKeyboardFunc(key); 139 glutMainLoop(); 140 return 0; /* ANSI C requires main to return int. */ 141} 142