132001f49Smrg/* 232001f49Smrg * Copyright (c) 1993-1997, Silicon Graphics, Inc. 332001f49Smrg * ALL RIGHTS RESERVED 432001f49Smrg * Permission to use, copy, modify, and distribute this software for 532001f49Smrg * any purpose and without fee is hereby granted, provided that the above 632001f49Smrg * copyright notice appear in all copies and that both the copyright notice 732001f49Smrg * and this permission notice appear in supporting documentation, and that 832001f49Smrg * the name of Silicon Graphics, Inc. not be used in advertising 932001f49Smrg * or publicity pertaining to distribution of the software without specific, 1032001f49Smrg * written prior permission. 1132001f49Smrg * 1232001f49Smrg * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" 1332001f49Smrg * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, 1432001f49Smrg * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR 1532001f49Smrg * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON 1632001f49Smrg * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, 1732001f49Smrg * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY 1832001f49Smrg * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, 1932001f49Smrg * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF 2032001f49Smrg * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN 2132001f49Smrg * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON 2232001f49Smrg * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE 2332001f49Smrg * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. 2432001f49Smrg * 2532001f49Smrg * US Government Users Restricted Rights 2632001f49Smrg * Use, duplication, or disclosure by the Government is subject to 2732001f49Smrg * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph 2832001f49Smrg * (c)(1)(ii) of the Rights in Technical Data and Computer Software 2932001f49Smrg * clause at DFARS 252.227-7013 and/or in similar or successor 3032001f49Smrg * clauses in the FAR or the DOD or NASA FAR Supplement. 3132001f49Smrg * Unpublished-- rights reserved under the copyright laws of the 3232001f49Smrg * United States. Contractor/manufacturer is Silicon Graphics, 3332001f49Smrg * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. 3432001f49Smrg * 3532001f49Smrg * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. 3632001f49Smrg */ 3732001f49Smrg 3832001f49Smrg/* 3932001f49Smrg * aaindex.c 4032001f49Smrg * This program draws shows how to draw anti-aliased lines in color 4132001f49Smrg * index mode. It draws two diagonal lines to form an X; when 'r' 4232001f49Smrg * is typed in the window, the lines are rotated in opposite 4332001f49Smrg * directions. 4432001f49Smrg */ 4532001f49Smrg#include "glut_wrap.h" 4632001f49Smrg#include "stdlib.h" 4732001f49Smrg 4832001f49Smrg#define RAMPSIZE 16 4932001f49Smrg#define RAMP1START 32 5032001f49Smrg#define RAMP2START 48 5132001f49Smrg 5232001f49Smrgstatic float rotAngle = 0.; 5332001f49Smrg 5432001f49Smrg/* Initialize antialiasing for color index mode, 5532001f49Smrg * including loading a green color ramp starting 5632001f49Smrg * at RAMP1START, and a blue color ramp starting 5732001f49Smrg * at RAMP2START. The ramps must be a multiple of 16. 5832001f49Smrg */ 5932001f49Smrgstatic void init(void) 6032001f49Smrg{ 6132001f49Smrg int i; 6232001f49Smrg 6332001f49Smrg for (i = 0; i < RAMPSIZE; i++) { 6432001f49Smrg GLfloat shade; 6532001f49Smrg shade = (GLfloat) i/(GLfloat) RAMPSIZE; 6632001f49Smrg glutSetColor(RAMP1START+(GLint)i, 0., shade, 0.); 6732001f49Smrg glutSetColor(RAMP2START+(GLint)i, 0., 0., shade); 6832001f49Smrg } 6932001f49Smrg 7032001f49Smrg glEnable (GL_LINE_SMOOTH); 7132001f49Smrg glHint (GL_LINE_SMOOTH_HINT, GL_DONT_CARE); 7232001f49Smrg glLineWidth (1.5); 7332001f49Smrg 7432001f49Smrg glClearIndex ((GLfloat) RAMP1START); 7532001f49Smrg} 7632001f49Smrg 7732001f49Smrg/* Draw 2 diagonal lines to form an X 7832001f49Smrg */ 7932001f49Smrgstatic void display(void) 8032001f49Smrg{ 8132001f49Smrg glClear(GL_COLOR_BUFFER_BIT); 8232001f49Smrg 8332001f49Smrg glIndexi(RAMP1START); 8432001f49Smrg glPushMatrix(); 8532001f49Smrg glRotatef(-rotAngle, 0.0, 0.0, 0.1); 8632001f49Smrg glBegin (GL_LINES); 8732001f49Smrg glVertex2f (-0.5, 0.5); 8832001f49Smrg glVertex2f (0.5, -0.5); 8932001f49Smrg glEnd (); 9032001f49Smrg glPopMatrix(); 9132001f49Smrg 9232001f49Smrg glIndexi(RAMP2START); 9332001f49Smrg glPushMatrix(); 9432001f49Smrg glRotatef(rotAngle, 0.0, 0.0, 0.1); 9532001f49Smrg glBegin (GL_LINES); 9632001f49Smrg glVertex2f (0.5, 0.5); 9732001f49Smrg glVertex2f (-0.5, -0.5); 9832001f49Smrg glEnd (); 9932001f49Smrg glPopMatrix(); 10032001f49Smrg 10132001f49Smrg glFlush(); 10232001f49Smrg} 10332001f49Smrg 10432001f49Smrgstatic void reshape(int w, int h) 10532001f49Smrg{ 10632001f49Smrg glViewport(0, 0, (GLsizei) w, (GLsizei) h); 10732001f49Smrg glMatrixMode(GL_PROJECTION); 10832001f49Smrg glLoadIdentity(); 10932001f49Smrg if (w <= h) 11032001f49Smrg gluOrtho2D (-1.0, 1.0, 11132001f49Smrg -1.0*(GLfloat)h/(GLfloat)w, 1.0*(GLfloat)h/(GLfloat)w); 11232001f49Smrg else 11332001f49Smrg gluOrtho2D (-1.0*(GLfloat)w/(GLfloat)h, 11432001f49Smrg 1.0*(GLfloat)w/(GLfloat)h, -1.0, 1.0); 11532001f49Smrg glMatrixMode(GL_MODELVIEW); 11632001f49Smrg glLoadIdentity(); 11732001f49Smrg} 11832001f49Smrg 11932001f49Smrg/* ARGSUSED1 */ 12032001f49Smrgstatic void keyboard(unsigned char key, int x, int y) 12132001f49Smrg{ 12232001f49Smrg switch (key) { 12332001f49Smrg case 'r': 12432001f49Smrg case 'R': 12532001f49Smrg rotAngle += 20.; 12632001f49Smrg if (rotAngle >= 360.) rotAngle = 0.; 12732001f49Smrg glutPostRedisplay(); 12832001f49Smrg break; 12932001f49Smrg case 27: /* Escape Key */ 13032001f49Smrg exit(0); 13132001f49Smrg break; 13232001f49Smrg default: 13332001f49Smrg break; 13432001f49Smrg } 13532001f49Smrg} 13632001f49Smrg 13732001f49Smrg/* Main Loop 13832001f49Smrg * Open window with initial window size, title bar, 13932001f49Smrg * color index display mode, and handle input events. 14032001f49Smrg */ 14132001f49Smrgint main(int argc, char** argv) 14232001f49Smrg{ 14332001f49Smrg glutInit(&argc, argv); 14432001f49Smrg glutInitDisplayMode (GLUT_SINGLE | GLUT_INDEX); 14532001f49Smrg glutInitWindowSize (200, 200); 14632001f49Smrg glutCreateWindow (argv[0]); 14732001f49Smrg init(); 14832001f49Smrg glutReshapeFunc (reshape); 14932001f49Smrg glutKeyboardFunc (keyboard); 15032001f49Smrg glutDisplayFunc (display); 15132001f49Smrg glutMainLoop(); 15232001f49Smrg return 0; 15332001f49Smrg} 154