2 * Copyright (c) 1993-1997, Silicon Graphics, Inc.
4 * Permission to use, copy, modify, and distribute this software for
5 * any purpose and without fee is hereby granted, provided that the above
6 * copyright notice appear in all copies and that both the copyright notice
7 * and this permission notice appear in supporting documentation, and that
8 * the name of Silicon Graphics, Inc. not be used in advertising
9 * or publicity pertaining to distribution of the software without specific,
10 * written prior permission.
12 * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
13 * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
14 * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
15 * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
16 * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
17 * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
18 * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
19 * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
20 * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
21 * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
22 * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
23 * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
25 * US Government Users Restricted Rights
26 * Use, duplication, or disclosure by the Government is subject to
27 * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
28 * (c)(1)(ii) of the Rights in Technical Data and Computer Software
29 * clause at DFARS 252.227-7013 and/or in similar or successor
30 * clauses in the FAR or the DOD or NASA FAR Supplement.
31 * Unpublished-- rights reserved under the copyright laws of the
32 * United States. Contractor/manufacturer is Silicon Graphics,
33 * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
35 * OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
40 * This program demonstrates polygon offset to draw a shaded
41 * polygon and its wireframe counterpart without ugly visual
42 * artifacts ("stitching").
53 GLfloat polyfactor
= 1.0;
54 GLfloat polyunits
= 1.0;
56 /* display() draws two spheres, one with a gray, diffuse material,
57 * the other sphere with a magenta material with a specular highlight.
61 GLfloat gray
[] = { 0.8, 0.8, 0.8, 1.0 };
62 GLfloat black
[] = { 0.0, 0.0, 0.0, 1.0 };
64 glClear (GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
66 glTranslatef (0.0, 0.0, tdist
);
67 glRotatef ((GLfloat
) spinx
, 1.0, 0.0, 0.0);
68 glRotatef ((GLfloat
) spiny
, 0.0, 1.0, 0.0);
70 glMaterialfv(GL_FRONT
, GL_AMBIENT_AND_DIFFUSE
, gray
);
71 glMaterialfv(GL_FRONT
, GL_SPECULAR
, black
);
72 glMaterialf(GL_FRONT
, GL_SHININESS
, 0.0);
73 glEnable(GL_LIGHTING
);
75 glEnable(GL_POLYGON_OFFSET_FILL
);
76 glPolygonOffset(polyfactor
, polyunits
);
78 glDisable(GL_POLYGON_OFFSET_FILL
);
80 glDisable(GL_LIGHTING
);
82 glColor3f (1.0, 1.0, 1.0);
83 glPolygonMode(GL_FRONT_AND_BACK
, GL_LINE
);
85 glPolygonMode(GL_FRONT_AND_BACK
, GL_FILL
);
91 /* specify initial properties
92 * create display list with sphere
93 * initialize lighting and depth buffer
97 GLfloat light_ambient
[] = { 0.0, 0.0, 0.0, 1.0 };
98 GLfloat light_diffuse
[] = { 1.0, 1.0, 1.0, 1.0 };
99 GLfloat light_specular
[] = { 1.0, 1.0, 1.0, 1.0 };
100 GLfloat light_position
[] = { 1.0, 1.0, 1.0, 0.0 };
102 GLfloat global_ambient
[] = { 0.2, 0.2, 0.2, 1.0 };
104 glClearColor (0.0, 0.0, 0.0, 1.0);
106 list
= glGenLists(1);
107 glNewList (list
, GL_COMPILE
);
108 glutSolidSphere(1.0, 20, 12);
111 glEnable(GL_DEPTH_TEST
);
113 glLightfv (GL_LIGHT0
, GL_AMBIENT
, light_ambient
);
114 glLightfv (GL_LIGHT0
, GL_DIFFUSE
, light_diffuse
);
115 glLightfv (GL_LIGHT0
, GL_SPECULAR
, light_specular
);
116 glLightfv (GL_LIGHT0
, GL_POSITION
, light_position
);
117 glLightModelfv (GL_LIGHT_MODEL_AMBIENT
, global_ambient
);
120 /* call when window is resized */
121 void reshape(int width
, int height
)
123 glViewport (0, 0, width
, height
);
124 glMatrixMode (GL_PROJECTION
);
126 gluPerspective(45.0, (GLdouble
)width
/(GLdouble
)height
,
128 glMatrixMode (GL_MODELVIEW
);
130 gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
133 /* call when mouse button is pressed */
135 void mouse(int button
, int state
, int x
, int y
) {
137 case GLUT_LEFT_BUTTON
:
140 spinx
= (spinx
+ 5) % 360;
147 case GLUT_MIDDLE_BUTTON
:
150 spiny
= (spiny
+ 5) % 360;
157 case GLUT_RIGHT_BUTTON
:
172 void keyboard (unsigned char key
, int x
, int y
)
177 tdist
= (tdist
+ 0.5);
183 tdist
= (tdist
- 0.5);
188 polyfactor
= polyfactor
+ 0.1;
189 printf ("polyfactor is %f\n", polyfactor
);
193 polyfactor
= polyfactor
- 0.1;
194 printf ("polyfactor is %f\n", polyfactor
);
198 polyunits
= polyunits
+ 1.0;
199 printf ("polyunits is %f\n", polyunits
);
203 polyunits
= polyunits
- 1.0;
204 printf ("polyunits is %f\n", polyunits
);
213 * Open window with initial window size, title bar,
214 * RGBA display mode, and handle input events.
216 int main(int argc
, char** argv
)
218 glutInit(&argc
, argv
);
219 glutInitDisplayMode(GLUT_SINGLE
| GLUT_RGB
| GLUT_DEPTH
);
220 glutCreateWindow(argv
[0]);
221 glutReshapeFunc(reshape
);
222 glutDisplayFunc(display
);
223 glutMouseFunc(mouse
);
224 glutKeyboardFunc(keyboard
);
230 int main(int argc
, char** argv
)
232 fprintf (stderr
, "This program demonstrates a feature which is not in OpenGL Version 1.0.\n");
233 fprintf (stderr
, "If your implementation of OpenGL Version 1.0 has the right extensions,\n");
234 fprintf (stderr
, "you may be able to modify this program to make it run.\n");