1 /*
2 * "fogpot.c" - A test program demonstrating the use of glFog() for
3 * depth-cueing.
4 */
5
6 #include <GL/glaux.h>
7 #include <GL/glpfile.h>
8
9
10 /*
11 * These #define constants are provided for compatibility between MS Windows
12 * and the rest of the world.
13 *
14 * CALLBACK and APIENTRY are function modifiers under MS Windows.
15 */
16
17 #ifndef WIN32
18 # define CALLBACK
19 # define APIENTRY
20 #endif /* !WIN32 */
21
22 GLfloat rotation = 0.0;
23 GLPfile *output;
24
25
26 /*
27 * 'reshape_scene()' - Change the size of the scene...
28 */
29
30 void CALLBACK
reshape_scene(GLsizei width,GLsizei height)31 reshape_scene(GLsizei width, /* I - Width of the window in pixels */
32 GLsizei height) /* I - Height of the window in pixels */
33 {
34 /*
35 * Reset the current viewport and perspective transformation...
36 */
37
38 glViewport(0, 0, width, height);
39
40 glMatrixMode(GL_PROJECTION);
41 glLoadIdentity();
42 gluPerspective(22.5, (float)width / (float)height, 0.1, 1000.0);
43
44 glMatrixMode(GL_MODELVIEW);
45 }
46
47
48 /*
49 * 'draw_scene()' - Draw a scene containing a cube with a sphere in front of
50 * it.
51 */
52
53 void CALLBACK
draw_scene(void)54 draw_scene(void)
55 {
56 static float red_light[4] = { 1.0, 0.0, 0.0, 1.0 };
57 static float red_pos[4] = { 1.0, 1.0, 1.0, 0.0 };
58 static float blue_light[4] = { 0.0, 0.0, 1.0, 1.0 };
59 static float blue_pos[4] = { -1.0, -1.0, -1.0, 0.0 };
60 static float fog_color[4] = { 0.0, 0.0, 0.0, 0.0 };
61
62
63 /*
64 * Enable drawing features that we need...
65 */
66
67 glEnable(GL_DEPTH_TEST);
68 glEnable(GL_LIGHTING);
69 glEnable(GL_LIGHT0);
70 glEnable(GL_LIGHT1);
71
72 glShadeModel(GL_SMOOTH);
73 // glShadeModel(GL_FLAT);
74
75 if (output != NULL)
76 output->StartPage();
77
78 /*
79 * Clear the color and depth buffers...
80 */
81
82 glClearColor(0.0, 0.0, 0.0, 0.0);
83 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
84
85 /*
86 * Draw the cube and sphere in different colors...
87 *
88 * We have positioned two lights in this scene. The first is red and
89 * located above, to the right, and behind the viewer. The second is blue
90 * and located below, to the left, and in front of the viewer.
91 */
92
93 glLightfv(GL_LIGHT0, GL_DIFFUSE, red_light);
94 glLightfv(GL_LIGHT0, GL_POSITION, red_pos);
95
96 glLightfv(GL_LIGHT1, GL_DIFFUSE, blue_light);
97 glLightfv(GL_LIGHT1, GL_POSITION, blue_pos);
98
99 glEnable(GL_COLOR_MATERIAL);
100
101 // glEnable(GL_FOG);
102 glFogf(GL_FOG_DENSITY, 0.25);
103 glFogfv(GL_FOG_COLOR, fog_color);
104
105 glPushMatrix();
106 glTranslatef(-1.0, -0.5, -15.0);
107 glRotatef(-rotation, 0.0, 1.0, 0.0);
108 glRotatef(rotation, 1.0, 0.0, 0.0);
109 glColor3f(1.0, 1.0, 0.0);
110
111 auxSolidCylinder(1.0, 1.0);
112 glPopMatrix();
113
114 glPushMatrix();
115 glTranslatef(1.0, 0.0, -10.0);
116 glRotatef(rotation, 0.0, 1.0, 0.0);
117 glRotatef(rotation, 1.0, 0.0, 0.0);
118
119 glColor3f(0.0, 1.0, 1.0);
120 auxSolidTeapot(1.0);
121 glPopMatrix();
122
123 if (output != NULL)
124 {
125 if (output->EndPage() == 0)
126 {
127 delete output;
128 output = NULL;
129 };
130 };
131
132 auxSwapBuffers();
133 }
134
135
136 /*
137 * 'rotate_objects()' - Rotate while we are idle...
138 */
139
140 void CALLBACK
rotate_objects(void)141 rotate_objects(void)
142 {
143 rotation += 2.0;
144 if (rotation >= 360.0)
145 rotation -= 360.0;
146
147 draw_scene();
148 }
149
150
151 /*
152 * 'main()' - Initialize the window and display the scene until the user presses
153 * the ESCape key.
154 */
155
156 void
main(void)157 main(void)
158 {
159 auxInitDisplayMode(AUX_RGB | AUX_DEPTH | AUX_DOUBLE);
160 auxInitPosition(256, 256, 768, 512);
161 auxInitWindow("Fogged Teapots");
162
163 auxReshapeFunc(reshape_scene);
164 auxIdleFunc(rotate_objects);
165
166 output = new GLPfile("test.ps");
167
168 auxMainLoop(draw_scene);
169 }
170
171
172 /*
173 * End of "fogpot.c".
174 */
175