132001f49Smrg 232001f49Smrg/* Copyright (c) Mark J. Kilgard, 1994. */ 332001f49Smrg 432001f49Smrg/* 532001f49Smrg * (c) Copyright 1993, Silicon Graphics, Inc. 632001f49Smrg * ALL RIGHTS RESERVED 732001f49Smrg * Permission to use, copy, modify, and distribute this software for 832001f49Smrg * any purpose and without fee is hereby granted, provided that the above 932001f49Smrg * copyright notice appear in all copies and that both the copyright notice 1032001f49Smrg * and this permission notice appear in supporting documentation, and that 1132001f49Smrg * the name of Silicon Graphics, Inc. not be used in advertising 1232001f49Smrg * or publicity pertaining to distribution of the software without specific, 1332001f49Smrg * written prior permission. 1432001f49Smrg * 1532001f49Smrg * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" 1632001f49Smrg * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, 1732001f49Smrg * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR 1832001f49Smrg * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON 1932001f49Smrg * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, 2032001f49Smrg * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY 2132001f49Smrg * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, 2232001f49Smrg * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF 2332001f49Smrg * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN 2432001f49Smrg * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON 2532001f49Smrg * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE 2632001f49Smrg * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. 2732001f49Smrg * 2832001f49Smrg * US Government Users Restricted Rights 2932001f49Smrg * Use, duplication, or disclosure by the Government is subject to 3032001f49Smrg * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph 3132001f49Smrg * (c)(1)(ii) of the Rights in Technical Data and Computer Software 3232001f49Smrg * clause at DFARS 252.227-7013 and/or in similar or successor 3332001f49Smrg * clauses in the FAR or the DOD or NASA FAR Supplement. 3432001f49Smrg * Unpublished-- rights reserved under the copyright laws of the 3532001f49Smrg * United States. Contractor/manufacturer is Silicon Graphics, 3632001f49Smrg * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. 3732001f49Smrg * 3832001f49Smrg * OpenGL(TM) is a trademark of Silicon Graphics, Inc. 3932001f49Smrg */ 4032001f49Smrg/* 4132001f49Smrg * polys.c 4232001f49Smrg * This program demonstrates polygon stippling. 4332001f49Smrg */ 4432001f49Smrg#include <stdlib.h> 4532001f49Smrg#include "glut_wrap.h" 4632001f49Smrg 4732001f49Smrgstatic int win; 4832001f49Smrg 4932001f49Smrgstatic void display(void) 5032001f49Smrg{ 5132001f49Smrg GLubyte fly[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 5232001f49Smrg0x03, 0x80, 0x01, 0xC0, 0x06, 0xC0, 0x03, 0x60, 0x04, 0x60, 0x06, 0x20, 5332001f49Smrg0x04, 0x30, 0x0C, 0x20, 0x04, 0x18, 0x18, 0x20, 0x04, 0x0C, 0x30, 0x20, 5432001f49Smrg0x04, 0x06, 0x60, 0x20, 0x44, 0x03, 0xC0, 0x22, 0x44, 0x01, 0x80, 0x22, 5532001f49Smrg0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22, 5632001f49Smrg0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22, 0x66, 0x01, 0x80, 0x66, 5732001f49Smrg0x33, 0x01, 0x80, 0xCC, 0x19, 0x81, 0x81, 0x98, 0x0C, 0xC1, 0x83, 0x30, 5832001f49Smrg0x07, 0xe1, 0x87, 0xe0, 0x03, 0x3f, 0xfc, 0xc0, 0x03, 0x31, 0x8c, 0xc0, 5932001f49Smrg0x03, 0x33, 0xcc, 0xc0, 0x06, 0x64, 0x26, 0x60, 0x0c, 0xcc, 0x33, 0x30, 6032001f49Smrg0x18, 0xcc, 0x33, 0x18, 0x10, 0xc4, 0x23, 0x08, 0x10, 0x63, 0xC6, 0x08, 6132001f49Smrg0x10, 0x30, 0x0c, 0x08, 0x10, 0x18, 0x18, 0x08, 0x10, 0x00, 0x00, 0x08}; 6232001f49Smrg 6332001f49Smrg GLubyte halftone[] = { 6432001f49Smrg0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 6532001f49Smrg0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 6632001f49Smrg0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 6732001f49Smrg0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 6832001f49Smrg0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 6932001f49Smrg0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 7032001f49Smrg0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 7132001f49Smrg0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 7232001f49Smrg0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 7332001f49Smrg0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 7432001f49Smrg0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55}; 7532001f49Smrg 7632001f49Smrg glClear (GL_COLOR_BUFFER_BIT); 7732001f49Smrg 7832001f49Smrg/* draw all polygons in white */ 7932001f49Smrg glColor3f (1.0, 1.0, 1.0); 8032001f49Smrg 8132001f49Smrg/* draw one solid, unstippled rectangle, */ 8232001f49Smrg/* then two stippled rectangles */ 8332001f49Smrg glRectf (25.0, 25.0, 125.0, 125.0); 8432001f49Smrg glEnable (GL_POLYGON_STIPPLE); 8532001f49Smrg glPolygonStipple (fly); 8632001f49Smrg glRectf (125.0, 25.0, 225.0, 125.0); 8732001f49Smrg glPolygonStipple (halftone); 8832001f49Smrg glRectf (225.0, 25.0, 325.0, 125.0); 8932001f49Smrg glDisable (GL_POLYGON_STIPPLE); 9032001f49Smrg 9132001f49Smrg glFlush (); 9232001f49Smrg} 9332001f49Smrg 9432001f49Smrgstatic void myinit (void) 9532001f49Smrg{ 9632001f49Smrg/* clear background to black */ 9732001f49Smrg glClearColor (0.0, 0.0, 0.0, 0.0); 9832001f49Smrg glShadeModel (GL_FLAT); 9932001f49Smrg} 10032001f49Smrg 10132001f49Smrgstatic void reshape(GLsizei w, GLsizei h) 10232001f49Smrg{ 10332001f49Smrg glViewport(0, 0, w, h); 10432001f49Smrg glMatrixMode(GL_PROJECTION); 10532001f49Smrg glLoadIdentity(); 10632001f49Smrg glOrtho(0.0, (GLdouble)w, 0.0, (GLdouble)h, -1.0, 1.0); 10732001f49Smrg glMatrixMode(GL_MODELVIEW); 10832001f49Smrg glLoadIdentity(); 10932001f49Smrg} 11032001f49Smrg 11132001f49Smrgstatic void 11232001f49Smrgkey(unsigned char k, int x, int y) 11332001f49Smrg{ 11432001f49Smrg switch (k) { 11532001f49Smrg case 27: /* Escape */ 11632001f49Smrg glutDestroyWindow(win); 11732001f49Smrg exit(0); 11832001f49Smrg break; 11932001f49Smrg default: 12032001f49Smrg break; 12132001f49Smrg } 12232001f49Smrg glutPostRedisplay(); 12332001f49Smrg} 12432001f49Smrg 12532001f49Smrg/* Main Loop 12632001f49Smrg * Open window with initial window size, title bar, 12732001f49Smrg * RGBA display mode, and handle input events. 12832001f49Smrg */ 12932001f49Smrgint main(int argc, char** argv) 13032001f49Smrg{ 13132001f49Smrg glutInit(&argc, argv); 13232001f49Smrg glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); 13332001f49Smrg glutInitWindowSize (350, 150); 13432001f49Smrg win = glutCreateWindow (argv[0]); 13532001f49Smrg myinit (); 13632001f49Smrg glutDisplayFunc(display); 13732001f49Smrg glutReshapeFunc(reshape); 13832001f49Smrg glutKeyboardFunc(key); 13932001f49Smrg glutMainLoop(); 14032001f49Smrg return 0; /* ANSI C requires main to return int. */ 14132001f49Smrg} 142