2 /* Copyright (c) Mark J. Kilgard, 1994. */
5 * (c) Copyright 1993, Silicon Graphics, Inc.
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.
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.
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.
38 * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
46 /* Initialize lighting and other values.
48 static void myinit(void)
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 };
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
);
61 glEnable(GL_LIGHTING
);
64 glEnable(GL_DEPTH_TEST
);
65 glShadeModel (GL_FLAT
);
67 glClearColor(0.0, 0.0, 0.0, 0.0);
68 glClearAccum(0.0, 0.0, 0.0, 0.0);
71 static void displayObjects(void)
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 };
79 glRotatef (30.0, 1.0, 0.0, 0.0);
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);
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
);
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);
104 glTranslatef (0.70, -0.90, 0.25);
105 glMaterialfv(GL_FRONT
, GL_DIFFUSE
, octa_diffuse
);
106 glutSolidOctahedron ();
114 static void display(void)
119 glGetIntegerv (GL_VIEWPORT
, viewport
);
121 glClear(GL_ACCUM_BUFFER_BIT
);
122 for (jitter
= 0; jitter
< ACSIZE
; jitter
++) {
123 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
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
130 glTranslatef (j8
[jitter
].x
*4.5/viewport
[2],
131 j8
[jitter
].y
*4.5/viewport
[3], 0.0);
134 glAccum(GL_ACCUM
, 1.0/ACSIZE
);
136 glAccum (GL_RETURN
, 1.0);
140 static void myReshape(int w
, int h
)
142 glViewport(0, 0, w
, h
);
143 glMatrixMode(GL_PROJECTION
);
146 glOrtho (-2.25, 2.25, -2.25*h
/w
, 2.25*h
/w
, -10.0, 10.0);
148 glOrtho (-2.25*w
/h
, 2.25*w
/h
, -2.25, 2.25, -10.0, 10.0);
149 glMatrixMode(GL_MODELVIEW
);
153 key(unsigned char k
, int x
, int y
)
156 case 27: /* Escape */
166 * Open window with initial window size, title bar,
167 * RGBA display mode, and handle input events.
169 int main(int argc
, char** argv
)
171 glutInit(&argc
, argv
);
172 glutInitDisplayMode (GLUT_SINGLE
| GLUT_RGB
173 | GLUT_ACCUM
| GLUT_DEPTH
);
174 glutInitWindowSize (250, 250);
175 glutCreateWindow (argv
[0]);
177 glutReshapeFunc (myReshape
);
178 glutDisplayFunc(display
);
179 glutKeyboardFunc(key
);
181 return 0; /* ANSI C requires main to return int. */