-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfogplane.c
executable file
·72 lines (58 loc) · 1.88 KB
/
fogplane.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* Hostile Takeover:
* CS248 Final Project, Fall 2004
*
* Written by Jonathan Reeves
* jrreeves@stanford.edu
*
* A simple 3D video game demonstrating the use of OpenGL for graphics
* rendering with a number of advanced techniques and optimizations to make
* it interesting. See the README file which came with this package for more
* details. It also includes a list of sources which were consulted while
* building this software package.
*
*/
#include <GL/gl.h>
#include <GL/glu.h>
#include "fogplane.h"
float fogColor[4] = {0.8, 0.8, 0.8, 1.0};
/* just set up the gl parameters */
void FogPlaneSetup(float near, float far){
glFogi(GL_FOG_MODE, GL_LINEAR);
glFogfv(GL_FOG_COLOR, fogColor);
glFogf(GL_FOG_START, near);
glFogf(GL_FOG_END, far);
glHint(GL_FOG_HINT, GL_NICEST);
}
/* draw an alpha-blended set of planes which get more and more opaque as you
* go down */
void FogPlaneDraw(float yaw, float x, float y, float z){
glDisable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glPushMatrix();
glTranslatef(x, y, z);
glRotatef(yaw, 0.0, 1.0, 0.0);
glTranslatef(70.0, 0.0, 0.0);
glBegin(GL_QUAD_STRIP);
glColor4f(fogColor[0], fogColor[1], fogColor[2], 1.0);
glVertex3f(0.0, 0.0, -100.0);
glVertex3f(0.0, 0.0, 100.0);
glVertex3f(0.0, 1.0, -100.0);
glVertex3f(0.0, 1.0, 100.0);
glColor4f(fogColor[0], fogColor[1], fogColor[2], 1.0);
glVertex3f(0.0, 4.0, -100.0);
glVertex3f(0.0, 4.0, 100.0);
glVertex3f(0.0, 13.0, -100.0);
glVertex3f(0.0, 13.0, 100.0);
glColor4f(fogColor[0], fogColor[1], fogColor[2], 0.4);
glVertex3f(0.0, 20.0, -100.0);
glVertex3f(0.0, 20.0, 100.0);
glColor4f(fogColor[0], fogColor[1], fogColor[2], 0.0);
glVertex3f(0.0, 40.0, -100.0);
glVertex3f(0.0, 40.0, 100.0);
glEnd();
glPopMatrix();
glDisable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
}