]> git.jsancho.org Git - lugaru.git/blob - Source/Environment/Skybox.cpp
468329a53a9e69de274d76ad522569a90f1d8ed3
[lugaru.git] / Source / Environment / Skybox.cpp
1 /*
2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
4
5 This file is part of Lugaru.
6
7 Lugaru is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 Lugaru is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "Environment/Skybox.hpp"
22
23 #include "Game.hpp"
24
25 extern float viewdistance;
26 extern float blurness;
27 extern int environment;
28 extern bool skyboxtexture;
29 extern float skyboxr;
30 extern float skyboxg;
31 extern float skyboxb;
32
33 void SkyBox::load(const std::string& ffront, const std::string& fleft, const std::string& fback,
34                   const std::string& fright, const std::string& fup, const std::string& fdown)
35 {
36     front.load(ffront, true);
37     left.load(fleft, true);
38     back.load(fback, true);
39     right.load(fright, true);
40     up.load(fup, true);
41     down.load(fdown, true);
42 }
43
44 void SkyBox::draw()
45 {
46     static float size = viewdistance / 4;
47     glPushMatrix();
48     static GLfloat M[16];
49     glGetFloatv(GL_MODELVIEW_MATRIX, M);
50     M[12] = 0;
51     M[13] = 0;
52     M[14] = 0;
53     glLoadMatrixf(M);
54     if (environment == desertenvironment) {
55         glScalef(1 + blurness / 1000, 1, 1 + blurness / 1000);
56         glColor3f(1 * skyboxr, .95 * skyboxg, .95 * skyboxb);
57     } else {
58         glColor3f(.85 * skyboxr, .85 * skyboxg, .95 * skyboxb);
59     }
60
61     if (!skyboxtexture) {
62         glDisable(GL_TEXTURE_2D);
63         glColor3f(skyboxr * .8, skyboxg * .8, skyboxb * .8);
64     }
65     glDepthMask(0);
66     glDisable(GL_CULL_FACE);
67     glEnable(GL_BLEND);
68     glDisable(GL_LIGHTING);
69     if (skyboxtexture)
70         glEnable(GL_TEXTURE_2D);
71     glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
72     front.bind();
73     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
74     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
75     glBegin(GL_QUADS);
76     glNormal3f(0.0f, 0.0f, -1);
77     glTexCoord2f(0, 0);
78     glVertex3f(-size, -size, size);
79     glTexCoord2f(1, 0);
80     glVertex3f(size, -size, size);
81     glTexCoord2f(1, 1);
82     glVertex3f(size, size, size);
83     glTexCoord2f(0, 1);
84     glVertex3f(-size, size, size);
85     glEnd();
86     back.bind();
87     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
88     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
89     glBegin(GL_QUADS);
90     glNormal3f(0.0f, 0.0f, 1);
91     glTexCoord2f(1, 0);
92     glVertex3f(-size, -size, -size);
93     glTexCoord2f(1, 1);
94     glVertex3f(-size, size, -size);
95     glTexCoord2f(0, 1);
96     glVertex3f(size, size, -size);
97     glTexCoord2f(0, 0);
98     glVertex3f(size, -size, -size);
99     glEnd();
100     up.bind();
101     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
102     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
103     glBegin(GL_QUADS);
104     glNormal3f(0.0f, -1.0f, 0);
105     glTexCoord2f(0, 1);
106     glVertex3f(-size, size, -size);
107     glTexCoord2f(0, 0);
108     glVertex3f(-size, size, size);
109     glTexCoord2f(1, 0);
110     glVertex3f(size, size, size);
111     glTexCoord2f(1, 1);
112     glVertex3f(size, size, -size);
113     glEnd();
114     down.bind();
115     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
116     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
117     glBegin(GL_QUADS);
118     glNormal3f(0.0f, 1.0f, 0);
119
120     glTexCoord2f(0, 0);
121     glVertex3f(-size, -size, -size);
122     glTexCoord2f(1, 0);
123     glVertex3f(size, -size, -size);
124     glTexCoord2f(1, 1);
125     glVertex3f(size, -size, size);
126     glTexCoord2f(0, 1);
127     glVertex3f(-size, -size, size);
128     glEnd();
129     right.bind();
130     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
131     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
132     glBegin(GL_QUADS);
133     glNormal3f(-1.0f, 0.0f, 0);
134     glTexCoord2f(1, 0);
135     glVertex3f(size, -size, -size);
136     glTexCoord2f(1, 1);
137     glVertex3f(size, size, -size);
138     glTexCoord2f(0, 1);
139     glVertex3f(size, size, size);
140     glTexCoord2f(0, 0);
141     glVertex3f(size, -size, size);
142     glEnd();
143     left.bind();
144     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
145     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
146     glBegin(GL_QUADS);
147     glNormal3f(1.0f, 0.0f, 0);
148     glTexCoord2f(0, 0);
149     glVertex3f(-size, -size, -size);
150     glTexCoord2f(1, 0);
151     glVertex3f(-size, -size, size);
152     glTexCoord2f(1, 1);
153     glVertex3f(-size, size, size);
154     glTexCoord2f(0, 1);
155     glVertex3f(-size, size, -size);
156     glEnd();
157     glEnable(GL_CULL_FACE);
158     glDepthMask(1);
159     glPopMatrix();
160 }