2 Copyright (C) 2003, 2010 - Wolfire Games
4 This file is part of Lugaru.
6 Lugaru is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 See the GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 extern float viewdistance;
27 extern bool trilinear;
28 extern float blurness;
29 extern int environment;
30 extern TGAImageRec texture;
31 extern bool skyboxtexture;
35 extern int tutoriallevel;
37 bool SkyBox::load( const char *ffront,const char *fleft,const char *fback,const char *fright,const char *fup,const char *fdown,const char *fcloud,const char *freflect)
39 /* static GLuint type;
40 unsigned char fileNamep[256];
45 Game::LoadTexture(ffront, &front, true, false);
47 Game::LoadTexture(fleft, &left, true, false);
49 Game::LoadTexture(fback, &back, true, false);
51 Game::LoadTexture(fright, &right, true, false);
53 Game::LoadTexture(fup, &up, true, false);
55 Game::LoadTexture(fdown, &down, true, false);
57 Game::LoadTexture(fcloud, &cloud, true, false);
59 Game::LoadTexture(freflect, &reflect, true, false);
62 CopyCStringToPascal(ffront,fileNamep);
63 upload_image( fileNamep ,0);
65 if ( texture.bpp == 24 )
70 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
72 if(!front)glGenTextures( 1, &front );
73 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
75 glBindTexture( GL_TEXTURE_2D, front);
76 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
77 //glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
78 if(trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
79 if(!trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
81 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
86 CopyCStringToPascal(fleft,fileNamep);
87 upload_image( fileNamep ,0);
89 if ( texture.bpp == 24 )
94 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
96 if(!left)glGenTextures( 1, &left );
97 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
99 glBindTexture( GL_TEXTURE_2D, left);
100 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
101 //glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
102 if(trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
103 if(!trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
105 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
110 CopyCStringToPascal(fback,fileNamep);
111 upload_image( fileNamep ,0);
113 if ( texture.bpp == 24 )
118 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
120 if(!back)glGenTextures( 1, &back );
121 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
123 glBindTexture( GL_TEXTURE_2D, back);
124 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
125 //glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
126 if(trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
127 if(!trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
129 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
134 CopyCStringToPascal(fright,fileNamep);
135 upload_image( fileNamep ,0);
137 if ( texture.bpp == 24 )
142 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
144 if(!right)glGenTextures( 1, &right );
145 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
147 glBindTexture( GL_TEXTURE_2D, right);
148 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
149 //glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
150 if(trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
151 if(!trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
153 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
158 CopyCStringToPascal(fup,fileNamep);
159 upload_image( fileNamep ,0);
161 if ( texture.bpp == 24 )
166 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
168 if(!up)glGenTextures( 1, &up );
169 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
171 glBindTexture( GL_TEXTURE_2D, up);
172 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
173 //glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
174 if(trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
175 if(!trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
177 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
182 CopyCStringToPascal(fdown,fileNamep);
183 upload_image( fileNamep ,0);
185 if ( texture.bpp == 24 )
190 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
192 if(!down)glGenTextures( 1, &down );
193 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
195 glBindTexture( GL_TEXTURE_2D, down);
196 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
197 //glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
198 if(trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
199 if(!trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
201 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
206 CopyCStringToPascal(fcloud,fileNamep);
207 upload_image( fileNamep ,0);
209 if ( texture.bpp == 24 )
214 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
216 if(!cloud)glGenTextures( 1, &cloud );
217 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
219 glBindTexture( GL_TEXTURE_2D, cloud);
220 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
221 //glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
222 if(trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
223 if(!trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
225 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
230 CopyCStringToPascal(freflect,fileNamep);
231 upload_image( fileNamep ,0);
233 if ( texture.bpp == 24 )
238 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
240 if(!reflect)glGenTextures( 1, &reflect );
241 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
243 glBindTexture( GL_TEXTURE_2D, reflect);
244 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
245 //glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
246 if(trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
247 if(!trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
249 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
258 static float size=viewdistance/4;
260 static GLfloat M[16];
261 glGetFloatv(GL_MODELVIEW_MATRIX,M);
266 //if(environment==2)glTranslatef(0,blurness*viewdistance/1000,0);
267 if(environment==2)glScalef(1+blurness/1000,1,1+blurness/1000);
268 if(environment!=2)glColor3f(.85*skyboxr,.85*skyboxg,.95*skyboxb);
269 else glColor3f(1*skyboxr,.95*skyboxg,.95*skyboxb);
272 glDisable(GL_TEXTURE_2D);
273 glColor3f(skyboxr*.8,skyboxg*.8,skyboxb*.8);
276 glDisable(GL_CULL_FACE);
278 glDisable(GL_LIGHTING);
279 // glActiveTextureARB(GL_TEXTURE0_ARB);
280 if(skyboxtexture)glEnable(GL_TEXTURE_2D);
281 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
282 glBindTexture(GL_TEXTURE_2D, front);
283 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
284 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
286 glNormal3f( 0.0f, 0.0f, -1);
287 glTexCoord2f(0, 0); glVertex3f(-size, -size, size);
288 glTexCoord2f(1, 0); glVertex3f( size, -size, size);
289 glTexCoord2f(1, 1); glVertex3f( size, size, size);
290 glTexCoord2f(0, 1); glVertex3f(-size, size, size);
292 glBindTexture(GL_TEXTURE_2D, back);
293 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
294 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
296 glNormal3f( 0.0f, 0.0f, 1);
297 glTexCoord2f(1, 0); glVertex3f(-size, -size, -size);
298 glTexCoord2f(1, 1); glVertex3f(-size, size, -size);
299 glTexCoord2f(0, 1); glVertex3f( size, size, -size);
300 glTexCoord2f(0, 0); glVertex3f( size, -size, -size);
302 glBindTexture(GL_TEXTURE_2D, up);
303 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
304 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
306 glNormal3f( 0.0f, -1.0f, 0);
307 glTexCoord2f(0, 1); glVertex3f(-size, size, -size);
308 glTexCoord2f(0, 0); glVertex3f(-size, size, size);
309 glTexCoord2f(1, 0); glVertex3f( size, size, size);
310 glTexCoord2f(1, 1); glVertex3f( size, size, -size);
313 glBindTexture(GL_TEXTURE_2D, down);
314 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
315 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
317 glNormal3f( 0.0f, 1.0f, 0);
319 glTexCoord2f(0, 0); glVertex3f(-size, -size, -size);
320 glTexCoord2f(1, 0); glVertex3f( size, -size, -size);
321 glTexCoord2f(1, 1); glVertex3f( size, -size, size);
322 glTexCoord2f(0, 1); glVertex3f(-size, -size, size);
325 glBindTexture(GL_TEXTURE_2D, right);
326 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
327 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
329 glNormal3f( -1.0f, 0.0f, 0);
330 glTexCoord2f(1, 0); glVertex3f( size, -size, -size);
331 glTexCoord2f(1, 1); glVertex3f( size, size, -size);
332 glTexCoord2f(0, 1); glVertex3f( size, size, size);
333 glTexCoord2f(0, 0); glVertex3f( size, -size, size);
335 glBindTexture(GL_TEXTURE_2D, left);
336 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
337 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
339 glNormal3f( 1.0f, 0.0f, 0);
340 glTexCoord2f(0, 0); glVertex3f(-size, -size, -size);
341 glTexCoord2f(1, 0); glVertex3f(-size, -size, size);
342 glTexCoord2f(1, 1); glVertex3f(-size, size, size);
343 glTexCoord2f(0, 1); glVertex3f(-size, size, -size);
348 glBindTexture(GL_TEXTURE_2D, cloud);
349 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
350 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
352 glNormal3f( 0.0f, -1.0f, 0);
353 glTexCoord2f(0, (1+cloudmove)*30); glVertex3f(-size, size/200, -size);
354 glTexCoord2f(0, 0); glVertex3f(-size, size/200, size);
355 glTexCoord2f((1+cloudmove)*30, 0); glVertex3f( size, size/200, size);
356 glTexCoord2f((1+cloudmove)*30, (1+cloudmove)*30); glVertex3f( size, size/200, -size);
358 glDisable(GL_BLEND);*/
359 glEnable(GL_CULL_FACE);
366 front = 0,left = 0,back = 0,right = 0,up = 0,down = 0,cloud = 0,reflect = 0;
371 if (front) glDeleteTextures( 1, &front );
372 if (left) glDeleteTextures( 1, &left );
373 if (back) glDeleteTextures( 1, &back );
374 if (right) glDeleteTextures( 1, &right );
375 if (up) glDeleteTextures( 1, &up );
376 if (down) glDeleteTextures( 1, &down );
377 if (cloud) glDeleteTextures( 1, &cloud );
378 if (reflect) glDeleteTextures( 1, &reflect );