]> git.jsancho.org Git - lugaru.git/blob - Source/GameInitDispose.cpp
cleanup
[lugaru.git] / Source / GameInitDispose.cpp
1 /*
2 Copyright (C) 2003, 2010 - Wolfire Games
3
4 This file is part of Lugaru.
5
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.
10
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.
14
15 See the GNU General Public License for more details.
16
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.
20 */
21
22 #include "Game.h"
23 #include "openal_wrapper.h"
24 #include "Animation.h"
25
26 extern float screenwidth,screenheight;
27 extern float viewdistance;
28 extern XYZ viewer;
29 extern XYZ lightlocation;
30 extern float lightambient[3],lightbrightness[3];
31 extern float fadestart;
32 extern float texscale;
33 extern float gravity;
34 extern Light light;
35 extern Skeleton testskeleton;
36 extern int numsounds;
37 extern Terrain terrain;
38 //extern Sprites sprites;
39 extern int kTextureSize;
40 extern float texdetail;
41 extern float realtexdetail;
42 extern float volume;
43 extern Objects objects;
44 extern int detail;
45 extern bool cellophane;
46 extern GLubyte bloodText[512*512*3];
47 extern GLubyte wolfbloodText[512*512*3];
48 extern bool ismotionblur;
49 extern bool trilinear;
50 extern bool osx;
51 extern bool musictoggle;
52 extern int environment;
53 extern bool ambientsound;
54 extern float multiplier;
55 extern int netdatanew;
56 extern float mapinfo;
57 extern bool stillloading;
58 extern TGAImageRec texture;
59 extern short vRefNum;
60 extern long dirID;
61 extern int mainmenu;
62 extern int oldmainmenu;
63 extern bool visibleloading;
64 extern float flashamount,flashr,flashg,flashb;
65 extern int flashdelay;
66 extern int whichjointstartarray[26];
67 extern int whichjointendarray[26];
68 extern int difficulty;
69 extern float tintr,tintg,tintb;
70 extern float slomospeed;
71 extern bool gamestarted;
72
73 extern int numdialogues;
74 extern int numdialogueboxes[20];
75 extern int dialoguetype[20];
76 extern int dialogueboxlocation[20][20];
77 extern float dialogueboxcolor[20][20][3];
78 extern int dialogueboxsound[20][20];
79 extern char dialoguetext[20][20][128];
80 extern char dialoguename[20][20][64];
81 extern XYZ dialoguecamera[20][20];
82 extern float dialoguecamerarotation[20][20];
83 extern float dialoguecamerarotation2[20][20];
84 extern int indialogue;
85 extern int whichdialogue;
86 extern float dialoguetime;
87
88 extern float accountcampaignhighscore[10];
89 extern float accountcampaignfasttime[10];
90 extern float accountcampaignscore[10];
91 extern float accountcampaigntime[10];
92
93 extern int accountcampaignchoicesmade[10];
94 extern int accountcampaignchoices[10][5000];
95
96 void LOG(const std::string &fmt, ...)
97 {
98     // !!! FIXME: write me.
99 }
100
101
102 Game::TextureList Game::textures;
103
104 void Game::Dispose()
105 {
106         int i,j;
107
108         LOGFUNC;
109
110         if(endgame==2){
111                 accountactive->endGame();
112                 endgame=0;
113         }
114
115         Account::saveFile(":Data:Users", accountactive);
116
117         TexIter it = textures.begin();
118         for (; it != textures.end(); ++it)
119         {
120                 if (glIsTexture(it->second))
121                         glDeleteTextures(1, &it->second);
122         }
123         textures.clear();
124
125         LOG("Shutting down sound system...");
126
127         OPENAL_StopSound(OPENAL_ALL);
128
129 // this is causing problems on Linux, but we'll force an _exit() a little
130 //  later in the shutdown process.  --ryan.
131 #if !PLATFORM_LINUX
132
133         for (i=0; i < sounds_count; ++i)
134         {
135                 OPENAL_Sample_Free(samp[i]);
136         }
137
138         OPENAL_Close();
139         if (texture.data)
140         {
141                 free(texture.data);
142         }
143         texture.data = 0;
144 #endif
145 }
146
147
148 void Game::LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha)
149 {
150         GLuint          type;
151
152         LOGFUNC;
153
154         LOG(std::string("Loading texture...") + fileName);
155
156         // Fix filename so that is os appropreate
157         char * fixedFN = ConvertFileName(fileName);
158
159         unsigned char fileNamep[256];
160         CopyCStringToPascal(fixedFN, fileNamep);
161         //Load Image
162         upload_image( fileNamep ,hasalpha);
163
164 //      std::string fname(fileName);
165 //      std::transform(fname.begin(), fname.end(), tolower);
166 //      TexIter it = textures.find(fname);
167
168         //Is it valid?
169         if(1==1)
170         //if(textures.end() == it)
171         {
172                 //Alpha channel?
173                 if ( texture.bpp == 24 )
174                         type = GL_RGB;
175                 else
176                         type = GL_RGBA;
177
178                 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
179
180                 if(!*textureid)
181                         glGenTextures( 1, textureid );
182                 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
183
184                 glBindTexture( GL_TEXTURE_2D, *textureid);
185                 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
186                 if(trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
187                 if(!trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
188                 if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
189                 
190                 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
191         }
192 }
193
194 void Game::LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize)
195 {
196         GLuint          type;
197         int i;
198         int bytesPerPixel;
199
200         LOGFUNC;
201
202         LOG(std::string("Loading texture (S)...") + fileName);
203
204         //Load Image
205         unsigned char fileNamep[256];
206         CopyCStringToPascal(ConvertFileName(fileName), fileNamep);
207         //Load Image
208         upload_image( fileNamep ,0);
209         //LoadTGA( fileName );
210
211 //      std::string fname(fileName);
212 //      std::transform(fname.begin(), fname.end(), tolower);
213 //      TexIter it = textures.find(fname);
214
215         //Is it valid?
216         if(1==1)
217         //if(textures.end() == it)
218         {
219                 bytesPerPixel=texture.bpp/8;
220
221                 //Alpha channel?
222                 if ( texture.bpp == 24 )
223                         type = GL_RGB;
224                 else
225                         type = GL_RGBA;
226
227                 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
228
229                 if(!*textureid)glGenTextures( 1, textureid );
230                 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
231
232                 glBindTexture( GL_TEXTURE_2D, *textureid);
233                 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
234                 if(trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
235                 if(!trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
236                 if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
237
238                 int tempnum=0;
239                 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
240                         if((i+1)%4||type==GL_RGB){
241                                 array[tempnum]=texture.data[i];
242                                 tempnum++;
243                         }
244                 }
245
246                 *skinsize=texture.sizeX;
247
248                 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, GL_RGB, GL_UNSIGNED_BYTE, array );
249
250 //              textures.insert(std::make_pair(fname, *textureid));
251         }
252 //      else
253 //      {
254 //              *textureid = it->second;
255 //      }
256 }
257
258 void Game::LoadSave(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize)
259 {
260         int i;
261         int bytesPerPixel;
262
263         LOGFUNC;
264
265         LOG(std::string("Loading (S)...") + fileName);
266
267         //Load Image
268         float temptexdetail=texdetail;
269         texdetail=1;
270         //upload_image( fileName );
271         //LoadTGA( fileName );
272
273         // Converting file to something os specific
274         char * fixedFN = ConvertFileName(fileName);
275
276         //Load Image
277         unsigned char fileNamep[256];
278         CopyCStringToPascal(fixedFN, fileNamep);
279         //Load Image
280         upload_image( fileNamep ,0);
281         texdetail=temptexdetail;
282
283         //Is it valid?
284         if(1==1){
285                 bytesPerPixel=texture.bpp/8;
286
287                 int tempnum=0;
288                 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
289                         if((i+1)%4||bytesPerPixel==3){
290                                 array[tempnum]=texture.data[i];
291                                 tempnum++;
292                         }
293                 }
294         }
295 }
296
297 bool Game::AddClothes(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize)
298 {
299         int i;
300         int bytesPerPixel;
301
302         LOGFUNC;
303
304         //upload_image( fileName );
305         //LoadTGA( fileName );
306         //Load Image
307         unsigned char fileNamep[256];
308         CopyCStringToPascal(fileName,fileNamep);
309         //Load Image
310         bool opened;
311         opened=upload_image( fileNamep ,1);
312
313         float alphanum;
314         //Is it valid?
315         if(opened){
316                 if(tintr>1)tintr=1;
317                 if(tintg>1)tintg=1;
318                 if(tintb>1)tintb=1;
319
320                 if(tintr<0)tintr=0;
321                 if(tintg<0)tintg=0;
322                 if(tintb<0)tintb=0;
323
324                 bytesPerPixel=texture.bpp/8;
325
326                 int tempnum=0;
327                 alphanum=255;
328                 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
329                         if(bytesPerPixel==3)alphanum=255;
330                         else if((i+1)%4==0)alphanum=texture.data[i];
331                         //alphanum/=2;
332                         if((i+1)%4||bytesPerPixel==3){
333                                 if((i%4)==0)texture.data[i]*=tintr;
334                                 if((i%4)==1)texture.data[i]*=tintg;
335                                 if((i%4)==2)texture.data[i]*=tintb;
336                                 array[tempnum]=(float)array[tempnum]*(1-alphanum/255)+(float)texture.data[i]*(alphanum/255);
337                                 tempnum++;
338                         }
339                 }
340         }
341         else return 0;
342         return 1;
343 }
344
345
346 //***************> ResizeGLScene() <******/
347 GLvoid Game::ReSizeGLScene(float fov, float pnear)
348 {
349         if (screenheight==0)
350         {
351                 screenheight=1;
352         }
353
354         glViewport(0,0,screenwidth,screenheight);
355
356         glMatrixMode(GL_PROJECTION);
357         glLoadIdentity();
358
359         gluPerspective(fov,(GLfloat)screenwidth/(GLfloat)screenheight,pnear,viewdistance);
360
361         glMatrixMode(GL_MODELVIEW);
362         glLoadIdentity();
363 }
364
365 void Game::LoadingScreen()
366 {
367         static float loadprogress,minprogress,maxprogress;
368         static AbsoluteTime time = {0,0};
369         static AbsoluteTime frametime = {0,0};
370         AbsoluteTime currTime = UpTime ();
371         double deltaTime = (float) AbsoluteDeltaToDuration (currTime, frametime);
372
373         if (0 > deltaTime)      // if negative microseconds
374                 deltaTime /= -1000000.0;
375         else                            // else milliseconds
376                 deltaTime /= 1000.0;
377
378         multiplier=deltaTime;
379         if(multiplier<.001)multiplier=.001;
380         if(multiplier>10)multiplier=10;
381         if(multiplier>.05){
382                 frametime = currTime;   // reset for next time interval
383
384                 float size=1;
385                 glLoadIdentity();
386                 //Clear to black
387                 glClearColor(0,0,0,1);
388                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
389
390
391                 loadtime+=multiplier*4;
392
393                 loadprogress=loadtime;
394                 if(loadprogress>100)loadprogress=100;
395
396                 //loadprogress=abs(Random()%100);
397
398                 //Background
399
400                 glEnable(GL_TEXTURE_2D);
401                 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
402                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
403                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
404                 glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
405                 glDisable(GL_CULL_FACE);
406                 glDisable(GL_LIGHTING);
407                 glDepthMask(0);
408                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
409                 glPushMatrix();                                                                         // Store The Projection Matrix
410                 glLoadIdentity();                                                                       // Reset The Projection Matrix
411                 glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
412                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
413                 glPushMatrix();                                                                         // Store The Modelview Matrix
414                 glLoadIdentity();                                                               // Reset The Modelview Matrix
415                 glTranslatef(screenwidth/2,screenheight/2,0);
416                 glScalef((float)screenwidth/2,(float)screenheight/2,1);
417                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
418                 glDisable(GL_BLEND);
419                 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
420                 glPushMatrix();
421                 //glScalef(.25,.25,.25);
422                 glBegin(GL_QUADS);
423                 glTexCoord2f(.1-loadprogress/100,0+loadprogress/100+.3);
424                 glVertex3f(-1,          -1,      0.0f);
425                 glTexCoord2f(.1-loadprogress/100,0+loadprogress/100+.3);
426                 glVertex3f(1,   -1,      0.0f);
427                 glTexCoord2f(.1-loadprogress/100,1+loadprogress/100+.3);
428                 glVertex3f(1,   1, 0.0f);
429                 glTexCoord2f(.1-loadprogress/100,1+loadprogress/100+.3);
430                 glVertex3f(-1,  1, 0.0f);
431                 glEnd();
432                 glPopMatrix();
433                 glEnable(GL_BLEND);
434                 glPushMatrix();
435                 //glScalef(.25,.25,.25);
436                 glBegin(GL_QUADS);
437                 glTexCoord2f(.4+loadprogress/100,0+loadprogress/100);
438                 glVertex3f(-1,          -1,      0.0f);
439                 glTexCoord2f(.4+loadprogress/100,0+loadprogress/100);
440                 glVertex3f(1,   -1,      0.0f);
441                 glTexCoord2f(.4+loadprogress/100,1+loadprogress/100);
442                 glVertex3f(1,   1, 0.0f);
443                 glTexCoord2f(.4+loadprogress/100,1+loadprogress/100);
444                 glVertex3f(-1,  1, 0.0f);
445                 glEnd();
446                 glPopMatrix();
447                 glDisable(GL_TEXTURE_2D);
448                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
449                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
450                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
451                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
452                 glDisable(GL_BLEND);
453                 glDepthMask(1);
454
455                 glEnable(GL_TEXTURE_2D);
456                 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
457                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
458                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
459                 glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
460                 glDisable(GL_CULL_FACE);
461                 glDisable(GL_LIGHTING);
462                 glDepthMask(0);
463                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
464                 glPushMatrix();                                                                         // Store The Projection Matrix
465                 glLoadIdentity();                                                                       // Reset The Projection Matrix
466                 glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
467                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
468                 glPushMatrix();                                                                         // Store The Modelview Matrix
469                 glLoadIdentity();                                                               // Reset The Modelview Matrix
470                 glTranslatef(screenwidth/2,screenheight/2,0);
471                 glScalef((float)screenwidth/2*(1.5-(loadprogress)/200),(float)screenheight/2*(1.5-(loadprogress)/200),1);
472                 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
473                 glEnable(GL_BLEND);
474                 //glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
475                 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
476                 glPushMatrix();
477                 //glScalef(.25,.25,.25);
478                 glBegin(GL_QUADS);
479                 glTexCoord2f(0+.5,0+.5);
480                 glVertex3f(-1,          -1,      0.0f);
481                 glTexCoord2f(1+.5,0+.5);
482                 glVertex3f(1,   -1,      0.0f);
483                 glTexCoord2f(1+.5,1+.5);
484                 glVertex3f(1,   1, 0.0f);
485                 glTexCoord2f(0+.5,1+.5);
486                 glVertex3f(-1,  1, 0.0f);
487                 glEnd();
488                 glPopMatrix();
489                 glDisable(GL_TEXTURE_2D);
490                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
491                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
492                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
493                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
494                 glDisable(GL_BLEND);
495                 glDepthMask(1);
496
497                 glEnable(GL_TEXTURE_2D);
498                 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
499                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
500                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
501                 glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
502                 glDisable(GL_CULL_FACE);
503                 glDisable(GL_LIGHTING);
504                 glDepthMask(0);
505                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
506                 glPushMatrix();                                                                         // Store The Projection Matrix
507                 glLoadIdentity();                                                                       // Reset The Projection Matrix
508                 glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
509                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
510                 glPushMatrix();                                                                         // Store The Modelview Matrix
511                 glLoadIdentity();                                                               // Reset The Modelview Matrix
512                 glTranslatef(screenwidth/2,screenheight/2,0);
513                 glScalef((float)screenwidth/2*(100+loadprogress)/100,(float)screenheight/2*(100+loadprogress)/100,1);
514                 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
515                 glEnable(GL_BLEND);
516                 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,.4);
517                 glPushMatrix();
518                 //glScalef(.25,.25,.25);
519                 glBegin(GL_QUADS);
520                 glTexCoord2f(0+.2,0+.8);
521                 glVertex3f(-1,          -1,      0.0f);
522                 glTexCoord2f(1+.2,0+.8);
523                 glVertex3f(1,   -1,      0.0f);
524                 glTexCoord2f(1+.2,1+.8);
525                 glVertex3f(1,   1, 0.0f);
526                 glTexCoord2f(0+.2,1+.8);
527                 glVertex3f(-1,  1, 0.0f);
528                 glEnd();
529                 glPopMatrix();
530                 glDisable(GL_TEXTURE_2D);
531                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
532                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
533                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
534                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
535                 glDisable(GL_BLEND);
536                 glDepthMask(1);
537
538                 //Text
539                 /*
540                 glEnable(GL_TEXTURE_2D);
541                 static char string[256]="";
542                 sprintf (string, "LOADING... %d%",(int)loadprogress);
543                 glColor4f(1,1,1,.2);
544                 text.glPrint(280-280*loadprogress/100/2/4,125-125*loadprogress/100/2/4,string,1,1+loadprogress/100,640,480);
545                 glColor4f(1.2-loadprogress/100,1.2-loadprogress/100,1.2-loadprogress/100,1);
546                 text.glPrint(280,125,string,1,1,640,480);
547                 */
548
549                 if(flashamount>0){
550                         if(flashamount>1)flashamount=1;
551                         if(flashdelay<=0)flashamount-=multiplier;
552                         flashdelay--;
553                         if(flashamount<0)flashamount=0;
554                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
555                         glDisable(GL_CULL_FACE);
556                         glDisable(GL_LIGHTING);
557                         glDisable(GL_TEXTURE_2D);
558                         glDepthMask(0);
559                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
560                         glPushMatrix();                                                                         // Store The Projection Matrix
561                         glLoadIdentity();                                                                       // Reset The Projection Matrix
562                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
563                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
564                         glPushMatrix();                                                                         // Store The Modelview Matrix
565                         glLoadIdentity();                                                               // Reset The Modelview Matrix
566                         glScalef(screenwidth,screenheight,1);
567                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
568                         glEnable(GL_BLEND);
569                         glColor4f(flashr,flashg,flashb,flashamount);
570                         glBegin(GL_QUADS);
571                         glVertex3f(0,           0,       0.0f);
572                         glVertex3f(256, 0,       0.0f);
573                         glVertex3f(256, 256, 0.0f);
574                         glVertex3f(0,   256, 0.0f);
575                         glEnd();
576                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
577                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
578                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
579                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
580                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
581                         glEnable(GL_CULL_FACE);
582                         glDisable(GL_BLEND);
583                         glDepthMask(1);
584                 }
585
586                 swap_gl_buffers();
587         }
588 }
589
590 void Game::FadeLoadingScreen(float howmuch)
591 {
592         static float loadprogress,minprogress,maxprogress;
593
594         float size=1;
595         glLoadIdentity();
596         //Clear to black
597         glClearColor(0,0,0,1);
598         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
599
600         loadprogress=howmuch;
601
602         //loadprogress=abs(Random()%100);
603
604         //Background
605
606         //glEnable(GL_TEXTURE_2D);
607         glDisable(GL_TEXTURE_2D);
608         //glBindTexture( GL_TEXTURE_2D, loadscreentexture);
609         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
610         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
611         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
612         glDisable(GL_CULL_FACE);
613         glDisable(GL_LIGHTING);
614         glDepthMask(0);
615         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
616         glPushMatrix();                                                                         // Store The Projection Matrix
617         glLoadIdentity();                                                                       // Reset The Projection Matrix
618         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
619         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
620         glPushMatrix();                                                                         // Store The Modelview Matrix
621         glLoadIdentity();                                                               // Reset The Modelview Matrix
622         glTranslatef(screenwidth/2,screenheight/2,0);
623         glScalef((float)screenwidth/2,(float)screenheight/2,1);
624         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
625         glDisable(GL_BLEND);
626         glColor4f(loadprogress/100,0,0,1);
627         glPushMatrix();
628         //glScalef(.25,.25,.25);
629         glBegin(GL_QUADS);
630         glTexCoord2f(0,0);
631         glVertex3f(-1,          -1,      0.0f);
632         glTexCoord2f(1,0);
633         glVertex3f(1,   -1,      0.0f);
634         glTexCoord2f(1,1);
635         glVertex3f(1,   1, 0.0f);
636         glTexCoord2f(0,1);
637         glVertex3f(-1,  1, 0.0f);
638         glEnd();
639         glPopMatrix();
640         glDisable(GL_TEXTURE_2D);
641         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
642         glPopMatrix();                                                                          // Restore The Old Projection Matrix
643         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
644         glPopMatrix();                                                                          // Restore The Old Projection Matrix
645         glDisable(GL_BLEND);
646         glDepthMask(1);
647         //Text
648         /*
649         glEnable(GL_TEXTURE_2D);
650         static char string[256]="";
651         sprintf (string, "LOADING... %d%",(int)loadprogress);
652         glColor4f(1,1,1,.2);
653         text.glPrint(280-280*loadprogress/100/2/4,125-125*loadprogress/100/2/4,string,1,1+loadprogress/100,640,480);
654         glColor4f(1.2-loadprogress/100,1.2-loadprogress/100,1.2-loadprogress/100,1);
655         text.glPrint(280,125,string,1,1,640,480);
656         */
657         swap_gl_buffers();
658 }
659
660
661 void Game::InitGame()
662 {
663 #if PLATFORM_MACOSX
664         ProcessSerialNumber PSN;
665         ProcessInfoRec pinfo;
666         FSSpec pspec;
667         OSStatus err;
668         /* set up process serial number */
669         PSN.highLongOfPSN = 0;
670         PSN.lowLongOfPSN = kCurrentProcess;
671         /* set up info block */
672         pinfo.processInfoLength = sizeof(pinfo);
673         pinfo.processName = NULL;
674         pinfo.processAppSpec = &pspec;
675         /* grab the vrefnum and directory */
676         err = GetProcessInformation(&PSN, &pinfo);
677         if (err == noErr) {
678                 vRefNum = pspec.vRefNum;
679                 dirID = pspec.parID;
680         }
681 #endif
682
683         LOGFUNC;
684
685         autocam=0;
686
687         int i,j;
688
689         numchallengelevels=14;
690
691         accountactive=Account::loadFile(":Data:Users");
692
693         tintr=1;
694         tintg=1;
695         tintb=1;
696
697         whichjointstartarray[0]=righthip;
698         whichjointendarray[0]=rightfoot;
699
700         whichjointstartarray[1]=righthip;
701         whichjointendarray[1]=rightankle;
702
703         whichjointstartarray[2]=righthip;
704         whichjointendarray[2]=rightknee;
705
706         whichjointstartarray[3]=rightknee;
707         whichjointendarray[3]=rightankle;
708
709         whichjointstartarray[4]=rightankle;
710         whichjointendarray[4]=rightfoot;
711
712         whichjointstartarray[5]=lefthip;
713         whichjointendarray[5]=leftfoot;
714
715         whichjointstartarray[6]=lefthip;
716         whichjointendarray[6]=leftankle;
717
718         whichjointstartarray[7]=lefthip;
719         whichjointendarray[7]=leftknee;
720
721         whichjointstartarray[8]=leftknee;
722         whichjointendarray[8]=leftankle;
723
724         whichjointstartarray[9]=leftankle;
725         whichjointendarray[9]=leftfoot;
726
727         whichjointstartarray[10]=abdomen;
728         whichjointendarray[10]=rightshoulder;
729
730         whichjointstartarray[11]=abdomen;
731         whichjointendarray[11]=rightelbow;
732
733         whichjointstartarray[12]=abdomen;
734         whichjointendarray[12]=rightwrist;
735
736         whichjointstartarray[13]=abdomen;
737         whichjointendarray[13]=righthand;
738
739         whichjointstartarray[14]=rightshoulder;
740         whichjointendarray[14]=rightelbow;
741
742         whichjointstartarray[15]=rightelbow;
743         whichjointendarray[15]=rightwrist;
744
745         whichjointstartarray[16]=rightwrist;
746         whichjointendarray[16]=righthand;
747
748         whichjointstartarray[17]=abdomen;
749         whichjointendarray[17]=leftshoulder;
750
751         whichjointstartarray[18]=abdomen;
752         whichjointendarray[18]=leftelbow;
753
754         whichjointstartarray[19]=abdomen;
755         whichjointendarray[19]=leftwrist;
756
757         whichjointstartarray[20]=abdomen;
758         whichjointendarray[20]=lefthand;
759
760         whichjointstartarray[21]=leftshoulder;
761         whichjointendarray[21]=leftelbow;
762
763         whichjointstartarray[22]=leftelbow;
764         whichjointendarray[22]=leftwrist;
765
766         whichjointstartarray[23]=leftwrist;
767         whichjointendarray[23]=lefthand;
768
769         whichjointstartarray[24]=abdomen;
770         whichjointendarray[24]=neck;
771
772         whichjointstartarray[25]=neck;
773         whichjointendarray[25]=head;
774
775         FadeLoadingScreen(0);
776
777         stillloading=1;
778
779         texture.data = ( GLubyte* )malloc( 1024*1024*4 );
780
781         int temptexdetail=texdetail;
782         texdetail=1;
783         text.LoadFontTexture(":Data:Textures:Font.png");
784         text.BuildFont();
785         texdetail=temptexdetail;
786
787         FadeLoadingScreen(10);
788
789         if(detail==2){
790                 texdetail=1;
791         }
792         if(detail==1){
793                 texdetail=2;
794         }
795         if(detail==0){
796                 texdetail=4;
797         }
798
799         LOG("Initializing sound system...");
800
801     int output = -1;
802
803     #if PLATFORM_LINUX
804     extern bool cmdline(const char *cmd);
805     unsigned char rc = 0;
806     output = OPENAL_OUTPUT_ALSA;  // Try alsa first...
807     if (cmdline("forceoss"))      //  ...but let user override that.
808         output = OPENAL_OUTPUT_OSS;
809     else if (cmdline("nosound"))
810         output = OPENAL_OUTPUT_NOSOUND;
811
812     OPENAL_SetOutput(output);
813         if ((rc = OPENAL_Init(44100, 32, 0)) == false)
814     {
815         // if we tried ALSA and failed, fall back to OSS.
816         if ( (output == OPENAL_OUTPUT_ALSA) && (!cmdline("forcealsa")) )
817         {
818             OPENAL_Close();
819             output = OPENAL_OUTPUT_OSS;
820             OPENAL_SetOutput(output);
821                 rc = OPENAL_Init(44100, 32, 0);
822         }
823     }
824
825     if (rc == false)
826     {
827         OPENAL_Close();
828         output = OPENAL_OUTPUT_NOSOUND;  // we tried! just do silence.
829         OPENAL_SetOutput(output);
830             rc = OPENAL_Init(44100, 32, 0);
831     }
832     #else
833         OPENAL_Init(44100, 32, 0);
834     #endif
835
836         OPENAL_SetSFXMasterVolume((int)(volume*255));
837         loadAllSounds();
838
839         if(musictoggle)
840           emit_stream_np(stream_music3);
841
842         LoadTexture(":Data:Textures:Cursor.png",&cursortexture,0,1);
843
844         LoadTexture(":Data:Textures:MapCircle.png",&Mapcircletexture,0,1);
845         LoadTexture(":Data:Textures:MapBox.png",&Mapboxtexture,0,1);
846         LoadTexture(":Data:Textures:MapArrow.png",&Maparrowtexture,0,1);
847
848         temptexdetail=texdetail;
849         if(texdetail>2)texdetail=2;
850         LoadTexture(":Data:Textures:Lugaru.png",&Mainmenuitems[0],0,0);
851         LoadTexture(":Data:Textures:Newgame.png",&Mainmenuitems[1],0,0);
852         LoadTexture(":Data:Textures:Options.png",&Mainmenuitems[2],0,0);
853         LoadTexture(":Data:Textures:Quit.png",&Mainmenuitems[3],0,0);
854         LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
855         LoadTexture(":Data:Textures:Eyelid.png",&Mainmenuitems[4],0,1);
856         //LoadTexture(":Data:Textures:Eye.jpg",&Mainmenuitems[5],0,1);
857         texdetail=temptexdetail;
858
859         loaddistrib=0;
860         anim=0;
861
862         FadeLoadingScreen(95);
863
864
865         gameon=0;
866         mainmenu=1;
867
868         stillloading=0;
869         firstload=0;
870         oldmainmenu=0;
871
872         newdetail=detail;
873         newscreenwidth=screenwidth;
874         newscreenheight=screenheight;
875 }
876
877
878 void Game::LoadStuff()
879 {
880         static float temptexdetail;
881         static float viewdistdetail;
882         static int i,j,texsize;
883         float megascale =1;
884
885         LOGFUNC;
886
887         visibleloading=1;
888
889         loadtime=0;
890
891         stillloading=1;
892
893         //texture.data = ( GLubyte* )malloc( 1024*1024*4 );
894
895         for(i=0;i<maxplayers;i++)
896         {
897                 if (glIsTexture(player[i].skeleton.drawmodel.textureptr))
898                 {
899                         glDeleteTextures(1, &player[i].skeleton.drawmodel.textureptr);
900                 }
901                 player[i].skeleton.drawmodel.textureptr=0;;
902         }
903
904         //temptexdetail=texdetail;
905         //texdetail=1;
906         i=abs(Random()%4);
907         LoadTexture(":Data:Textures:fire.jpg",&loadscreentexture,1,0);
908         //texdetail=temptexdetail;
909
910         temptexdetail=texdetail;
911         texdetail=1;
912         text.LoadFontTexture(":Data:Textures:Font.png");
913         text.BuildFont();
914         texdetail=temptexdetail;
915
916         numsounds=71;
917
918         viewdistdetail=2;
919         viewdistance=50*megascale*viewdistdetail;
920
921         brightness=100;
922
923
924
925         if(detail==2){
926                 texdetail=1;
927         }
928         if(detail==1){
929                 texdetail=2;
930         }
931         if(detail==0){
932                 texdetail=4;
933         }
934
935         realtexdetail=texdetail;
936
937         /*texdetail/=4;
938         if(texdetail<1)texdetail=1;
939         realtexdetail=texdetail*4;
940         */
941         numplayers=1;
942
943
944
945         /*LoadTexture(":Data:Textures:snow.png",&terraintexture,1);
946
947         LoadTexture(":Data:Textures:rock.png",&terraintexture2,1);
948
949         LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
950         */
951
952
953         LOG("Loading weapon data...");
954
955         LoadTexture(":Data:Textures:knife.png",&weapons.knifetextureptr,0,1);
956         LoadTexture(":Data:Textures:bloodknife.png",&weapons.bloodknifetextureptr,0,1);
957         LoadTexture(":Data:Textures:lightbloodknife.png",&weapons.lightbloodknifetextureptr,0,1);
958         LoadTexture(":Data:Textures:sword.jpg",&weapons.swordtextureptr,1,0);
959         LoadTexture(":Data:Textures:Swordblood.jpg",&weapons.bloodswordtextureptr,1,0);
960         LoadTexture(":Data:Textures:Swordbloodlight.jpg",&weapons.lightbloodswordtextureptr,1,0);
961         LoadTexture(":Data:Textures:Staff.jpg",&weapons.stafftextureptr,1,0);
962
963         weapons.throwingknifemodel.load((char *)":Data:Models:throwingknife.solid",1);
964         weapons.throwingknifemodel.Scale(.001,.001,.001);
965         //weapons.throwingknifemodel.Rotate(0,0,-90);
966         weapons.throwingknifemodel.Rotate(90,0,0);
967         weapons.throwingknifemodel.Rotate(0,90,0);
968         weapons.throwingknifemodel.flat=0;
969         weapons.throwingknifemodel.CalculateNormals(1);
970         //weapons.throwingknifemodel.ScaleNormals(-1,-1,-1);
971
972         weapons.swordmodel.load((char *)":Data:Models:sword.solid",1);
973         weapons.swordmodel.Scale(.001,.001,.001);
974         //weapons.swordmodel.Rotate(0,0,-90);
975         weapons.swordmodel.Rotate(90,0,0);
976         weapons.swordmodel.Rotate(0,90,0);
977         weapons.swordmodel.Rotate(0,0,90);
978         weapons.swordmodel.flat=1;
979         weapons.swordmodel.CalculateNormals(1);
980         //weapons.swordmodel.ScaleNormals(-1,-1,-1);
981
982         weapons.staffmodel.load((char *)":Data:Models:staff.solid",1);
983         weapons.staffmodel.Scale(.005,.005,.005);
984         //weapons.staffmodel.Rotate(0,0,-90);
985         weapons.staffmodel.Rotate(90,0,0);
986         weapons.staffmodel.Rotate(0,90,0);
987         weapons.staffmodel.Rotate(0,0,90);
988         weapons.staffmodel.flat=1;
989         weapons.staffmodel.CalculateNormals(1);
990         //weapons.staffmodel.ScaleNormals(-1,-1,-1);
991
992         //temptexdetail=texdetail;
993         //if(texdetail>4)texdetail=4;
994         LoadTexture(":Data:Textures:shadow.png",&terrain.shadowtexture,0,1);
995
996         LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture,0,1);
997
998         LoadTexture(":Data:Textures:break.png",&terrain.breaktexture,0,1);
999
1000         LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture2,0,1);
1001
1002
1003         LoadTexture(":Data:Textures:footprint.png",&terrain.footprinttexture,0,1);
1004
1005         LoadTexture(":Data:Textures:bodyprint.png",&terrain.bodyprinttexture,0,1);
1006
1007         /*LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1);
1008
1009         LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1);
1010
1011         LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1);
1012
1013         LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1);
1014
1015         LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1);
1016
1017         LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1);
1018         //texdetail=temptexdetail;
1019         LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1);*/
1020
1021
1022
1023         LoadTexture(":Data:Textures:hawk.png",&hawktexture,0,1);
1024
1025         LoadTexture(":Data:Textures:logo.png",&logotexture,0,1);
1026
1027
1028         //LoadTexture(":Data:Textures:box.jpg",&objects.boxtextureptr,1,0);
1029
1030
1031         LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1,1);
1032         LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1,1);
1033         LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1,1);
1034         LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1,1);
1035         LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1,1);
1036         LoadTexture(":Data:Textures:bloodflame.png",&Sprite::bloodflametexture,1,1);
1037         LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1,1);
1038         LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1,0);
1039         LoadTexture(":Data:Textures:splinter.png",&Sprite::splintertexture,1,1);
1040         LoadTexture(":Data:Textures:leaf.png",&Sprite::leaftexture,1,1);
1041         LoadTexture(":Data:Textures:tooth.png",&Sprite::toothtexture,1,1);
1042
1043         rotation=0;
1044         rotation2=0;
1045         ReSizeGLScene(90,.01);
1046
1047         viewer=0;
1048
1049
1050
1051
1052         if(detail)kTextureSize=1024;
1053         if(detail==1)kTextureSize=512;
1054         if(detail==0)kTextureSize=256;
1055
1056
1057         //drawmode=motionblurmode;
1058
1059         //Set up distant light
1060         light.color[0]=.95;
1061         light.color[1]=.95;
1062         light.color[2]=1;
1063         light.ambient[0]=.2;
1064         light.ambient[1]=.2;
1065         light.ambient[2]=.24;
1066         light.location.x=1;
1067         light.location.y=1;
1068         light.location.z=-.2;
1069         Normalise(&light.location);
1070
1071         LoadingScreen();
1072
1073         SetUpLighting();
1074
1075
1076         fadestart=.6;
1077         gravity=-10;
1078
1079         texscale=.2/megascale/viewdistdetail;
1080         terrain.scale=3*megascale*viewdistdetail;
1081
1082         viewer.x=terrain.size/2*terrain.scale;
1083         viewer.z=terrain.size/2*terrain.scale;
1084
1085         hawk.load((char *)":Data:Models:hawk.solid",1);
1086         hawk.Scale(.03,.03,.03);
1087         hawk.Rotate(90,1,1);
1088         hawk.CalculateNormals(0);
1089         hawk.ScaleNormals(-1,-1,-1);
1090         hawkcoords.x=terrain.size/2*terrain.scale-5-7;
1091         hawkcoords.z=terrain.size/2*terrain.scale-5-7;
1092         hawkcoords.y=terrain.getHeight(hawkcoords.x,hawkcoords.z)+25;
1093
1094
1095         eye.load((char *)":Data:Models:eye.solid",1);
1096         eye.Scale(.03,.03,.03);
1097         eye.CalculateNormals(0);
1098
1099         cornea.load((char *)":Data:Models:cornea.solid",1);
1100         cornea.Scale(.03,.03,.03);
1101         cornea.CalculateNormals(0);
1102
1103         iris.load((char *)":Data:Models:iris.solid",1);
1104         iris.Scale(.03,.03,.03);
1105         iris.CalculateNormals(0);
1106
1107         LoadSave(":Data:Textures:Bloodfur.png",0,1,&bloodText[0],0);
1108         LoadSave(":Data:Textures:Wolfbloodfur.png",0,1,&wolfbloodText[0],0);
1109
1110         oldenvironment=-4;
1111
1112         gameon=1;
1113         mainmenu=0;
1114
1115         firstload=0;
1116         //if(targetlevel!=7)
1117                 Loadlevel(targetlevel);
1118
1119
1120         rabbitcoords=player[0].coords;
1121         rabbitcoords.y=terrain.getHeight(rabbitcoords.x,rabbitcoords.z);
1122
1123         loadAllAnimations();
1124         //Fix knife stab, too lazy to do it manually
1125         XYZ moveamount;
1126         moveamount=0;
1127         moveamount.z=2;
1128         for(i=0;i<player[0].skeleton.num_joints;i++){
1129                 for(j=0;j<animation[knifesneakattackanim].numframes;j++){
1130                         animation[knifesneakattackanim].position[i][j]+=moveamount;
1131                 }
1132         }
1133
1134         LoadingScreen();
1135
1136         for(i=0;i<player[0].skeleton.num_joints;i++){
1137                 for(j=0;j<animation[knifesneakattackedanim].numframes;j++){
1138                         animation[knifesneakattackedanim].position[i][j]+=moveamount;
1139                 }
1140         }
1141
1142         LoadingScreen();
1143
1144         for(i=0;i<player[0].skeleton.num_joints;i++){
1145                 animation[dead1anim].position[i][1]=animation[dead1anim].position[i][0];
1146                 animation[dead2anim].position[i][1]=animation[dead2anim].position[i][0];
1147                 animation[dead3anim].position[i][1]=animation[dead3anim].position[i][0];
1148                 animation[dead4anim].position[i][1]=animation[dead4anim].position[i][0];
1149         }
1150         animation[dead1anim].speed[0]=0.001;
1151         animation[dead2anim].speed[0]=0.001;
1152         animation[dead3anim].speed[0]=0.001;
1153         animation[dead4anim].speed[0]=0.001;
1154
1155         animation[dead1anim].speed[1]=0.001;
1156         animation[dead2anim].speed[1]=0.001;
1157         animation[dead3anim].speed[1]=0.001;
1158         animation[dead4anim].speed[1]=0.001;
1159
1160         for(i=0;i<player[0].skeleton.num_joints;i++){
1161                 for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1162                         animation[swordsneakattackanim].position[i][j]+=moveamount;
1163                 }
1164         }
1165         LoadingScreen();
1166         for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1167                 animation[swordsneakattackanim].weapontarget[j]+=moveamount;
1168         }
1169
1170         LoadingScreen();
1171
1172         for(i=0;i<player[0].skeleton.num_joints;i++){
1173                 for(j=0;j<animation[swordsneakattackedanim].numframes;j++){
1174                         animation[swordsneakattackedanim].position[i][j]+=moveamount;
1175                 }
1176         }
1177         /*
1178         for(i=0;i<player[0].skeleton.num_joints;i++){
1179         for(j=0;j<animation[sleepanim].numframes;j++){
1180         animation[sleepanim].position[i][j]=DoRotation(animation[sleepanim].position[i][j],0,180,0);
1181         }
1182         }
1183         */
1184         LoadingScreen();
1185         temptexdetail=texdetail;
1186         texdetail=1;
1187         texdetail=temptexdetail;
1188
1189         LoadingScreen();
1190
1191         //if(ismotionblur){
1192         if(!screentexture){
1193                 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
1194
1195                 glGenTextures( 1, &screentexture );
1196                 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1197
1198
1199                 glEnable(GL_TEXTURE_2D);
1200                 glBindTexture( GL_TEXTURE_2D, screentexture);
1201                 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
1202                 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
1203
1204                 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);
1205         }
1206
1207         if(targetlevel!=7){
1208                 emit_sound_at(fireendsound);
1209         }
1210
1211         stillloading=0;
1212         loading=0;
1213         changedelay=1;
1214
1215         visibleloading=0;
1216 }
1217