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/* accanti.c 41 */ 42#include <stdlib.h> 43#include "glut_wrap.h" 44#include "jitter.h" 45 46/* Initialize lighting and other values. 47 */ 48static void myinit(void) 49{ 50 GLfloat mat_ambient[] = { 1.0, 1.0, 1.0, 1.0 }; 51 GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; 52 GLfloat light_position[] = { 0.0, 0.0, 10.0, 1.0 }; 53 GLfloat lm_ambient[] = { 0.2, 0.2, 0.2, 1.0 }; 54 55 glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); 56 glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); 57 glMaterialf(GL_FRONT, GL_SHININESS, 50.0); 58 glLightfv(GL_LIGHT0, GL_POSITION, light_position); 59 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lm_ambient); 60 61 glEnable(GL_LIGHTING); 62 glEnable(GL_LIGHT0); 63 glDepthFunc(GL_LESS); 64 glEnable(GL_DEPTH_TEST); 65 glShadeModel (GL_FLAT); 66 67 glClearColor(0.0, 0.0, 0.0, 0.0); 68 glClearAccum(0.0, 0.0, 0.0, 0.0); 69} 70 71static void displayObjects(void) 72{ 73 GLfloat torus_diffuse[] = { 0.7, 0.7, 0.0, 1.0 }; 74 GLfloat cube_diffuse[] = { 0.0, 0.7, 0.7, 1.0 }; 75 GLfloat sphere_diffuse[] = { 0.7, 0.0, 0.7, 1.0 }; 76 GLfloat octa_diffuse[] = { 0.7, 0.4, 0.4, 1.0 }; 77 78 glPushMatrix (); 79 glRotatef (30.0, 1.0, 0.0, 0.0); 80 81 glPushMatrix (); 82 glTranslatef (-0.80, 0.35, 0.0); 83 glRotatef (100.0, 1.0, 0.0, 0.0); 84 glMaterialfv(GL_FRONT, GL_DIFFUSE, torus_diffuse); 85 glutSolidTorus (0.275, 0.85, 16, 16); 86 glPopMatrix (); 87 88 glPushMatrix (); 89 glTranslatef (-0.75, -0.50, 0.0); 90 glRotatef (45.0, 0.0, 0.0, 1.0); 91 glRotatef (45.0, 1.0, 0.0, 0.0); 92 glMaterialfv(GL_FRONT, GL_DIFFUSE, cube_diffuse); 93 glutSolidCube (1.5); 94 glPopMatrix (); 95 96 glPushMatrix (); 97 glTranslatef (0.75, 0.60, 0.0); 98 glRotatef (30.0, 1.0, 0.0, 0.0); 99 glMaterialfv(GL_FRONT, GL_DIFFUSE, sphere_diffuse); 100 glutSolidSphere (1.0, 16, 16); 101 glPopMatrix (); 102 103 glPushMatrix (); 104 glTranslatef (0.70, -0.90, 0.25); 105 glMaterialfv(GL_FRONT, GL_DIFFUSE, octa_diffuse); 106 glutSolidOctahedron (); 107 glPopMatrix (); 108 109 glPopMatrix (); 110} 111 112#define ACSIZE 8 113 114static void display(void) 115{ 116 GLint viewport[4]; 117 int jitter; 118 119 glGetIntegerv (GL_VIEWPORT, viewport); 120 121 glClear(GL_ACCUM_BUFFER_BIT); 122 for (jitter = 0; jitter < ACSIZE; jitter++) { 123 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 124 glPushMatrix (); 125/* Note that 4.5 is the distance in world space between 126 * left and right and bottom and top. 127 * This formula converts fractional pixel movement to 128 * world coordinates. 129 */ 130 glTranslatef (j8[jitter].x*4.5/viewport[2], 131 j8[jitter].y*4.5/viewport[3], 0.0); 132 displayObjects (); 133 glPopMatrix (); 134 glAccum(GL_ACCUM, 1.0/ACSIZE); 135 } 136 glAccum (GL_RETURN, 1.0); 137 glFlush(); 138} 139 140static void myReshape(int w, int h) 141{ 142 glViewport(0, 0, w, h); 143 glMatrixMode(GL_PROJECTION); 144 glLoadIdentity(); 145 if (w <= h) 146 glOrtho (-2.25, 2.25, -2.25*h/w, 2.25*h/w, -10.0, 10.0); 147 else 148 glOrtho (-2.25*w/h, 2.25*w/h, -2.25, 2.25, -10.0, 10.0); 149 glMatrixMode(GL_MODELVIEW); 150} 151 152static void 153key(unsigned char k, int x, int y) 154{ 155 switch (k) { 156 case 27: /* Escape */ 157 exit(0); 158 break; 159 default: 160 return; 161 } 162 glutPostRedisplay(); 163} 164 165/* Main Loop 166 * Open window with initial window size, title bar, 167 * RGBA display mode, and handle input events. 168 */ 169int main(int argc, char** argv) 170{ 171 glutInit(&argc, argv); 172 glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB 173 | GLUT_ACCUM | GLUT_DEPTH); 174 glutInitWindowSize (250, 250); 175 glutCreateWindow (argv[0]); 176 myinit(); 177 glutReshapeFunc (myReshape); 178 glutDisplayFunc(display); 179 glutKeyboardFunc(key); 180 glutMainLoop(); 181 return 0; /* ANSI C requires main to return int. */ 182} 183