chmod a-x **/glslnoise.c
[mesa-demos.git] / src / redbook / plane.c
blobdc17f7b2386710a6fa7bdd9d319bf1783d474638
2 /* Copyright (c) Mark J. Kilgard, 1994. */
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.
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.
41 * plane.c
42 * This program demonstrates the use of local versus
43 * infinite lighting on a flat plane.
45 #include <stdlib.h>
46 #include <GL/glut.h>
48 /* Initialize material property, light source, and lighting model.
50 void myinit(void)
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);
73 glEnable(GL_LIGHT0);
74 glDepthFunc(GL_LESS);
75 glEnable(GL_DEPTH_TEST);
78 void drawPlane(void)
80 glBegin (GL_QUADS);
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);
104 glEnd();
107 void display (void)
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);
114 glPushMatrix ();
115 glTranslatef (-1.5, 0.0, 0.0);
116 glLightfv (GL_LIGHT0, GL_POSITION, infinite_light);
117 drawPlane ();
118 glPopMatrix ();
120 glPushMatrix ();
121 glTranslatef (1.5, 0.0, 0.0);
122 glLightfv (GL_LIGHT0, GL_POSITION, local_light);
123 drawPlane ();
124 glPopMatrix ();
125 glFlush ();
128 void myReshape(int w, int h)
130 glViewport (0, 0, w, h);
131 glMatrixMode (GL_PROJECTION);
132 glLoadIdentity ();
133 if (w <= h)
134 glOrtho (-1.5, 1.5, -1.5*(GLdouble)h/(GLdouble)w,
135 1.5*(GLdouble)h/(GLdouble)w, -10.0, 10.0);
136 else
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);
142 static void
143 key(unsigned char k, int x, int y)
145 switch (k) {
146 case 27: /* Escape */
147 exit(0);
148 break;
149 default:
150 return;
152 glutPostRedisplay();
155 /* Main Loop
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]);
165 myinit();
166 glutReshapeFunc (myReshape);
167 glutDisplayFunc(display);
168 glutKeyboardFunc(key);
169 glutMainLoop();
170 return 0; /* ANSI C requires main to return int. */