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.
42 * This program demonstrates the use of local versus
43 * infinite lighting on a flat plane.
48 /* Initialize material property, light source, and lighting model.
52 GLfloat mat_ambient
[] = { 0.0, 0.0, 0.0, 1.0 };
53 /* mat_specular and mat_shininess are NOT default values */
54 GLfloat mat_diffuse
[] = { 0.4, 0.4, 0.4, 1.0 };
55 GLfloat mat_specular
[] = { 1.0, 1.0, 1.0, 1.0 };
56 GLfloat mat_shininess
[] = { 15.0 };
58 GLfloat light_ambient
[] = { 0.0, 0.0, 0.0, 1.0 };
59 GLfloat light_diffuse
[] = { 1.0, 1.0, 1.0, 1.0 };
60 GLfloat light_specular
[] = { 1.0, 1.0, 1.0, 1.0 };
61 GLfloat lmodel_ambient
[] = { 0.2, 0.2, 0.2, 1.0 };
63 glMaterialfv(GL_FRONT
, GL_AMBIENT
, mat_ambient
);
64 glMaterialfv(GL_FRONT
, GL_DIFFUSE
, mat_diffuse
);
65 glMaterialfv(GL_FRONT
, GL_SPECULAR
, mat_specular
);
66 glMaterialfv(GL_FRONT
, GL_SHININESS
, mat_shininess
);
67 glLightfv(GL_LIGHT0
, GL_AMBIENT
, light_ambient
);
68 glLightfv(GL_LIGHT0
, GL_DIFFUSE
, light_diffuse
);
69 glLightfv(GL_LIGHT0
, GL_SPECULAR
, light_specular
);
70 glLightModelfv(GL_LIGHT_MODEL_AMBIENT
, lmodel_ambient
);
72 glEnable(GL_LIGHTING
);
75 glEnable(GL_DEPTH_TEST
);
81 glNormal3f (0.0, 0.0, 1.0);
82 glVertex3f (-1.0, -1.0, 0.0);
83 glVertex3f (0.0, -1.0, 0.0);
84 glVertex3f (0.0, 0.0, 0.0);
85 glVertex3f (-1.0, 0.0, 0.0);
87 glNormal3f (0.0, 0.0, 1.0);
88 glVertex3f (0.0, -1.0, 0.0);
89 glVertex3f (1.0, -1.0, 0.0);
90 glVertex3f (1.0, 0.0, 0.0);
91 glVertex3f (0.0, 0.0, 0.0);
93 glNormal3f (0.0, 0.0, 1.0);
94 glVertex3f (0.0, 0.0, 0.0);
95 glVertex3f (1.0, 0.0, 0.0);
96 glVertex3f (1.0, 1.0, 0.0);
97 glVertex3f (0.0, 1.0, 0.0);
99 glNormal3f (0.0, 0.0, 1.0);
100 glVertex3f (0.0, 0.0, 0.0);
101 glVertex3f (0.0, 1.0, 0.0);
102 glVertex3f (-1.0, 1.0, 0.0);
103 glVertex3f (-1.0, 0.0, 0.0);
109 GLfloat infinite_light
[] = { 1.0, 1.0, 1.0, 0.0 };
110 GLfloat local_light
[] = { 1.0, 1.0, 1.0, 1.0 };
112 glClear (GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
115 glTranslatef (-1.5, 0.0, 0.0);
116 glLightfv (GL_LIGHT0
, GL_POSITION
, infinite_light
);
121 glTranslatef (1.5, 0.0, 0.0);
122 glLightfv (GL_LIGHT0
, GL_POSITION
, local_light
);
128 void myReshape(int w
, int h
)
130 glViewport (0, 0, w
, h
);
131 glMatrixMode (GL_PROJECTION
);
134 glOrtho (-1.5, 1.5, -1.5*(GLdouble
)h
/(GLdouble
)w
,
135 1.5*(GLdouble
)h
/(GLdouble
)w
, -10.0, 10.0);
137 glOrtho (-1.5*(GLdouble
)w
/(GLdouble
)h
,
138 1.5*(GLdouble
)w
/(GLdouble
)h
, -1.5, 1.5, -10.0, 10.0);
139 glMatrixMode (GL_MODELVIEW
);
143 key(unsigned char k
, int x
, int y
)
146 case 27: /* Escape */
156 * Open window with initial window size, title bar,
157 * RGBA display mode, and handle input events.
159 int main(int argc
, char** argv
)
161 glutInit(&argc
, argv
);
162 glutInitDisplayMode (GLUT_SINGLE
| GLUT_RGB
| GLUT_DEPTH
);
163 glutInitWindowSize (500, 200);
164 glutCreateWindow (argv
[0]);
166 glutReshapeFunc (myReshape
);
167 glutDisplayFunc(display
);
168 glutKeyboardFunc(key
);
170 return 0; /* ANSI C requires main to return int. */