]> git.jsancho.org Git - lugaru.git/blob - Source/Environment/Skybox.cpp
Sorted all source files in folders
[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.h"
22 #include "Game.h"
23
24 extern float viewdistance;
25 extern float blurness;
26 extern int environment;
27 extern bool skyboxtexture;
28 extern float skyboxr;
29 extern float skyboxg;
30 extern float skyboxb;
31
32 void SkyBox::load (const std::string& ffront, const std::string& fleft, const std::string& fback,
33                    const std::string& fright, const std::string& fup,   const std::string& fdown)
34 {
35     front.load(ffront, true);
36     left.load(fleft, true);
37     back.load(fback, true);
38     right.load(fright, true);
39     up.load(fup, true);
40     down.load(fdown, true);
41 }
42
43 void SkyBox::draw()
44 {
45     static float size = viewdistance / 4;
46     glPushMatrix();
47     static GLfloat M[16];
48     glGetFloatv(GL_MODELVIEW_MATRIX, M);
49     M[12] = 0;
50     M[13] = 0;
51     M[14] = 0;
52     glLoadMatrixf(M);
53     if (environment == desertenvironment) {
54         glScalef(1 + blurness / 1000, 1, 1 + blurness / 1000);
55         glColor3f(1 * skyboxr, .95 * skyboxg, .95 * skyboxb);
56     } else {
57         glColor3f(.85 * skyboxr, .85 * skyboxg, .95 * skyboxb);
58     }
59
60     if (!skyboxtexture) {
61         glDisable(GL_TEXTURE_2D);
62         glColor3f(skyboxr * .8, skyboxg * .8, skyboxb * .8);
63     }
64     glDepthMask(0);
65     glDisable(GL_CULL_FACE);
66     glEnable(GL_BLEND);
67     glDisable(GL_LIGHTING);
68     if (skyboxtexture)
69         glEnable(GL_TEXTURE_2D);
70     glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
71     front.bind();
72     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
73     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
74     glBegin(GL_QUADS);
75     glNormal3f( 0.0f, 0.0f, -1);
76     glTexCoord2f(0, 0);
77     glVertex3f(-size, -size,  size);
78     glTexCoord2f(1, 0);
79     glVertex3f( size, -size,  size);
80     glTexCoord2f(1, 1);
81     glVertex3f( size,  size,  size);
82     glTexCoord2f(0, 1);
83     glVertex3f(-size,  size,  size);
84     glEnd();
85     back.bind();
86     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
87     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
88     glBegin(GL_QUADS);
89     glNormal3f( 0.0f, 0.0f, 1);
90     glTexCoord2f(1, 0);
91     glVertex3f(-size, -size, -size);
92     glTexCoord2f(1, 1);
93     glVertex3f(-size,  size, -size);
94     glTexCoord2f(0, 1);
95     glVertex3f( size,  size, -size);
96     glTexCoord2f(0, 0);
97     glVertex3f( size, -size, -size);
98     glEnd();
99     up.bind();
100     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
101     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
102     glBegin(GL_QUADS);
103     glNormal3f( 0.0f, -1.0f, 0);
104     glTexCoord2f(0, 1);
105     glVertex3f(-size,  size, -size);
106     glTexCoord2f(0, 0);
107     glVertex3f(-size,  size,  size);
108     glTexCoord2f(1, 0);
109     glVertex3f( size,  size,  size);
110     glTexCoord2f(1, 1);
111     glVertex3f( size,  size, -size);
112     glEnd();
113     down.bind();
114     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
115     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
116     glBegin(GL_QUADS);
117     glNormal3f( 0.0f, 1.0f, 0);
118
119     glTexCoord2f(0, 0);
120     glVertex3f(-size, -size, -size);
121     glTexCoord2f(1, 0);
122     glVertex3f( size, -size, -size);
123     glTexCoord2f(1, 1);
124     glVertex3f( size, -size,  size);
125     glTexCoord2f(0, 1);
126     glVertex3f(-size, -size,  size);
127     glEnd();
128     right.bind();
129     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
130     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
131     glBegin(GL_QUADS);
132     glNormal3f( -1.0f, 0.0f, 0);
133     glTexCoord2f(1, 0);
134     glVertex3f( size, -size, -size);
135     glTexCoord2f(1, 1);
136     glVertex3f( size,  size, -size);
137     glTexCoord2f(0, 1);
138     glVertex3f( size,  size,  size);
139     glTexCoord2f(0, 0);
140     glVertex3f( size, -size,  size);
141     glEnd();
142     left.bind();
143     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
144     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
145     glBegin(GL_QUADS);
146     glNormal3f( 1.0f, 0.0f, 0);
147     glTexCoord2f(0, 0);
148     glVertex3f(-size, -size, -size);
149     glTexCoord2f(1, 0);
150     glVertex3f(-size, -size,  size);
151     glTexCoord2f(1, 1);
152     glVertex3f(-size,  size,  size);
153     glTexCoord2f(0, 1);
154     glVertex3f(-size,  size, -size);
155     glEnd();
156     glEnable(GL_CULL_FACE);
157     glDepthMask(1);
158     glPopMatrix();
159 }
160
161 SkyBox::~SkyBox()
162 {
163     front.destroy();
164     left.destroy();
165     back.destroy();
166     right.destroy();
167     up.destroy();
168     down.destroy();
169 };
170