4 extern float viewdistance;
8 extern int environment;
9 extern TGAImageRec texture;
10 extern bool skyboxtexture;
14 extern int tutoriallevel;
16 bool SkyBox::load( char *ffront,char *fleft,char *fback,char *fright,char *fup,char *fdown,char *fcloud,char *freflect)
18 /* static GLuint type;
19 unsigned char fileNamep[256];
24 Game::LoadTexture(ffront, &front, true, false);
26 Game::LoadTexture(fleft, &left, true, false);
28 Game::LoadTexture(fback, &back, true, false);
30 Game::LoadTexture(fright, &right, true, false);
32 Game::LoadTexture(fup, &up, true, false);
34 Game::LoadTexture(fdown, &down, true, false);
36 Game::LoadTexture(fcloud, &cloud, true, false);
38 Game::LoadTexture(freflect, &reflect, true, false);
41 CopyCStringToPascal(ffront,fileNamep);
42 upload_image( fileNamep ,0);
44 if ( texture.bpp == 24 )
49 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
51 if(!front)glGenTextures( 1, &front );
52 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
54 glBindTexture( GL_TEXTURE_2D, front);
55 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
56 //glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
57 if(trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
58 if(!trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
60 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
65 CopyCStringToPascal(fleft,fileNamep);
66 upload_image( fileNamep ,0);
68 if ( texture.bpp == 24 )
73 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
75 if(!left)glGenTextures( 1, &left );
76 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
78 glBindTexture( GL_TEXTURE_2D, left);
79 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
80 //glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
81 if(trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
82 if(!trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
84 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
89 CopyCStringToPascal(fback,fileNamep);
90 upload_image( fileNamep ,0);
92 if ( texture.bpp == 24 )
97 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
99 if(!back)glGenTextures( 1, &back );
100 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
102 glBindTexture( GL_TEXTURE_2D, back);
103 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
104 //glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
105 if(trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
106 if(!trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
108 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
113 CopyCStringToPascal(fright,fileNamep);
114 upload_image( fileNamep ,0);
116 if ( texture.bpp == 24 )
121 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
123 if(!right)glGenTextures( 1, &right );
124 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
126 glBindTexture( GL_TEXTURE_2D, right);
127 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
128 //glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
129 if(trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
130 if(!trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
132 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
137 CopyCStringToPascal(fup,fileNamep);
138 upload_image( fileNamep ,0);
140 if ( texture.bpp == 24 )
145 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
147 if(!up)glGenTextures( 1, &up );
148 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
150 glBindTexture( GL_TEXTURE_2D, up);
151 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
152 //glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
153 if(trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
154 if(!trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
156 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
161 CopyCStringToPascal(fdown,fileNamep);
162 upload_image( fileNamep ,0);
164 if ( texture.bpp == 24 )
169 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
171 if(!down)glGenTextures( 1, &down );
172 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
174 glBindTexture( GL_TEXTURE_2D, down);
175 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
176 //glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
177 if(trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
178 if(!trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
180 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
185 CopyCStringToPascal(fcloud,fileNamep);
186 upload_image( fileNamep ,0);
188 if ( texture.bpp == 24 )
193 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
195 if(!cloud)glGenTextures( 1, &cloud );
196 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
198 glBindTexture( GL_TEXTURE_2D, cloud);
199 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
200 //glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
201 if(trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
202 if(!trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
204 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
209 CopyCStringToPascal(freflect,fileNamep);
210 upload_image( fileNamep ,0);
212 if ( texture.bpp == 24 )
217 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
219 if(!reflect)glGenTextures( 1, &reflect );
220 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
222 glBindTexture( GL_TEXTURE_2D, reflect);
223 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
224 //glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
225 if(trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
226 if(!trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
228 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
237 static float size=viewdistance/4;
239 static GLfloat M[16];
240 glGetFloatv(GL_MODELVIEW_MATRIX,M);
245 //if(environment==2)glTranslatef(0,blurness*viewdistance/1000,0);
246 if(environment==2)glScalef(1+blurness/1000,1,1+blurness/1000);
247 if(environment!=2)glColor3f(.85*skyboxr,.85*skyboxg,.95*skyboxb);
248 else glColor3f(1*skyboxr,.95*skyboxg,.95*skyboxb);
251 glDisable(GL_TEXTURE_2D);
252 glColor3f(skyboxr*.8,skyboxg*.8,skyboxb*.8);
255 glDisable(GL_CULL_FACE);
257 glDisable(GL_LIGHTING);
258 // glActiveTextureARB(GL_TEXTURE0_ARB);
259 if(skyboxtexture)glEnable(GL_TEXTURE_2D);
260 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
261 glBindTexture(GL_TEXTURE_2D, front);
262 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
263 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
265 glNormal3f( 0.0f, 0.0f, -1);
266 glTexCoord2f(0, 0); glVertex3f(-size, -size, size);
267 glTexCoord2f(1, 0); glVertex3f( size, -size, size);
268 glTexCoord2f(1, 1); glVertex3f( size, size, size);
269 glTexCoord2f(0, 1); glVertex3f(-size, size, size);
271 glBindTexture(GL_TEXTURE_2D, back);
272 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
273 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
275 glNormal3f( 0.0f, 0.0f, 1);
276 glTexCoord2f(1, 0); glVertex3f(-size, -size, -size);
277 glTexCoord2f(1, 1); glVertex3f(-size, size, -size);
278 glTexCoord2f(0, 1); glVertex3f( size, size, -size);
279 glTexCoord2f(0, 0); glVertex3f( size, -size, -size);
281 glBindTexture(GL_TEXTURE_2D, up);
282 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
283 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
285 glNormal3f( 0.0f, -1.0f, 0);
286 glTexCoord2f(0, 1); glVertex3f(-size, size, -size);
287 glTexCoord2f(0, 0); glVertex3f(-size, size, size);
288 glTexCoord2f(1, 0); glVertex3f( size, size, size);
289 glTexCoord2f(1, 1); glVertex3f( size, size, -size);
292 glBindTexture(GL_TEXTURE_2D, down);
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, 1.0f, 0);
298 glTexCoord2f(0, 0); glVertex3f(-size, -size, -size);
299 glTexCoord2f(1, 0); glVertex3f( size, -size, -size);
300 glTexCoord2f(1, 1); glVertex3f( size, -size, size);
301 glTexCoord2f(0, 1); glVertex3f(-size, -size, size);
304 glBindTexture(GL_TEXTURE_2D, right);
305 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
306 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
308 glNormal3f( -1.0f, 0.0f, 0);
309 glTexCoord2f(1, 0); glVertex3f( size, -size, -size);
310 glTexCoord2f(1, 1); glVertex3f( size, size, -size);
311 glTexCoord2f(0, 1); glVertex3f( size, size, size);
312 glTexCoord2f(0, 0); glVertex3f( size, -size, size);
314 glBindTexture(GL_TEXTURE_2D, left);
315 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
316 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
318 glNormal3f( 1.0f, 0.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);
327 glBindTexture(GL_TEXTURE_2D, cloud);
328 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
329 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
331 glNormal3f( 0.0f, -1.0f, 0);
332 glTexCoord2f(0, (1+cloudmove)*30); glVertex3f(-size, size/200, -size);
333 glTexCoord2f(0, 0); glVertex3f(-size, size/200, size);
334 glTexCoord2f((1+cloudmove)*30, 0); glVertex3f( size, size/200, size);
335 glTexCoord2f((1+cloudmove)*30, (1+cloudmove)*30); glVertex3f( size, size/200, -size);
337 glDisable(GL_BLEND);*/
338 glEnable(GL_CULL_FACE);
345 front = 0,left = 0,back = 0,right = 0,up = 0,down = 0,cloud = 0,reflect = 0;
350 if (front) glDeleteTextures( 1, &front );
351 if (left) glDeleteTextures( 1, &left );
352 if (back) glDeleteTextures( 1, &back );
353 if (right) glDeleteTextures( 1, &right );
354 if (up) glDeleteTextures( 1, &up );
355 if (down) glDeleteTextures( 1, &down );
356 if (cloud) glDeleteTextures( 1, &cloud );
357 if (reflect) glDeleteTextures( 1, &reflect );