]> git.jsancho.org Git - lugaru.git/blob - Source/Environment/Skybox.cpp
Added braces to all statements with clang-tidy and ran clang-format again
[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     }
72     glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
73     front.bind();
74     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
75     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
76     glBegin(GL_QUADS);
77     glNormal3f(0.0f, 0.0f, -1);
78     glTexCoord2f(0, 0);
79     glVertex3f(-size, -size, size);
80     glTexCoord2f(1, 0);
81     glVertex3f(size, -size, size);
82     glTexCoord2f(1, 1);
83     glVertex3f(size, size, size);
84     glTexCoord2f(0, 1);
85     glVertex3f(-size, size, size);
86     glEnd();
87     back.bind();
88     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
89     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
90     glBegin(GL_QUADS);
91     glNormal3f(0.0f, 0.0f, 1);
92     glTexCoord2f(1, 0);
93     glVertex3f(-size, -size, -size);
94     glTexCoord2f(1, 1);
95     glVertex3f(-size, size, -size);
96     glTexCoord2f(0, 1);
97     glVertex3f(size, size, -size);
98     glTexCoord2f(0, 0);
99     glVertex3f(size, -size, -size);
100     glEnd();
101     up.bind();
102     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
103     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
104     glBegin(GL_QUADS);
105     glNormal3f(0.0f, -1.0f, 0);
106     glTexCoord2f(0, 1);
107     glVertex3f(-size, size, -size);
108     glTexCoord2f(0, 0);
109     glVertex3f(-size, size, size);
110     glTexCoord2f(1, 0);
111     glVertex3f(size, size, size);
112     glTexCoord2f(1, 1);
113     glVertex3f(size, size, -size);
114     glEnd();
115     down.bind();
116     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
117     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
118     glBegin(GL_QUADS);
119     glNormal3f(0.0f, 1.0f, 0);
120
121     glTexCoord2f(0, 0);
122     glVertex3f(-size, -size, -size);
123     glTexCoord2f(1, 0);
124     glVertex3f(size, -size, -size);
125     glTexCoord2f(1, 1);
126     glVertex3f(size, -size, size);
127     glTexCoord2f(0, 1);
128     glVertex3f(-size, -size, size);
129     glEnd();
130     right.bind();
131     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
132     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
133     glBegin(GL_QUADS);
134     glNormal3f(-1.0f, 0.0f, 0);
135     glTexCoord2f(1, 0);
136     glVertex3f(size, -size, -size);
137     glTexCoord2f(1, 1);
138     glVertex3f(size, size, -size);
139     glTexCoord2f(0, 1);
140     glVertex3f(size, size, size);
141     glTexCoord2f(0, 0);
142     glVertex3f(size, -size, size);
143     glEnd();
144     left.bind();
145     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
146     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
147     glBegin(GL_QUADS);
148     glNormal3f(1.0f, 0.0f, 0);
149     glTexCoord2f(0, 0);
150     glVertex3f(-size, -size, -size);
151     glTexCoord2f(1, 0);
152     glVertex3f(-size, -size, size);
153     glTexCoord2f(1, 1);
154     glVertex3f(-size, size, size);
155     glTexCoord2f(0, 1);
156     glVertex3f(-size, size, -size);
157     glEnd();
158     glEnable(GL_CULL_FACE);
159     glDepthMask(1);
160     glPopMatrix();
161 }