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").
55
GLfloat polyfactor = 1.0;
56
GLfloat polyunits = 1.0;
57
GLboolean doubleBuffer;
60
/* display() draws two spheres, one with a gray, diffuse material,
61
* the other sphere with a magenta material with a specular highlight.
63
static void display (void)
65
GLfloat gray[] = { 0.8, 0.8, 0.8, 1.0 };
66
GLfloat black[] = { 0.0, 0.0, 0.0, 1.0 };
68
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
70
glTranslatef (0.0, 0.0, tdist);
71
glRotatef ((GLfloat) spinx, 1.0, 0.0, 0.0);
72
glRotatef ((GLfloat) spiny, 0.0, 1.0, 0.0);
74
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
75
glMaterialfv(GL_FRONT, GL_SPECULAR, black);
76
glMaterialf(GL_FRONT, GL_SHININESS, 0.0);
78
glEnable(GL_LIGHTING);
80
glEnable(GL_POLYGON_OFFSET_FILL);
81
glPolygonOffset(polyfactor, polyunits);
83
glDisable(GL_POLYGON_OFFSET_FILL);
86
glDisable(GL_LIGHTING);
88
glColor3f (1.0, 1.0, 1.0);
89
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
90
glPolygonOffset(-polyfactor, -polyunits);
91
if (!fill) glEnable(GL_POLYGON_OFFSET_LINE);
93
glDisable(GL_POLYGON_OFFSET_LINE);
94
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
97
glEnable(GL_LIGHTING);
104
if (doubleBuffer) glutSwapBuffers();
107
/* specify initial properties
108
* create display list with sphere
109
* initialize lighting and depth buffer
111
static void gfxinit (void)
113
GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 };
114
GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
115
GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
116
GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
118
GLfloat global_ambient[] = { 0.2, 0.2, 0.2, 1.0 };
120
glClearColor (0.0, 0.0, 0.0, 1.0);
122
list = glGenLists(1);
123
glNewList (list, GL_COMPILE);
124
glutSolidSphere(1.0, 20, 12);
127
glEnable(GL_DEPTH_TEST);
129
glLightfv (GL_LIGHT0, GL_AMBIENT, light_ambient);
130
glLightfv (GL_LIGHT0, GL_DIFFUSE, light_diffuse);
131
glLightfv (GL_LIGHT0, GL_SPECULAR, light_specular);
132
glLightfv (GL_LIGHT0, GL_POSITION, light_position);
133
glLightModelfv (GL_LIGHT_MODEL_AMBIENT, global_ambient);
136
/* call when window is resized */
137
static void reshape(int width, int height)
139
glViewport (0, 0, width, height);
140
glMatrixMode (GL_PROJECTION);
142
gluPerspective(45.0, (GLdouble)width/(GLdouble)height,
144
glMatrixMode (GL_MODELVIEW);
146
gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
149
static void Benchmark( float xdiff, float ydiff )
151
int startTime, endTime;
155
printf("Benchmarking...\n");
159
startTime = glutGet(GLUT_ELAPSED_TIME);
166
endTime = glutGet(GLUT_ELAPSED_TIME);
167
} while (endTime - startTime < 5000); /* 5 seconds */
170
seconds = (double) (endTime - startTime) / 1000.0;
171
fps = draws / seconds;
172
printf("Result: fps: %g\n", fps);
177
/* call when mouse button is pressed */
179
static void mouse(int button, int state, int x, int y) {
181
case GLUT_LEFT_BUTTON:
191
case GLUT_MIDDLE_BUTTON:
201
case GLUT_RIGHT_BUTTON:
216
static void keyboard (unsigned char key, int x, int y)
221
tdist = (tdist + 0.5);
227
tdist = (tdist - 0.5);
232
polyfactor = polyfactor + 0.1;
233
printf ("polyfactor is %f\n", polyfactor);
237
polyfactor = polyfactor - 0.1;
238
printf ("polyfactor is %f\n", polyfactor);
242
polyunits = polyunits + 1.0;
243
printf ("polyunits is %f\n", polyunits);
247
polyunits = polyunits - 1.0;
248
printf ("polyunits is %f\n", polyunits);
259
printf ("fill/line: %d\n", fill);
262
case 27: /* Escape */
271
static GLenum Args(int argc, char **argv)
275
doubleBuffer = GL_FALSE;
277
for (i = 1; i < argc; i++) {
278
if (strcmp(argv[i], "-sb") == 0) {
279
doubleBuffer = GL_FALSE;
280
} else if (strcmp(argv[i], "-db") == 0) {
281
doubleBuffer = GL_TRUE;
283
printf("%s (Bad option).\n", argv[i]);
292
* Open window with initial window size, title bar,
293
* RGBA display mode, and handle input events.
295
int main(int argc, char** argv)
298
glutInit(&argc, argv);
302
type = GLUT_DEPTH | GLUT_RGB;
303
type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
305
glutInitDisplayMode(type);
306
glutCreateWindow("polyoff");
307
glutReshapeFunc(reshape);
308
glutDisplayFunc(display);
309
glutMouseFunc(mouse);
310
glutKeyboardFunc(keyboard);
316
int main(int argc, char** argv)
318
fprintf (stderr, "This program demonstrates a feature which is not in OpenGL Version 1.0.\n");
319
fprintf (stderr, "If your implementation of OpenGL Version 1.0 has the right extensions,\n");
320
fprintf (stderr, "you may be able to modify this program to make it run.\n");