]> git.jsancho.org Git - lugaru.git/blob - Source/GameDraw.cpp
23692b30bac3096fb0d9ce5b3f34f0be5e82a2c7
[lugaru.git] / Source / GameDraw.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 "Input.h"
25 #include "Awards.h"
26
27 using namespace std;
28
29 extern XYZ viewer;
30 extern int environment;
31 extern float texscale;
32 extern Light light;
33 extern Terrain terrain;
34 //extern Sprites sprites;
35 extern float multiplier;
36 extern float sps;
37 extern float viewdistance;
38 extern float fadestart;
39 extern float screenwidth,screenheight;
40 extern int kTextureSize;
41 extern FRUSTUM frustum;
42 extern Light light;
43 extern Objects objects;
44 extern int detail;
45 extern float usermousesensitivity;
46 extern bool osx;
47 extern float camerashake;
48 extern int slomo;
49 extern float slomodelay;
50 extern bool ismotionblur;
51 extern float woozy;
52 extern float blackout;
53 extern bool damageeffects;
54 extern float volume;
55 extern bool texttoggle;
56 extern float blurness;
57 extern float targetblurness;
58 extern float playerdist;
59 extern bool cellophane;
60 extern bool freeze;
61 extern float flashamount,flashr,flashg,flashb;
62 extern int flashdelay;
63 extern int netstate;
64 extern float motionbluramount;
65 extern bool isclient;
66 extern bool alwaysblur;
67 extern int test;
68 extern bool tilt2weird;
69 extern bool tiltweird;
70 extern bool midweird;
71 extern bool proportionweird;
72 extern bool vertexweird[6];
73 extern bool velocityblur;
74 extern bool debugmode;
75 extern int mainmenu;
76 extern int oldmainmenu;
77 extern int bloodtoggle;
78 extern int difficulty;
79 extern bool decals;
80 // MODIFIED GWC
81 //extern int texdetail;
82 extern float texdetail;
83 extern bool musictoggle;
84 extern int tutoriallevel;
85 extern float smoketex;
86 extern float tutorialstagetime;
87 extern float tutorialmaxtime;
88 extern int tutorialstage;
89 extern bool againbonus;
90 extern float damagedealt;
91 extern bool invertmouse;
92
93 extern int numhotspots;
94 extern int winhotspot;
95 extern int killhotspot;
96 extern XYZ hotspot[40];
97 extern int hotspottype[40];
98 extern float hotspotsize[40];
99 extern char hotspottext[40][256];
100 extern int currenthotspot;;
101
102 extern bool campaign;
103 extern bool winfreeze;
104
105 extern float menupulse;
106
107 extern bool gamestart;
108
109 extern bool gamestarted;
110
111 extern bool showdamagebar;
112
113 enum drawmodes {
114   normalmode, motionblurmode, radialzoommode,
115   realmotionblurmode, doublevisionmode, glowmode,
116 };
117
118 void Game::flash() { // shouldn't be that way, these should be attributes and Person class should not change rendering.
119         flashr=1;
120         flashg=0;
121         flashb=0;
122         flashamount=1;
123         flashdelay=1;
124 }
125 /*********************> DrawGLScene() <*****/
126 int Game::DrawGLScene(StereoSide side)
127 {       
128         static float texcoordwidth,texcoordheight;
129         static float texviewwidth, texviewheight;
130         static int i,j,k,l;
131         static GLubyte color;
132         static XYZ checkpoint;
133         static float tempmult;
134         float tutorialopac;
135         static char string[256]="";
136         static char string2[256]="";
137         static char string3[256]="";
138
139         if ( stereomode == stereoAnaglyph ) {
140                 switch(side) {
141                         case stereoLeft: glColorMask( 0.0, 1.0, 1.0, 1.0 ); break;
142                         case stereoRight: glColorMask( 1.0, 0.0, 0.0, 1.0 ); break;
143                 }
144         } else {
145                 glColorMask( 1.0, 1.0, 1.0, 1.0 );
146                 
147                 if ( stereomode == stereoHorizontalInterlaced || stereomode == stereoVerticalInterlaced ) {
148                         glStencilFunc(side == stereoLeft ? GL_NOTEQUAL : GL_EQUAL, 0x01, 0x01);
149                 }
150         }
151
152         if(freeze||winfreeze||(mainmenu&&gameon)||(!gameon&&gamestarted)){
153                 tempmult=multiplier;
154                 multiplier=0;
155         }
156
157         if(!mainmenu){
158                 if(editorenabled){
159                         numboundaries=mapradius*2;
160                         if(numboundaries>360)numboundaries=360;
161                         for(i=0;i<numboundaries;i++){
162                                 boundary[i]=0;
163                                 boundary[i].z=1;
164                                 boundary[i]=mapcenter+DoRotation(boundary[i]*mapradius,0,i*(360/((float)(numboundaries))),0);
165                         }
166                 }
167
168                 SetUpLighting();
169
170                 static int changed;
171                 changed=0;
172
173                 olddrawmode=drawmode;
174                 if(ismotionblur&&!loading){
175                         if((findLengthfast(&player[0].velocity)>200)&&velocityblur&&!cameramode){
176                                 drawmode=motionblurmode;
177                                 motionbluramount=200/(findLengthfast(&player[0].velocity));
178                                 changed=1;
179                         }
180                         if(player[0].damage-player[0].superpermanentdamage>(player[0].damagetolerance-player[0].superpermanentdamage)*1/2&&damageeffects&&!cameramode){
181                                 drawmode=doublevisionmode;
182                                 changed=1;
183                         }
184                 }
185
186                 if(slomo&&!loading){
187                         if(ismotionblur)
188                                 drawmode=motionblurmode;
189                         motionbluramount=.2;
190                         slomodelay-=multiplier;
191                         if(slomodelay<0)slomo=0;
192                         camerashake=0;
193                         changed=1;
194                 }
195                 if((!changed&&!slomo)||loading){
196                         drawmode=normalmode;
197                         if(ismotionblur&&(/*fps>100||*/alwaysblur)){
198                                 if(olddrawmode!=realmotionblurmode)change=1;
199                                 else change=0;
200                                 drawmode=realmotionblurmode;
201                         }
202                         else if(olddrawmode==realmotionblurmode)change=2;
203                         else change=0;
204                 }
205
206                 if(freeze||winfreeze||(mainmenu&&gameon)||(!gameon&&gamestarted))drawmode=normalmode;
207                 if((freeze||winfreeze)&&ismotionblur&&!mainmenu)drawmode=radialzoommode;
208
209                 if(winfreeze||mainmenu)drawmode=normalmode;
210
211 #if PLATFORM_MACOSX
212                 if(drawmode==glowmode){
213                         RGBColor color2;
214                         color2.red=0;
215                         color2.green=0;
216                         color2.blue=0;
217                         DSpContext_FadeGamma(NULL,200,&color2);
218                 }
219 #endif
220
221                 if(drawtoggle!=2)drawtoggle=1-drawtoggle;
222
223                 if(!texcoordwidth){
224
225                         texviewwidth=kTextureSize;
226                         if(texviewwidth>screenwidth)texviewwidth=screenwidth;
227                         texviewheight=kTextureSize;
228                         if(texviewheight>screenheight)texviewheight=screenheight;
229
230                         texcoordwidth=screenwidth/kTextureSize;
231                         texcoordheight=screenheight/kTextureSize;
232                         if(texcoordwidth>1)texcoordwidth=1;
233                         if(texcoordheight>1)texcoordheight=1;
234                 }
235
236                 glDrawBuffer(GL_BACK);
237                 glReadBuffer(GL_BACK);
238
239                 if(abs(blurness-targetblurness)<multiplier*10||abs(blurness-targetblurness)>2){
240                         blurness=targetblurness;
241                         targetblurness=(float)(abs(Random()%100))/40;
242                 }
243                 if(blurness<targetblurness) 
244                         blurness+=multiplier*5;
245                 else
246                         blurness-=multiplier*5;
247
248                 //glFinish();
249                 static XYZ terrainlight;
250                 static float distance;
251                 if(drawmode==normalmode)ReSizeGLScene(90,.1f);
252                 if(drawmode!=normalmode)glViewport(0,0,texviewwidth,texviewheight);     
253                 glDepthFunc(GL_LEQUAL);
254                 glDepthMask(1);
255                 glAlphaFunc(GL_GREATER, 0.0001f);
256                 glEnable(GL_ALPHA_TEST);
257                 glClearColor(0.25f, 0.25f, 0.25f, 1.0f);
258                 glClear(GL_DEPTH_BUFFER_BIT);
259
260                 glMatrixMode (GL_MODELVIEW);
261                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
262                 glLoadIdentity ();
263                 
264                 // Move the camera for the current eye's point of view.
265                 // Reverse the movement if we're reversing stereo
266                 glTranslatef((stereoseparation/2) * side * (stereoreverse  ? -1 : 1), 0, 0);
267                 
268                 if(!cameramode&&!freeze&&!winfreeze){
269                         glRotatef(float(Random()%100)/10*camerashake/*+(woozy*woozy)/10*/,0,0,1);
270                         glRotatef(rotation2+sin(woozy/2)*(player[0].damage/player[0].damagetolerance)*5,1,0,0);
271                         glRotatef(rotation+sin(woozy)*(player[0].damage/player[0].damagetolerance)*5,0,1,0);
272                 }
273                 if(cameramode||freeze||winfreeze){
274                         glRotatef(rotation2,1,0,0);
275                         glRotatef(rotation,0,1,0);
276                 }
277
278                 if(environment==desertenvironment){
279                         glRotatef((float)(abs(Random()%100))/3000-1,1,0,0);
280                         glRotatef((float)(abs(Random()%100))/3000-1,0,1,0);
281                 }
282                 SetUpLight(&light,0);
283                 glPushMatrix();
284                 if(environment==desertenvironment&&detail==2)glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, blurness+.4 );
285                 if(environment==desertenvironment){
286                         glRotatef((float)(abs(Random()%100))/1000,1,0,0);
287                         glRotatef((float)(abs(Random()%100))/1000,0,1,0);
288                 }       
289                 skybox.draw();
290                 glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0);
291                 glPopMatrix();
292                 glTranslatef(-viewer.x,-viewer.y,-viewer.z);
293                 frustum.GetFrustum();
294
295                 //Make Shadow
296                 static XYZ point;
297                 static float size,opacity,rotation;
298                 rotation=0;
299                 for(k=0;k<numplayers;k++){
300                         if(!player[k].skeleton.free&&player[k].playerdetail&&player[k].howactive<typesleeping)
301                                 if(frustum.SphereInFrustum(player[k].coords.x,player[k].coords.y+player[k].scale*3,player[k].coords.z,player[k].scale*7)&&player[k].occluded<25)
302                                         for(i=0;i<player[k].skeleton.num_joints;i++){
303                                                 if(player[k].skeleton.joints[i].label==leftknee||player[k].skeleton.joints[i].label==rightknee||player[k].skeleton.joints[i].label==groin){
304                                                         point=DoRotation(player[k].skeleton.joints[i].position,0,player[k].rotation,0)*player[k].scale+player[k].coords;
305                                                         size=.4f;
306                                                         opacity=.4-player[k].skeleton.joints[i].position.y*player[k].scale/5-(player[k].coords.y-terrain.getHeight(player[k].coords.x,player[k].coords.z))/10;
307                                                         if(k!=0&&tutoriallevel==1){
308                                                                 opacity=.2+.2*sin(smoketex*6+i)-player[k].skeleton.joints[i].position.y*player[k].scale/5-(player[k].coords.y-terrain.getHeight(player[k].coords.x,player[k].coords.z))/10;
309                                                         }
310                                                         terrain.MakeDecal(shadowdecal,point,size,opacity,rotation);
311                                                         for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
312                                                                 j=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
313                                                                 if(objects.position[j].y<player[k].coords.y||objects.type[j]==tunneltype||objects.type[j]==weirdtype){
314                                                                         point=DoRotation(DoRotation(player[k].skeleton.joints[i].position,0,player[k].rotation,0)*player[k].scale+player[k].coords-objects.position[j],0,-objects.rotation[j],0);
315                                                                         size=.4f;
316                                                                         opacity=.4f;
317                                                                         if(k!=0&&tutoriallevel==1){
318                                                                                 opacity=.2+.2*sin(smoketex*6+i);
319                                                                         }
320                                                                         objects.model[j].MakeDecal(shadowdecal,&point,&size,&opacity,&rotation);
321                                                                 }
322                                                         }
323                                                 }
324                                         }
325                                         if((player[k].skeleton.free||player[k].howactive>=typesleeping)&&player[k].playerdetail)
326                                                 if(frustum.SphereInFrustum(player[k].coords.x,player[k].coords.y,player[k].coords.z,player[k].scale*5)&&player[k].occluded<25)
327                                                         for(i=0;i<player[k].skeleton.num_joints;i++){
328                                                                 if(player[k].skeleton.joints[i].label==leftknee||player[k].skeleton.joints[i].label==rightknee||player[k].skeleton.joints[i].label==groin||player[k].skeleton.joints[i].label==leftelbow||player[k].skeleton.joints[i].label==rightelbow||player[k].skeleton.joints[i].label==neck){
329                                                                         if(player[k].skeleton.free)point=player[k].skeleton.joints[i].position*player[k].scale+player[k].coords;
330                                                                         else point=DoRotation(player[k].skeleton.joints[i].position,0,player[k].rotation,0)*player[k].scale+player[k].coords;
331                                                                         size=.4f;
332                                                                         opacity=.4-player[k].skeleton.joints[i].position.y*player[k].scale/5-(player[k].coords.y-terrain.getHeight(player[k].coords.x,player[k].coords.z))/5;
333                                                                         if(k!=0&&tutoriallevel==1){
334                                                                                 opacity=.2+.2*sin(smoketex*6+i)-player[k].skeleton.joints[i].position.y*player[k].scale/5-(player[k].coords.y-terrain.getHeight(player[k].coords.x,player[k].coords.z))/10;
335                                                                         }
336                                                                         terrain.MakeDecal(shadowdecal,point,size,opacity*.7,rotation);
337                                                                         for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
338                                                                                 j=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
339                                                                                 if(objects.position[j].y<player[k].coords.y||objects.type[j]==tunneltype||objects.type[j]==weirdtype){
340                                                                                         if(player[k].skeleton.free)point=DoRotation(player[k].skeleton.joints[i].position*player[k].scale+player[k].coords-objects.position[j],0,-objects.rotation[j],0);
341                                                                                         else point=DoRotation(DoRotation(player[k].skeleton.joints[i].position,0,player[k].rotation,0)*player[k].scale+player[k].coords-objects.position[j],0,-objects.rotation[j],0);
342                                                                                         size=.4f;
343                                                                                         opacity=.4f;
344                                                                                         if(k!=0&&tutoriallevel==1){
345                                                                                                 opacity=.2+.2*sin(smoketex*6+i);
346                                                                                         }
347                                                                                         objects.model[j].MakeDecal(shadowdecal,&point,&size,&opacity,&rotation);
348                                                                                 }
349                                                                         }
350                                                                 }
351                                                         }
352
353                                                         if(!player[k].playerdetail)
354                                                                 if(frustum.SphereInFrustum(player[k].coords.x,player[k].coords.y,player[k].coords.z,player[k].scale*5))
355                                                                 {
356                                                                         point=player[k].coords;
357                                                                         size=.7;
358                                                                         opacity=.4-(player[k].coords.y-terrain.getHeight(player[k].coords.x,player[k].coords.z))/5;
359                                                                         terrain.MakeDecal(shadowdecal,point,size,opacity*.7,rotation);
360                                                                         for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
361                                                                                 j=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
362                                                                                 point=DoRotation(player[k].coords-objects.position[j],0,-objects.rotation[j],0);
363                                                                                 size=.7;
364                                                                                 opacity=.4f;
365                                                                                 objects.model[j].MakeDecal(shadowdecal,&point,&size,&opacity,&rotation);
366                                                                         }
367                                                                 }
368                 }
369
370                 //Terrain
371                 glEnable(GL_TEXTURE_2D);
372                 glDepthMask(1);
373                 glEnable(GL_DEPTH_TEST);
374                 glEnable(GL_CULL_FACE);
375                 glDisable(GL_BLEND);
376                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
377                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 
378                 glBindTexture( GL_TEXTURE_2D, terraintexture);
379                 terrain.draw(0);
380                 glBindTexture( GL_TEXTURE_2D, terraintexture2);
381                 terrain.draw(1);
382                 //glBindTexture( GL_TEXTURE_2D, terraintexture3);
383                 //glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
384                 //terrain.draw(2);
385
386                 terrain.drawdecals();
387
388                 //Model
389                 glEnable(GL_CULL_FACE);
390                 glEnable(GL_LIGHTING);
391                 glDisable(GL_BLEND);
392                 glEnable(GL_TEXTURE_2D);
393                 glDepthMask(1);
394
395                 glEnable(GL_COLOR_MATERIAL);
396
397                 test=2;
398                 tilt2weird=0;
399                 tiltweird=0;
400                 midweird=0;
401                 proportionweird=0;
402                 vertexweird[0]=0;
403                 vertexweird[1]=0;
404                 vertexweird[2]=0;
405                 vertexweird[3]=0;
406                 vertexweird[4]=0;
407                 vertexweird[5]=0;
408
409                 if(!cellophane){
410                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
411                         glEnable(GL_CULL_FACE);
412                         glCullFace(GL_FRONT);
413                         glDepthMask(1);
414                         for(k=0;k<numplayers;k++){
415                                 if(k==0||tutoriallevel!=1){
416                                         glEnable(GL_BLEND);
417                                         glEnable(GL_LIGHTING);
418                                         terrainlight=terrain.getLighting(player[k].coords.x,player[k].coords.z);
419                                         distance=findDistancefast(&viewer,&player[k].coords);
420                                         distance=(viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance;
421                                         glColor4f(terrainlight.x,terrainlight.y,terrainlight.z,distance);
422                                         if(distance>=1)glDisable(GL_BLEND);
423                                         if(distance>=.5){
424                                                 checkpoint=DoRotation(player[k].skeleton.joints[abs(Random()%player[k].skeleton.num_joints)].position,0,player[k].rotation,0)*player[k].scale+player[k].coords;
425                                                 checkpoint.y+=1;
426                                                 if(!player[k].occluded==0)i=checkcollide(viewer,checkpoint,player[k].lastoccluded);
427                                                 if(i==-1||player[k].occluded==0)i=checkcollide(viewer,checkpoint);
428                                                 if(i!=-1){
429                                                         player[k].occluded+=1;
430                                                         player[k].lastoccluded=i;
431                                                 }
432                                                 else player[k].occluded=0;
433                                                 if(player[k].occluded<25)player[k].DrawSkeleton();
434                                         }
435                                 }
436                         }
437                 }
438
439                 if(!cameramode&&musictype==stream_fighttheme)playerdist=findDistancefastflat(&player[0].coords,&viewer);
440                 else playerdist=-100;
441                 glPushMatrix();
442                 glCullFace(GL_BACK);
443                 glEnable(GL_TEXTURE_2D);
444                 objects.Draw();
445                 glPopMatrix();
446
447                 glPushMatrix();
448                 if(frustum.SphereInFrustum(realhawkcoords.x+hawk.boundingspherecenter.x,realhawkcoords.y+hawk.boundingspherecenter.y,realhawkcoords.z+hawk.boundingspherecenter.z,2)){   
449                         glAlphaFunc(GL_GREATER, 0.0001f);
450                         glDepthMask(1);
451                         glDisable(GL_CULL_FACE);
452                         glDisable(GL_LIGHTING);
453                         glEnable(GL_BLEND);
454                         glTranslatef(hawkcoords.x,hawkcoords.y,hawkcoords.z);
455                         glRotatef(hawkrotation,0,1,0);
456                         glTranslatef(25,0,0);
457                         distance=findDistancefast(&viewer,&realhawkcoords)*1.2;
458                         glColor4f(light.color[0],light.color[1],light.color[2],(viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance);
459                         if((viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance>1)glColor4f(light.color[0],light.color[1],light.color[2],1);
460                         if((viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance>0)
461                                 hawk.drawdifftex(hawktexture);
462                 }
463                 glPopMatrix();
464
465                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
466                 glEnable(GL_CULL_FACE);
467                 glCullFace(GL_FRONT);
468                 glDepthMask(1);
469                 for(k=0;k<numplayers;k++){
470                         if(!(k==0||tutoriallevel!=1)){
471                                 glEnable(GL_BLEND);
472                                 glEnable(GL_LIGHTING);
473                                 terrainlight=terrain.getLighting(player[k].coords.x,player[k].coords.z);
474                                 distance=findDistancefast(&viewer,&player[k].coords);
475                                 distance=(viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance;
476                                 glColor4f(terrainlight.x,terrainlight.y,terrainlight.z,distance);
477                                 if(distance>=1)glDisable(GL_BLEND);
478                                 if(distance>=.5){
479                                         checkpoint=DoRotation(player[k].skeleton.joints[abs(Random()%player[k].skeleton.num_joints)].position,0,player[k].rotation,0)*player[k].scale+player[k].coords;
480                                         checkpoint.y+=1;
481                                         if(!player[k].occluded==0)i=checkcollide(viewer,checkpoint,player[k].lastoccluded);
482                                         if(i==-1||player[k].occluded==0)i=checkcollide(viewer,checkpoint);
483                                         if(i!=-1){
484                                                 player[k].occluded+=1;
485                                                 player[k].lastoccluded=i;
486                                         }
487                                         else player[k].occluded=0;
488                                         if(player[k].occluded<25)player[k].DrawSkeleton();
489                                 }
490                         }
491                 }
492
493                 glPushMatrix();
494                 glEnable(GL_TEXTURE_2D);
495                 weapons.Draw();
496                 glPopMatrix();
497                 glCullFace(GL_BACK);
498
499                 glDisable(GL_COLOR_MATERIAL);
500
501                 glDisable(GL_LIGHTING);
502                 glDisable(GL_TEXTURE_2D);
503
504                 glDepthMask(0);
505
506                 Sprite::Draw();
507
508                 if(editorenabled){
509                         glEnable(GL_BLEND);
510                         glDisable(GL_LIGHTING);
511                         glDisable(GL_TEXTURE_2D);
512                         glDisable(GL_COLOR_MATERIAL);
513                         glColor4f(1,1,0,1);
514
515                         for(k=0;k<numplayers;k++){
516                                 if(player[k].numwaypoints>1){
517                                         glBegin(GL_LINE_LOOP);
518                                         for(i=0;i<player[k].numwaypoints;i++){
519                                                 glVertex3f(player[k].waypoints[i].x,player[k].waypoints[i].y+.5,player[k].waypoints[i].z);
520                                         }
521                                         glEnd();
522                                 }
523                         }
524
525
526                         if(numpathpoints>1){
527                                 glColor4f(0,1,0,1);
528                                 for(k=0;k<numpathpoints;k++){
529                                         if(numpathpointconnect[k]){
530                                                 for(i=0;i<numpathpointconnect[k];i++){
531                                                         glBegin(GL_LINE_LOOP);
532                                                         glVertex3f(pathpoint[k].x,pathpoint[k].y+.5,pathpoint[k].z);
533                                                         glVertex3f(pathpoint[pathpointconnect[k][i]].x,pathpoint[pathpointconnect[k][i]].y+.5,pathpoint[pathpointconnect[k][i]].z);                                     
534                                                         glEnd();
535                                                 }
536                                         }
537                                 }
538                                 glColor4f(1,1,1,1);
539                                 glPointSize(4);
540                                 glBegin(GL_POINTS);
541                                 glVertex3f(pathpoint[pathpointselected].x,pathpoint[pathpointselected].y+.5,pathpoint[pathpointselected].z);
542                                 glEnd();
543                         }
544                 }
545
546                 //Text
547
548                 glEnable(GL_TEXTURE_2D);
549                 glColor4f(.5,.5,.5,1);
550                 if(!console){
551                         sprintf (string, " ",(int)(fps));
552                         text.glPrint(10,30,string,0,.8,screenwidth,screenheight);
553
554                         if(!tutoriallevel)
555                                 if(bonus>0&&bonustime<1&&!winfreeze&&indialogue==-1/*bonustime<4*/){
556                                         const char *bonus_name;
557                                         if (bonus < bonus_count)
558                                           bonus_name = bonus_names[bonus];
559                                         else
560                                           bonus_name = "Excellent!"; // When does this happen?
561
562                                         glColor4f(0,0,0,1-bonustime);
563                                         text.glPrintOutline(1024/2-10*strlen(bonus_name)-4,768/16-4+768*4/5,bonus_name,1,2.5,1024,768);
564                                         glColor4f(1,0,0,1-bonustime);
565                                         text.glPrint(1024/2-10*strlen(bonus_name),768/16+768*4/5,bonus_name,1,2,1024,768);
566
567                                         sprintf (string, "%d",(int)bonusvalue);
568                                         glColor4f(0,0,0,1-bonustime);
569                                         text.glPrintOutline(1024/2-10*strlen(string)-4,768/16-4-20+768*4/5,string,1,2.5*.8,1024,768);
570                                         glColor4f(1,0,0,1-bonustime);
571                                         text.glPrint(1024/2-10*strlen(string),768/16-20+768*4/5,string,1,2*.8,1024,768);
572                                         glColor4f(.5,.5,.5,1);
573                                 }
574
575                                 if(tutoriallevel==1){
576                                         tutorialopac=tutorialmaxtime-tutorialstagetime;
577                                         if(tutorialopac>1)tutorialopac=1;
578                                         if(tutorialopac<0)tutorialopac=0;
579
580                                         sprintf (string, " ");
581                                         sprintf (string2, " ");
582                                         sprintf (string3, " ");
583                                         if(tutorialstage==0){
584                                                 sprintf (string, " ");
585                                                 sprintf (string2, " ");
586                                                 sprintf (string3, " ");
587                                         }
588                                         if(tutorialstage==1){
589                                                 sprintf (string, "Welcome to the Lugaru training level!");
590                                                 sprintf (string2, " ");
591                                                 sprintf (string3, " ");
592                                         }
593                                         if(tutorialstage==2){
594                                                 sprintf (string, "BASIC MOVEMENT:");
595                                                 sprintf (string2, " ");
596                                                 sprintf (string3, " ");
597                                         }
598                                         if(tutorialstage==3){
599                                                 sprintf (string, "You can move the mouse to rotate the camera.");
600                                                 sprintf (string2, " ");
601                                                 sprintf (string3, " ");
602                                         }
603                                         if(tutorialstage==4){
604                                                 sprintf (string, "Try using the %s, %s, %s and %s keys to move around.",Input::keyToChar(forwardkey),Input::keyToChar(leftkey),Input::keyToChar(backkey),Input::keyToChar(rightkey));
605                                                 sprintf (string2, "All movement is relative to the camera.");
606                                                 sprintf (string3, " ");
607                                         }
608                                         if(tutorialstage==5){
609                                                 sprintf (string, "Please press %s to jump.",Input::keyToChar(jumpkey));
610                                                 sprintf (string2, "You can hold it longer to jump higher.");
611                                                 sprintf (string3, " ");
612                                         }
613                                         if(tutorialstage==6){
614                                                 sprintf (string, "You can press %s to crouch.",Input::keyToChar(crouchkey));
615                                                 sprintf (string2, "You can jump higher from a crouching position.");
616                                                 sprintf (string3, " ");
617                                         }
618                                         if(tutorialstage==7){
619                                                 sprintf (string, "While running, you can press %s to roll.",Input::keyToChar(crouchkey));
620                                                 sprintf (string2, " ");
621                                                 sprintf (string3, " ");
622                                         }
623                                         if(tutorialstage==8){
624                                                 sprintf (string, "While crouching, you can sneak around silently");
625                                                 sprintf (string2, "using the movement keys.");
626                                                 sprintf (string3, " ");
627                                         }
628                                         if(tutorialstage==9){
629                                                 sprintf (string, "Release the crouch key while sneaking and hold the movement keys");
630                                                 sprintf (string2, "to run animal-style.");
631                                                 sprintf (string3, " ");
632                                         }
633                                         if(tutorialstage==10){
634                                                 sprintf (string, "ADVANCED MOVEMENT:");
635                                                 sprintf (string2, " ");
636                                                 sprintf (string3, " ");
637                                         }
638                                         if(tutorialstage==11){
639                                                 sprintf (string, "When you jump at a wall, you can hold %s again",Input::keyToChar(jumpkey));
640                                                 sprintf (string2, "during impact to perform a walljump.");
641                                                 sprintf (string3, "Be sure to use the movement keys to press against the wall");
642                                         }
643                                         if(tutorialstage==12){
644                                                 sprintf (string, "While in the air, you can press crouch to flip.",Input::keyToChar(jumpkey));
645                                                 sprintf (string2, "Walljumps and flips confuse enemies and give you more control.");
646                                                 sprintf (string3, " ");
647                                         }
648                                         if(tutorialstage==13){
649                                                 sprintf (string, "BASIC COMBAT:");
650                                                 sprintf (string2, " ");
651                                                 sprintf (string3, " ");
652                                         }
653                                         if(tutorialstage==14){
654                                                 sprintf (string, "There is now an imaginary enemy");
655                                                 sprintf (string2, "in the middle of the training area.");
656                                                 sprintf (string3, " ");
657                                         }
658                                         if(tutorialstage==15){
659                                                 if(attackkey==MOUSEBUTTON1)sprintf (string, "Click to attack when you are near an enemy.");
660                                                 else sprintf (string, "Press %s to attack when you are near an enemy.",Input::keyToChar(attackkey));
661                                                 sprintf (string2, "You can punch by standing still near an enemy and attacking.");
662                                                 sprintf (string3, " ");
663                                         }
664                                         if(tutorialstage==16){
665                                                 sprintf (string, "If you are close, you will perform a weak punch.");
666                                                 sprintf (string2, "The weak punch is excellent for starting attack combinations.");
667                                                 sprintf (string3, " ");
668                                         }
669                                         if(tutorialstage==17){
670                                                 sprintf (string, "Attacking while running results in a spin kick.");
671                                                 sprintf (string2, "This is one of your most powerful ground attacks.");
672                                                 sprintf (string3, " ");
673                                         }
674                                         if(tutorialstage==18){
675                                                 sprintf (string, "Sweep the enemy's legs out by attacking while crouched.");
676                                                 sprintf (string2, "This is a very fast attack, and easy to follow up.");
677                                                 sprintf (string3, " ");
678                                         }
679                                         if(tutorialstage==19){
680                                                 sprintf (string, "When an enemy is on the ground, you can deal some extra");
681                                                 sprintf (string2, "damage by running up and drop-kicking him.");
682                                                 sprintf (string3, "(Try knocking them down with a sweep first)");
683                                         }
684                                         if(tutorialstage==20){
685                                                 sprintf (string, "Your most powerful individual attack is the rabbit kick.");
686                                                 if(attackkey==MOUSEBUTTON1)sprintf (string2, "Run at the enemy while holding the mouse button, and press");
687                                                 else sprintf (string2, "Run at the enemy while holding %s, and press", Input::keyToChar(attackkey));
688                                                 sprintf (string3, "the jump key (%s) to attack.",Input::keyToChar(jumpkey));
689                                         }
690                                         if(tutorialstage==21){
691                                                 sprintf (string, "This attack is devastating if timed correctly.");
692                                                 sprintf (string2, "Even if timed incorrectly, it will knock the enemy over.");
693                                                 if(againbonus)sprintf (string3, "Try rabbit-kicking the imaginary enemy again.");
694                                                 else sprintf (string3, "Try rabbit-kicking the imaginary enemy.");
695                                         }
696                                         if(tutorialstage==22){
697                                                 sprintf (string, "If you sneak behind an enemy unnoticed, you can kill");
698                                                 sprintf (string2, "him instantly. Move close behind this enemy");
699                                                 sprintf (string3, "and attack.");
700                                         }
701                                         if(tutorialstage==23){
702                                                 sprintf (string, "Another important attack is the wall kick. When an enemy");
703                                                 sprintf (string2, "is near a wall, perform a walljump nearby and hold");
704                                                 sprintf (string3, "the attack key during impact with the wall.");
705                                         }
706                                         if(tutorialstage==24){
707                                                 sprintf (string, "You can tackle enemies by running at them animal-style");
708                                                 if(attackkey==MOUSEBUTTON1)sprintf (string2, "and pressing jump (%s) or attack(mouse button).",Input::keyToChar(jumpkey));
709                                                 else sprintf (string2, "and pressing jump (%s) or attack(%s).",Input::keyToChar(jumpkey),Input::keyToChar(attackkey));
710                                                 sprintf (string3, "This is especially useful when they are running away.");
711                                         }
712                                         if(tutorialstage==25){
713                                                 sprintf (string, "Dodge by pressing back and attack. Dodging is essential");
714                                                 sprintf (string2, "against enemies with swords or other long weapons.");
715                                                 sprintf (string3, " ");
716                                         }
717                                         if(tutorialstage==26){
718                                                 sprintf (string, "REVERSALS AND COUNTER-REVERSALS");
719                                                 sprintf (string2, " ");
720                                                 sprintf (string3, " ");
721                                         }
722                                         if(tutorialstage==27){
723                                                 sprintf (string, "The enemy can now reverse your attacks.");
724                                                 sprintf (string2, " ");
725                                                 sprintf (string3, " ");
726                                         }
727                                         if(tutorialstage==28){
728                                                 sprintf (string, "If you attack, you will notice that the enemy now sometimes");
729                                                 sprintf (string2, "catches your attack and uses it against you. Hold");
730                                                 sprintf (string3, "crouch (%s) after attacking to escape from reversals.",Input::keyToChar(crouchkey));
731                                         }
732                                         if(tutorialstage==29){
733                                                 sprintf (string, "Try escaping from two more reversals in a row.");
734                                                 sprintf (string2, " ");
735                                                 sprintf (string3, " ");
736                                         }
737                                         if(tutorialstage==30){
738                                                 sprintf (string, "Good!");
739                                                 sprintf (string2, " ");
740                                                 sprintf (string3, " ");
741                                         }
742                                         if(tutorialstage==31){
743                                                 sprintf (string, "To reverse an attack, you must tap crouch (%s) during the",Input::keyToChar(crouchkey));
744                                                 sprintf (string2, "enemy's attack. You must also be close to the enemy;");
745                                                 sprintf (string3, "this is especially important against armed opponents.");
746                                         }
747                                         if(tutorialstage==32){
748                                                 sprintf (string, "The enemy can attack in %d seconds.", (int)(tutorialmaxtime-tutorialstagetime));
749                                                 sprintf (string2, "This imaginary opponents attacks will be highlighted");
750                                                 sprintf (string3, "to make this easier.");
751                                         }
752                                         if(tutorialstage==33){
753                                                 sprintf (string, "Reverse three enemy attacks!");
754                                                 sprintf (string2, " ");
755                                                 sprintf (string3, " ");
756                                         }
757                                         if(tutorialstage==34){
758                                                 sprintf (string, "Reverse two more enemy attacks!");
759                                                 sprintf (string2, " ");
760                                                 sprintf (string3, " ");
761                                         }
762                                         if(tutorialstage==35){
763                                                 sprintf (string, "Reverse one more enemy attack!");
764                                                 sprintf (string2, " ");
765                                                 sprintf (string3, " ");
766                                         }
767                                         if(tutorialstage==36){
768                                                 sprintf (string, "Excellent!");
769                                                 sprintf (string2, " ");
770                                                 sprintf (string3, " ");
771                                         }
772                                         if(tutorialstage==37){
773                                                 sprintf (string, "Now spar with the enemy for %d more seconds.", (int)(tutorialmaxtime-tutorialstagetime));
774                                                 sprintf (string2, "Damage dealt: %d",(int)damagedealt);
775                                                 sprintf (string3, "Damage taken: %d.",(int)damagetaken);
776                                         }
777                                         if(tutorialstage==38){
778                                                 sprintf (string, "WEAPONS:");
779                                                 sprintf (string2, " ");
780                                                 sprintf (string3, " ");
781                                         }
782                                         if(tutorialstage==39){
783                                                 sprintf (string, "There is now an imaginary knife");
784                                                 sprintf (string2, "in the center of the training area.");
785                                                 sprintf (string3, " ");
786                                         }
787                                         if(tutorialstage==40){
788                                                 sprintf (string, "Stand, roll or handspring over the knife");
789                                                 sprintf (string2, "while pressing %s to pick it up.",Input::keyToChar(throwkey));
790                                                 sprintf (string3, "You can crouch and press the same key to drop it again.");
791                                         }
792                                         if(tutorialstage==41){
793                                                 sprintf (string, "You can equip and unequip weapons using the %s key.",Input::keyToChar(drawkey));
794                                                 sprintf (string2, "Sometimes it is best to keep them unequipped to");
795                                                 sprintf (string3, "prevent enemies from taking them. ");
796                                         }
797                                         if(tutorialstage==42){
798                                                 sprintf (string, "The knife is the smallest weapon and the least encumbering.");
799                                                 sprintf (string2, "You can equip or unequip it while standing, crouching,");
800                                                 sprintf (string3, "running or flipping.");
801                                         }
802                                         if(tutorialstage==43){
803                                                 sprintf (string, "You perform weapon attacks the same way as unarmed attacks,");
804                                                 sprintf (string2, "but sharp weapons cause permanent damage, instead of the");
805                                                 sprintf (string3, "temporary trauma from blunt weapons, fists and feet.");
806                                         }
807                                         if(tutorialstage==44){
808                                                 sprintf (string, "The enemy now has your knife!");
809                                                 sprintf (string2, "Please reverse two of his knife attacks.");
810                                                 sprintf (string3, " ");
811                                         }
812                                         if(tutorialstage==45){
813                                                 sprintf (string, "Please reverse one more of his knife attacks.");
814                                                 sprintf (string2, " ");
815                                                 sprintf (string3, " ");
816                                         }
817                                         if(tutorialstage==46){
818                                                 sprintf (string, "Now he has a sword!");
819                                                 sprintf (string2, "The sword has longer reach than your arms, so you");
820                                                 sprintf (string3, "must move close to reverse the sword slash.");
821                                         }
822                                         if(tutorialstage==47){
823                                                 sprintf (string, "Long weapons like the sword and staff are also useful for defense;");
824                                                 sprintf (string2, "you can parry enemy weapon attacks by pressing the attack key");
825                                                 sprintf (string3, "at the right time. Please try parrying the enemy's attacks!");
826                                         }
827                                         if(tutorialstage==48){
828                                                 sprintf (string, "The staff is like the sword, but has two main attacks.");
829                                                 sprintf (string2, "The standing smash is fast and effective, and the running");
830                                                 sprintf (string3, "spin smash is slower and more powerful.");
831                                         }
832                                         if(tutorialstage==49){
833                                                 sprintf (string, "When facing an enemy, you can throw the knife with %s.",Input::keyToChar(throwkey));
834                                                 sprintf (string2, "It is possible to throw the knife while flipping,");
835                                                 sprintf (string3, "but it is very inaccurate.");
836                                         }
837                                         if(tutorialstage==50){
838                                                 sprintf (string, "You now know everything you can learn from training.");
839                                                 sprintf (string2, "Everything else you must learn from experience!");
840                                                 sprintf (string3, " ");
841                                         }
842                                         if(tutorialstage==51){
843                                                 sprintf (string, "Walk out of the training area to return to the main menu.");
844                                                 sprintf (string2, " ");
845                                                 sprintf (string3, " ");
846                                         }
847
848                                         glColor4f(0,0,0,tutorialopac);
849                                         text.glPrintOutline(screenwidth/2-7.6*strlen(string)*screenwidth/1024-4,screenheight/16-4+screenheight*4/5,string,1,1.5*1.25*screenwidth/1024,screenwidth,screenheight);
850                                         text.glPrintOutline(screenwidth/2-7.6*strlen(string2)*screenwidth/1024-4,screenheight/16-4+screenheight*4/5-20*screenwidth/1024,string2,1,1.5*1.25*screenwidth/1024,screenwidth,screenheight);
851                                         text.glPrintOutline(screenwidth/2-7.6*strlen(string3)*screenwidth/1024-4,screenheight/16-4+screenheight*4/5-40*screenwidth/1024,string3,1,1.5*1.25*screenwidth/1024,screenwidth,screenheight);
852                                         glColor4f(1,1,1,tutorialopac);
853                                         text.glPrint(screenwidth/2-7.6*strlen(string)*screenwidth/1024,screenheight/16+screenheight*4/5,string,1,1.5*screenwidth/1024,screenwidth,screenheight);
854                                         text.glPrint(screenwidth/2-7.6*strlen(string2)*screenwidth/1024,screenheight/16+screenheight*4/5-20*screenwidth/1024,string2,1,1.5*screenwidth/1024,screenwidth,screenheight);
855                                         text.glPrint(screenwidth/2-7.6*strlen(string3)*screenwidth/1024,screenheight/16+screenheight*4/5-40*screenwidth/1024,string3,1,1.5*screenwidth/1024,screenwidth,screenheight);
856
857                                         sprintf (string, "Press 'tab' to skip to the next item.",Input::keyToChar(jumpkey));
858                                         sprintf (string2, "Press escape at any time to");
859                                         sprintf (string3, "pause or exit the tutorial.");
860
861                                         glColor4f(0,0,0,1);
862                                         text.glPrintOutline(screenwidth/2-7.6*strlen(string)*screenwidth/1024*.8-4,0-4+screenheight*1/10,string,1,1.5*1.25*screenwidth/1024*.8,screenwidth,screenheight);
863                                         text.glPrintOutline(screenwidth/2-7.6*strlen(string2)*screenwidth/1024*.8-4,0-4+screenheight*1/10-20*.8*screenwidth/1024,string2,1,1.5*1.25*screenwidth/1024*.8,screenwidth,screenheight);
864                                         text.glPrintOutline(screenwidth/2-7.6*strlen(string3)*screenwidth/1024*.8-4,0-4+screenheight*1/10-40*.8*screenwidth/1024,string3,1,1.5*1.25*screenwidth/1024*.8,screenwidth,screenheight);
865                                         glColor4f(0.5,0.5,0.5,1);
866                                         text.glPrint(screenwidth/2-7.6*strlen(string)*screenwidth/1024*.8,0+screenheight*1/10,string,1,1.5*screenwidth/1024*.8,screenwidth,screenheight);
867                                         text.glPrint(screenwidth/2-7.6*strlen(string2)*screenwidth/1024*.8,0+screenheight*1/10-20*.8*screenwidth/1024,string2,1,1.5*screenwidth/1024*.8,screenwidth,screenheight);
868                                         text.glPrint(screenwidth/2-7.6*strlen(string3)*screenwidth/1024*.8,0+screenheight*1/10-40*.8*screenwidth/1024,string3,1,1.5*screenwidth/1024*.8,screenwidth,screenheight);
869                                 }
870                                 //Hot spots     
871
872                                 if(numhotspots&&(bonustime>=1||bonus<=0||bonustime<0)&&!tutoriallevel){
873                                         int closest=-1;
874                                         float closestdist=-1;
875                                         float distance=0;
876                                         closest=currenthotspot;
877                                         for(i=0;i<numhotspots;i++){
878                                                 distance=findDistancefast(&player[0].coords,&hotspot[i]);
879                                                 if(closestdist==-1||distance<closestdist){
880                                                         if(findDistancefast(&player[0].coords,&hotspot[i])<hotspotsize[i]&&((hotspottype[i]<=10&&hotspottype[i]>=0)||(hotspottype[i]<=40&&hotspottype[i]>=20))){
881                                                                 closestdist=distance;
882                                                                 closest=i;
883                                                         }
884                                                 }
885                                         }
886                                         if(closest!=-1)
887                                                 currenthotspot=closest;
888                                         if(currenthotspot!=-1){
889                                                 if(hotspottype[closest]<=10){
890                                                         if(findDistancefast(&player[0].coords,&hotspot[closest])<hotspotsize[closest])
891                                                                 tutorialstagetime=0;
892                                                         tutorialmaxtime=1;
893                                                         tutorialopac=tutorialmaxtime-tutorialstagetime;
894                                                         if(tutorialopac>1)tutorialopac=1;
895                                                         if(tutorialopac<0)tutorialopac=0;
896
897                                                         sprintf (string, "%s", hotspottext[closest]);
898
899                                                         int lastline = 0;
900                                                         int line = 0;
901                                                         bool done = false;
902                                                         i=0;
903                                                         while(!done){
904                                                                 if(string[i]=='\n'||string[i]>'z'||string[i]<' '||string[i]=='\0'){
905                                                                         glColor4f(0,0,0,tutorialopac);
906                                                                         text.glPrintOutline(screenwidth/2-7.6*(i-lastline)*screenwidth/1024-4,screenheight/16-4+screenheight*4/5-20*screenwidth/1024*line,string,1,1.5*1.25*screenwidth/1024,screenwidth,screenheight,lastline,i);
907                                                                         glColor4f(1,1,1,tutorialopac);
908                                                                         text.glPrint(screenwidth/2-7.6*(i-lastline)*screenwidth/1024,screenheight/16+screenheight*4/5-20*screenwidth/1024*line,string,1,1.5*screenwidth/1024,screenwidth,screenheight,lastline,i);
909                                                                         lastline=i+1;
910                                                                         line++;
911                                                                         if(string[i]=='\0')done=1;
912                                                                 }
913                                                                 if(i>=255)done=1;
914                                                                 i++;
915                                                         }
916                                                 }
917                                                 else if (hotspottype[closest]>=20&&dialoguegonethrough[hotspottype[closest]-20]==0){
918                                                         whichdialogue=hotspottype[closest]-20;
919                                                         for(j=0;j<numdialogueboxes[whichdialogue];j++){
920                                                                 player[participantfocus[whichdialogue][j]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][j]];
921                                                                 player[participantfocus[whichdialogue][j]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
922                                                                 player[participantfocus[whichdialogue][j]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
923                                                                 player[participantfocus[whichdialogue][j]].velocity=0;
924                                                                 player[participantfocus[whichdialogue][j]].targetanimation=player[participantfocus[whichdialogue][j]].getIdle();
925                                                                 player[participantfocus[whichdialogue][j]].targetframe=0;
926                                                         }
927                                                         directing=0;
928                                                         indialogue=0;
929                                                         dialoguegonethrough[whichdialogue]++;
930                                                         if(dialogueboxsound[whichdialogue][indialogue]!=0){
931                                                                 int whichsoundplay;
932                                                                 if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
933                                                                 if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
934                                                                 if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
935                                                                 if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
936                                                                 if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
937                                                                 if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
938                                                                 if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
939                                                                 if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
940                                                                 if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
941                                                                 if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
942                                                                 if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
943                                                                 if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
944                                                                 if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
945                                                                 if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
946                                                                 if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
947                                                                 if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
948                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
949                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
950                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
951                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
952                                                                 emit_sound_at(whichsoundplay, player[participantfocus[whichdialogue][indialogue]].coords);
953                                                         }
954                                                 }
955                                         }
956                                 }
957
958                                 if(indialogue!=-1&&!mainmenu){
959                                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
960                                         glDisable(GL_CULL_FACE);
961                                         glDisable(GL_LIGHTING);
962                                         glDisable(GL_TEXTURE_2D);
963                                         glDepthMask(0);
964                                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
965                                         glPushMatrix();                                                                         // Store The Projection Matrix
966                                         glLoadIdentity();                                                                       // Reset The Projection Matrix
967                                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
968                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
969                                         glPushMatrix();                                                                         // Store The Modelview Matrix
970                                         glLoadIdentity();                                                               // Reset The Modelview Matrix
971                                         if(dialogueboxlocation[whichdialogue][indialogue]==1)glTranslatef(0,screenheight*3/4,0);
972                                         glScalef(screenwidth,screenheight/4,1);
973                                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
974                                         glEnable(GL_BLEND);
975
976                                         glColor4f(dialogueboxcolor[whichdialogue][indialogue][0],dialogueboxcolor[whichdialogue][indialogue][1],dialogueboxcolor[whichdialogue][indialogue][2],0.7);
977                                         glBegin(GL_QUADS);
978                                         glVertex3f(0,           0,       0.0f);
979                                         glVertex3f(1,   0,       0.0f);
980                                         glVertex3f(1,   1, 0.0f);
981                                         glVertex3f(0,   1, 0.0f);
982                                         glEnd();
983                                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
984                                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
985                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
986                                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
987                                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
988                                         glEnable(GL_CULL_FACE);
989                                         glDisable(GL_BLEND);
990                                         glDepthMask(1);
991                                         glEnable(GL_TEXTURE_2D);
992
993                                         tutorialopac=1;
994
995                                         float startx;
996                                         float starty;
997
998                                         startx=screenwidth*1/5;
999                                         if(dialogueboxlocation[whichdialogue][indialogue]==1)starty=screenheight/16+screenheight*4/5;
1000                                         if(dialogueboxlocation[whichdialogue][indialogue]==2)starty=screenheight*1/5-screenheight/16;
1001
1002                                         char tempname[264];
1003                                         bool goodchar;
1004                                         int tempnum=0;
1005                                         for(i=0;i<264;i++){
1006                                                 tempname[i]='\0';
1007                                         }
1008
1009                                         for(i=0;i<(int)strlen(dialoguename[whichdialogue][indialogue]);i++){
1010                                                 tempname[tempnum]=dialoguename[whichdialogue][indialogue][i];
1011                                                 goodchar=1;
1012                                                 if(dialoguename[whichdialogue][indialogue][i]=='#'||dialoguename[whichdialogue][indialogue][i]=='\0')goodchar=0;
1013                                                 if(goodchar)
1014                                                         tempnum++;
1015                                                 else
1016                                                         tempname[tempnum]='\0';
1017                                         }
1018
1019                                         sprintf (string, "%s: ", tempname);
1020
1021                                         if(dialogueboxcolor[whichdialogue][indialogue][0]+dialogueboxcolor[whichdialogue][indialogue][1]+dialogueboxcolor[whichdialogue][indialogue][2]<1.5){
1022                                                 glColor4f(0,0,0,tutorialopac);
1023                                                 text.glPrintOutline(startx-2*7.6*strlen(string)*screenwidth/1024-4,starty-4,string,1,1.5*1.25*screenwidth/1024,screenwidth,screenheight);
1024                                                 glColor4f(0.7,0.7,0.7,tutorialopac);
1025                                                 text.glPrint(startx-2*7.6*strlen(string)*screenwidth/1024,starty,string,1,1.5*screenwidth/1024,screenwidth,screenheight);
1026                                         }
1027                                         else
1028                                         {
1029                                                 glColor4f(0,0,0,tutorialopac);
1030                                                 text.glPrintOutline(startx-2*7.6*strlen(string)*screenwidth/1024-4,starty-4,string,1,1.5*1.25*screenwidth/1024,screenwidth,screenheight);
1031                                         }
1032
1033                                         tempnum=0;
1034                                         for(i=0;i<(int)strlen(dialoguetext[whichdialogue][indialogue])+1;i++){
1035                                                 tempname[tempnum]=dialoguetext[whichdialogue][indialogue][i];
1036                                                 if(dialoguetext[whichdialogue][indialogue][i]!='#')tempnum++;
1037                                         }
1038
1039                                         sprintf (string, "%s", tempname);
1040
1041                                         int lastline = 0;
1042                                         int line = 0;
1043                                         bool done = false;
1044                                         i=0;
1045                                         while(!done){
1046                                                 if(string[i]=='\n'||string[i]>'z'||string[i]<' '||string[i]=='\0'){
1047                                                         if(dialogueboxcolor[whichdialogue][indialogue][0]+dialogueboxcolor[whichdialogue][indialogue][1]+dialogueboxcolor[whichdialogue][indialogue][2]<1.5){
1048                                                                 glColor4f(0,0,0,tutorialopac);
1049                                                                 text.glPrintOutline(startx/*-7.6*(i-lastline)*screenwidth/1024*/-4,starty-4-20*screenwidth/1024*line,string,1,1.5*1.25*screenwidth/1024,screenwidth,screenheight,lastline,i);
1050                                                                 glColor4f(1,1,1,tutorialopac);
1051                                                                 text.glPrint(startx/*-7.6*(i-lastline)*screenwidth/1024*/,starty-20*screenwidth/1024*line,string,1,1.5*screenwidth/1024,screenwidth,screenheight,lastline,i);
1052                                                         }
1053                                                         else
1054                                                         {
1055                                                                 glColor4f(0,0,0,tutorialopac);
1056                                                                 text.glPrint(startx/*-7.6*(i-lastline)*screenwidth/1024*/,starty-20*screenwidth/1024*line,string,1,1.5*screenwidth/1024,screenwidth,screenheight,lastline,i);
1057                                                         }
1058                                                         lastline=i+1;
1059                                                         line++;
1060                                                         if(string[i]=='\0')done=1;
1061                                                 }
1062                                                 if(i>=255)done=1;
1063                                                 i++;
1064                                         }
1065                                 }       
1066
1067                                 if(!tutoriallevel&&!winfreeze&&indialogue==-1&&!mainmenu){
1068                                         if(campaign){
1069                                                 if(scoreadded)
1070                                                         sprintf (string, "Score: %d", (int)accountactive->getCampaignScore());
1071                                                 else
1072                                                         sprintf (string, "Score: %d", (int)accountactive->getCampaignScore()+(int)bonustotal);
1073                                         }
1074                                         if(!campaign)sprintf (string, "Score: %d", (int)bonustotal);
1075                                         glColor4f(0,0,0,1);
1076                                         text.glPrintOutline(1024/40-4,768/16-4+768*14/16,string,1,1.5*1.25,1024,768);
1077                                         glColor4f(1,0,0,1);
1078                                         text.glPrint(1024/40,768/16+768*14/16,string,1,1.5,1024,768);
1079                                         if(showdamagebar) {
1080                                                 glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1081                                                 glDisable(GL_CULL_FACE);
1082                                                 glDisable(GL_LIGHTING);
1083                                                 glDisable(GL_TEXTURE_2D);
1084                                                 glDepthMask(0);
1085                                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1086                                                 glPushMatrix();                                                                         // Store The Projection Matrix
1087                                                 glLoadIdentity();                                                                       // Reset The Projection Matrix
1088                                                 glOrtho(0,screenwidth,0,screenheight,-100,100);         // Set Up An Ortho Screen
1089                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1090                                                 glPushMatrix();                                                                         // Store The Modelview Matrix
1091                                                 glLoadIdentity();                                                                       // Reset The Modelview Matrix
1092                                                 glTranslatef(15,screenheight*17.5/20,0);
1093                                                 glScalef(screenwidth/3+20,screenheight/20,1);
1094                                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1095                                                 glEnable(GL_BLEND);
1096                                                 glColor4f(0.0,0.4,0.0,0.7);
1097                                                 float bar=((float)player[0].damage)/player[0].damagetolerance;
1098                                                 glBegin(GL_QUADS);
1099                                                 glVertex3f((bar<1?bar:1),0,0.0f);
1100                                                 glVertex3f(1,0,0.0f);
1101                                                 glVertex3f(1,1,0.0f);
1102                                                 glVertex3f((bar<1?bar:1),1,0.0f);
1103                                                 glEnd();
1104                                                 glColor4f(0.1,0.0,0.0,1);
1105                                                 bar = ((float)player[0].bloodloss)/player[0].damagetolerance;
1106                                                 glBegin(GL_QUADS);
1107                                                 glVertex3f(0,0,0.0f);
1108                                                 glVertex3f((bar<1?bar:1),0,0.0f);
1109                                                 glVertex3f((bar<1?bar:1),1,0.0f);
1110                                                 glVertex3f(0,1,0.0f);
1111                                                 glEnd();
1112                                                 glColor4f(0.4,0.0,0.0,0.7);
1113                                                 bar = ((float)player[0].damage)/player[0].damagetolerance;
1114                                                 glBegin(GL_QUADS);
1115                                                 glVertex3f(0,0,0.0f);
1116                                                 glVertex3f((bar<1?bar:1),0,0.0f);
1117                                                 glVertex3f((bar<1?bar:1),1,0.0f);
1118                                                 glVertex3f(0,1,0.0f);
1119                                                 glEnd();
1120                                                 glColor4f(0.4,0.0,0.0,0.7);
1121                                                 bar = ((float)player[0].permanentdamage)/player[0].damagetolerance;
1122                                                 glBegin(GL_QUADS);
1123                                                 glVertex3f(0,0,0.0f);
1124                                                 glVertex3f((bar<1?bar:1),0,0.0f);
1125                                                 glVertex3f((bar<1?bar:1),1,0.0f);
1126                                                 glVertex3f(0,1,0.0f);
1127                                                 glEnd();
1128                                                 glColor4f(0.4,0.0,0.0,0.7);
1129                                                 bar = ((float)player[0].superpermanentdamage)/player[0].damagetolerance;
1130                                                 glBegin(GL_QUADS);
1131                                                 glVertex3f(0,0,0.0f);
1132                                                 glVertex3f((bar<1?bar:1),0,0.0f);
1133                                                 glVertex3f((bar<1?bar:1),1,0.0f);
1134                                                 glVertex3f(0,1,0.0f);
1135                                                 glEnd();
1136                                                 glColor4f(0.0,0.0,0.0,0.7);
1137                                                 glLineWidth(2.0);
1138                                                 glBegin(GL_LINE_STRIP);
1139                                                 glVertex3f(0,0,0.0f);
1140                                                 glVertex3f(1,0,0.0f);
1141                                                 glVertex3f(1,1,0.0f);
1142                                                 glVertex3f(0,1,0.0f);
1143                                                 glVertex3f(0,0,0.0f);
1144                                                 glEnd();
1145                                                 
1146                                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1147                                                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
1148                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1149                                                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
1150                                                 glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1151                                                 glEnable(GL_CULL_FACE);
1152                                                 glDisable(GL_BLEND);
1153                                                 glDepthMask(1);
1154                                                 glEnable(GL_TEXTURE_2D);
1155                                                 
1156                                                 // writing the numbers : 
1157                                                 sprintf (string, "Damages : %d/%d (%d)",(int)(player[0].damage),(int)(player[0].damagetolerance),(int)(player[0].bloodloss));
1158                                                 glColor4f(0,0,0,1);
1159                                                 text.glPrintOutline(1024/40-4,768/16-4+768*14/16-40,string,1,1.5*1.25,1024,768);
1160                                                 glColor4f(1,0,0,1);
1161                                                 text.glPrint(1024/40,768/16+768*14/16-40,string,1,1.5,1024,768);
1162                                         }
1163                                 }
1164
1165                                 glColor4f(.5,.5,.5,1);
1166
1167
1168                                 if((texttoggle||editorenabled)&&debugmode&&!mainmenu){
1169                                         sprintf (string, "The framespersecond is %d.",(int)(fps));
1170                                         text.glPrint(10,30,string,0,.8,1024,768);
1171
1172                                         sprintf (string, "Name: %s", registrationname);
1173                                         text.glPrint(10,260,string,0,.8,1024,768);
1174
1175
1176                                         if(editorenabled)
1177                                                 sprintf (string, "Map editor enabled.");
1178                                         else
1179                                                 sprintf (string, "Map editor disabled.");
1180                                         text.glPrint(10,60,string,0,.8,1024,768);
1181                                         if(editorenabled){
1182                                                 sprintf (string, "Object size: %f",editorsize);
1183                                                 text.glPrint(10,75,string,0,.8,1024,768);
1184                                                 if(editorrotation>=0)sprintf (string, "Object rotation: %f",editorrotation);
1185                                                 else sprintf (string, "Object rotation: Random");
1186                                                 text.glPrint(10,90,string,0,.8,1024,768);
1187                                                 if(editorrotation2>=0)sprintf (string, "Object rotation2: %f",editorrotation2);
1188                                                 else sprintf (string, "Object rotation2: Random");
1189                                                 text.glPrint(10,105,string,0,.8,1024,768);
1190                                                 sprintf (string, "Object type: %d",editortype);
1191                                                 text.glPrint(10,120,string,0,.8,1024,768);
1192                                                 switch(editortype) {
1193                                                         case boxtype: 
1194                                                                 sprintf (string, "(box)");
1195                                                                 break;
1196                                                         case treetrunktype: 
1197                                                                 sprintf (string, "(tree)");
1198                                                                 break;
1199                                                         case walltype: 
1200                                                                 sprintf (string, "(wall)");
1201                                                                 break;
1202                                                         case weirdtype: 
1203                                                                 sprintf (string, "(weird)");
1204                                                                 break;
1205                                                         case spiketype: 
1206                                                                 sprintf (string, "(spike)");
1207                                                                 break;
1208                                                         case rocktype: 
1209                                                                 sprintf (string, "(rock)");
1210                                                                 break;
1211                                                         case bushtype: 
1212                                                                 sprintf (string, "(bush)");
1213                                                                 break;
1214                                                         case tunneltype: 
1215                                                                 sprintf (string, "(tunnel)");
1216                                                                 break;
1217                                                         case chimneytype: 
1218                                                                 sprintf (string, "(chimney)");
1219                                                                 break;
1220                                                         case platformtype: 
1221                                                                 sprintf (string, "(platform)");
1222                                                                 break;
1223                                                         case cooltype: 
1224                                                                 sprintf (string, "(cool)");
1225                                                                 break;
1226                                                         case firetype: 
1227                                                                 sprintf (string, "(fire)");
1228                                                                 break;
1229                                                 }
1230                                                 text.glPrint(130,120,string,0,.8,1024,768);
1231
1232                                                 sprintf (string, "Numplayers: %d",numplayers);
1233                                                 text.glPrint(10,155,string,0,.8,1024,768);
1234                                                 sprintf (string, "Player %d: numwaypoints: %d",numplayers,player[numplayers-1].numwaypoints);
1235                                                 text.glPrint(10,140,string,0,.8,1024,768);
1236                                         }
1237                                         sprintf (string, "Difficulty: %d",difficulty);
1238                                         text.glPrint(10,240,string,0,.8,1024,768);
1239
1240                                 }
1241                 }
1242
1243                 if(drawmode==glowmode){
1244                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1245                         glDisable(GL_CULL_FACE);
1246                         glDisable(GL_LIGHTING);
1247                         glDisable(GL_TEXTURE_2D);
1248                         glDepthMask(0);
1249                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1250                         glPushMatrix();                                                                         // Store The Projection Matrix
1251                         glLoadIdentity();                                                                       // Reset The Projection Matrix
1252                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
1253                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1254                         glPushMatrix();                                                                         // Store The Modelview Matrix
1255                         glLoadIdentity();                                                               // Reset The Modelview Matrix
1256                         glScalef(screenwidth,screenheight,1);
1257                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1258                         glEnable(GL_BLEND);
1259                         glColor4f(0,0,0,.5);
1260                         glBegin(GL_QUADS);
1261                         glVertex3f(0,           0,       0.0f);
1262                         glVertex3f(256, 0,       0.0f);
1263                         glVertex3f(256, 256, 0.0f);
1264                         glVertex3f(0,   256, 0.0f);
1265                         glEnd();
1266                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1267                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1268                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1269                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1270                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1271                         glEnable(GL_CULL_FACE);
1272                         glDisable(GL_BLEND);
1273                         glDepthMask(1);
1274                 }
1275
1276                 if((((blackout&&damageeffects)||(player[0].bloodloss>0&&damageeffects&&player[0].blooddimamount>0)||player[0].dead)&&!cameramode)||console){
1277                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1278                         glDisable(GL_CULL_FACE);
1279                         glDisable(GL_LIGHTING);
1280                         glDisable(GL_TEXTURE_2D);
1281                         glDepthMask(0);
1282                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1283                         glPushMatrix();                                                                         // Store The Projection Matrix
1284                         glLoadIdentity();                                                                       // Reset The Projection Matrix
1285                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
1286                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1287                         glPushMatrix();                                                                         // Store The Modelview Matrix
1288                         glLoadIdentity();                                                               // Reset The Modelview Matrix
1289                         glScalef(screenwidth,screenheight,1);
1290                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1291                         glEnable(GL_BLEND);
1292                         if(player[0].dead)blackout+=multiplier*3;
1293                         if(player[0].dead==1)blackout=.4f;
1294                         if(player[0].dead==2&&blackout>.6)blackout=.6;
1295                         glColor4f(0,0,0,blackout);
1296                         if(!player[0].dead){
1297                                 if((player[0].bloodloss/player[0].damagetolerance*(sin(woozy)/4+.5))*.3<.3){
1298                                         glColor4f(0,0,0,player[0].blooddimamount*player[0].bloodloss/player[0].damagetolerance*(sin(woozy)/4+.5)*.3);
1299                                         blackout=player[0].blooddimamount*player[0].bloodloss/player[0].damagetolerance*(sin(woozy)/4+.5)*.3;
1300                                 }
1301                                 else {
1302                                         glColor4f(0,0,0,player[0].blooddimamount*.3);
1303                                         blackout=player[0].blooddimamount*.3;
1304                                 }
1305                         }
1306                         if(console)glColor4f(.7,0,0,.2);
1307                         glBegin(GL_QUADS);
1308                         glVertex3f(0,           0,       0.0f);
1309                         glVertex3f(256, 0,       0.0f);
1310                         glVertex3f(256, 256, 0.0f);
1311                         glVertex3f(0,   256, 0.0f);
1312                         glEnd();
1313                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1314                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1315                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1316                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1317                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1318                         glEnable(GL_CULL_FACE);
1319                         glDisable(GL_BLEND);
1320                         glDepthMask(1);
1321                 }
1322
1323                 if(flashamount>0&&damageeffects){
1324                         if(flashamount>1)flashamount=1;
1325                         if(flashdelay<=0)flashamount-=multiplier;
1326                         flashdelay--;
1327                         if(flashamount<0)flashamount=0;
1328                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1329                         glDisable(GL_CULL_FACE);
1330                         glDisable(GL_LIGHTING);
1331                         glDepthMask(0);
1332                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1333                         glPushMatrix();                                                                         // Store The Projection Matrix
1334                         glLoadIdentity();                                                                       // Reset The Projection Matrix
1335                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
1336                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1337                         glPushMatrix();                                                                         // Store The Modelview Matrix
1338                         glLoadIdentity();                                                               // Reset The Modelview Matrix
1339                         glScalef(screenwidth,screenheight,1);
1340                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1341                         glEnable(GL_BLEND);
1342                         glColor4f(flashr,flashg,flashb,flashamount);
1343                         glBegin(GL_QUADS);
1344                         glVertex3f(0,           0,       0.0f);
1345                         glVertex3f(256, 0,       0.0f);
1346                         glVertex3f(256, 256, 0.0f);
1347                         glVertex3f(0,   256, 0.0f);
1348                         glEnd();
1349                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1350                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1351                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1352                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1353                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1354                         glEnable(GL_CULL_FACE);
1355                         glDisable(GL_BLEND);
1356                         glDepthMask(1);
1357                 }       
1358
1359                 if(!console){
1360                         displaytime[0]=0;
1361                         glEnable(GL_TEXTURE_2D);
1362                         glColor4f(1,1,1,1);
1363                         if(chatting){
1364                                 sprintf (string, " ]");
1365                                 text.glPrint(10,30+screenheight-330,string,0,1,screenwidth,screenheight);
1366                                 if(displayblink){
1367                                         sprintf (string, "_");
1368                                         text.glPrint(30+(float)(displayselected)*10,30+(screenheight-330),string,0,1,screenwidth,screenheight);
1369                                 }
1370                         }
1371                         for(i=0;i<15;i++){
1372                                 if((i!=0||chatting)&&displaytime[i]<4)
1373                                         for(j=0;j<displaychars[i];j++){
1374                                                 glColor4f(1,1,1,4-displaytime[i]);
1375                                                 if(j<displaychars[i]){
1376                                                         sprintf (string, "%c",displaytext[i][j]);
1377                                                         text.glPrint(30+j*10,30+i*20+(screenheight-330),string,0,1,screenwidth,screenheight);
1378                                                 }
1379                                         }
1380                         }
1381                 }
1382
1383                 if(minimap&&indialogue==-1){
1384                         float mapviewdist = 20000;
1385
1386                         glDisable(GL_DEPTH_TEST);
1387                         glColor3f (1.0, 1.0, 1.0); // no coloring
1388
1389                         glEnable(GL_TEXTURE_2D);
1390                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
1391                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
1392                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1393                         glDisable(GL_CULL_FACE);
1394                         glDisable(GL_LIGHTING);
1395                         glDepthMask(0);
1396                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1397                         glPushMatrix();                                                                         // Store The Projection Matrix
1398                         glLoadIdentity();                                                                       // Reset The Projection Matrix
1399                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
1400                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1401                         glPushMatrix();                                                                         // Store The Modelview Matrix
1402                         glLoadIdentity();                                                               // Reset The Modelview Matrix
1403                         glScalef((float)screenwidth/2,(float)screenwidth/2,1);
1404                         glTranslatef(1.75,.25,0);
1405                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1406                         glEnable(GL_BLEND);
1407                         glColor4f(1,1,1,1);
1408                         glPushMatrix();
1409                         float opac = .7;
1410                         XYZ center;
1411                         float radius;
1412                         float distcheck;
1413                         int numliveplayers=0;
1414                         center = 0;
1415                         for(i=0;i<numplayers;i++){
1416                                 if(!player[i].dead) numliveplayers++;
1417                         }
1418
1419                         int numadd = 0;
1420
1421                         for(i=0;i<objects.numobjects;i++){
1422                                 if(objects.type[i]==treetrunktype||objects.type[i]==boxtype){
1423                                         center+=objects.position[i];    
1424                                         numadd++;
1425                                 }
1426                         }
1427                         for(i=0;i<numplayers;i++){
1428                                 if(!player[i].dead)center+=player[i].coords;    
1429                         }
1430                         center/=numadd+numliveplayers;
1431
1432                         center=player[0].coords;
1433
1434                         float maxdistance=0;
1435                         float tempdist;
1436                         int whichclosest;
1437                         for(i=0;i<objects.numobjects;i++){
1438                                 tempdist=findDistancefast(&center,&objects.position[i]);
1439                                 if(tempdist>maxdistance){
1440                                         whichclosest=i;
1441                                         maxdistance=tempdist;
1442                                 }
1443                         }
1444                         for(i=0;i<numplayers;i++){
1445                                 if(!player[i].dead){
1446                                         tempdist=findDistancefast(&center,&player[i].coords);
1447                                         if(tempdist>maxdistance){
1448                                                 whichclosest=i;
1449                                                 maxdistance=tempdist;
1450                                         }
1451                                 }
1452                         }
1453                         radius=fast_sqrt(maxdistance);
1454
1455                         radius=110;
1456
1457                         glScalef(.25/radius*256*terrain.scale*.4,.25/radius*256*terrain.scale*.4,1);
1458                         glPushMatrix();
1459                         glScalef(1/(1/radius*256*terrain.scale*.4),1/(1/radius*256*terrain.scale*.4),1);
1460                         glPopMatrix();
1461                         glRotatef(player[0].lookrotation*-1+180,0,0,1);
1462                         glTranslatef(-(center.x/terrain.scale/256*-2+1),(center.z/terrain.scale/256*-2+1),0);
1463                         for(i=0;i<objects.numobjects;i++){
1464                                 if(objects.type[i]==treetrunktype){
1465                                         distcheck=findDistancefast(&player[0].coords,&objects.position[i]);
1466                                         if(distcheck<mapviewdist){
1467                                                 glBindTexture( GL_TEXTURE_2D, Mapcircletexture);
1468                                                 glColor4f(0,.3,0,opac*(1-distcheck/mapviewdist));
1469                                                 glPushMatrix();
1470                                                 glTranslatef(objects.position[i].x/terrain.scale/256*-2+1,objects.position[i].z/terrain.scale/256*2-1,0);
1471                                                 glRotatef(objects.rotation[i],0,0,1);
1472                                                 glScalef(.003,.003,.003);
1473                                                 glBegin(GL_QUADS);
1474                                                 glTexCoord2f(0,0);
1475                                                 glVertex3f(-1,          -1,      0.0f);
1476                                                 glTexCoord2f(1,0);
1477                                                 glVertex3f(1,   -1,      0.0f);
1478                                                 glTexCoord2f(1,1);
1479                                                 glVertex3f(1,   1, 0.0f);
1480                                                 glTexCoord2f(0,1);
1481                                                 glVertex3f(-1,  1, 0.0f);
1482                                                 glEnd();
1483                                                 glPopMatrix();
1484                                         }
1485                                 }
1486                                 if(objects.type[i]==boxtype){
1487                                         distcheck=findDistancefast(&player[0].coords,&objects.position[i]);
1488                                         if(distcheck<mapviewdist){
1489                                                 glBindTexture( GL_TEXTURE_2D, Mapboxtexture);
1490                                                 glColor4f(.4,.4,.4,opac*(1-distcheck/mapviewdist));
1491                                                 glPushMatrix();
1492                                                 glTranslatef(objects.position[i].x/terrain.scale/256*-2+1,objects.position[i].z/terrain.scale/256*2-1,0);
1493                                                 glRotatef(objects.rotation[i],0,0,1);
1494                                                 glScalef(.01*objects.scale[i],.01*objects.scale[i],.01*objects.scale[i]);
1495                                                 glBegin(GL_QUADS);
1496                                                 glTexCoord2f(0,0);
1497                                                 glVertex3f(-1,          -1,      0.0f);
1498                                                 glTexCoord2f(1,0);
1499                                                 glVertex3f(1,   -1,      0.0f);
1500                                                 glTexCoord2f(1,1);
1501                                                 glVertex3f(1,   1, 0.0f);
1502                                                 glTexCoord2f(0,1);
1503                                                 glVertex3f(-1,  1, 0.0f);
1504                                                 glEnd();
1505                                                 glPopMatrix();
1506                                         }
1507                                 }
1508                         }
1509                         if(editorenabled){
1510                                 glBindTexture( GL_TEXTURE_2D, Mapcircletexture);
1511                                 for(i=0;i<numboundaries;i++){
1512                                         glColor4f(0,0,0,opac/3);
1513                                         glPushMatrix();
1514                                         glTranslatef(boundary[i].x/terrain.scale/256*-2+1,boundary[i].z/terrain.scale/256*2-1,0);
1515                                         glScalef(.002,.002,.002);
1516                                         glBegin(GL_QUADS);
1517                                         glTexCoord2f(0,0);
1518                                         glVertex3f(-1,          -1,      0.0f);
1519                                         glTexCoord2f(1,0);
1520                                         glVertex3f(1,   -1,      0.0f);
1521                                         glTexCoord2f(1,1);
1522                                         glVertex3f(1,   1, 0.0f);
1523                                         glTexCoord2f(0,1);
1524                                         glVertex3f(-1,  1, 0.0f);
1525                                         glEnd();
1526                                         glPopMatrix();
1527                                 }
1528                         }
1529                         for(i=0;i<numplayers;i++){
1530                                 distcheck=findDistancefast(&player[0].coords,&player[i].coords);
1531                                 if(distcheck<mapviewdist){
1532                                         glPushMatrix();
1533                                         glBindTexture( GL_TEXTURE_2D, Maparrowtexture);
1534                                         if(i==0)glColor4f(1,1,1,opac);
1535                                         else if(player[i].dead==2||player[i].howactive>typesleeping)glColor4f(0,0,0,opac*(1-distcheck/mapviewdist));
1536                                         else if(player[i].dead)glColor4f(.3,.3,.3,opac*(1-distcheck/mapviewdist));
1537                                         else if(player[i].aitype==attacktypecutoff)glColor4f(1,0,0,opac*(1-distcheck/mapviewdist));
1538                                         else if(player[i].aitype==passivetype)glColor4f(0,1,0,opac*(1-distcheck/mapviewdist));
1539                                         else glColor4f(1,1,0,1);
1540                                         glTranslatef(player[i].coords.x/terrain.scale/256*-2+1,player[i].coords.z/terrain.scale/256*2-1,0);
1541                                         glRotatef(player[i].rotation+180,0,0,1);
1542                                         glScalef(.005,.005,.005);
1543                                         glBegin(GL_QUADS);
1544                                         glTexCoord2f(0,0);
1545                                         glVertex3f(-1,          -1,      0.0f);
1546                                         glTexCoord2f(1,0);
1547                                         glVertex3f(1,   -1,      0.0f);
1548                                         glTexCoord2f(1,1);
1549                                         glVertex3f(1,   1, 0.0f);
1550                                         glTexCoord2f(0,1);
1551                                         glVertex3f(-1,  1, 0.0f);
1552                                         glEnd();
1553                                         glPopMatrix();
1554                                 }
1555                         }
1556                         glPopMatrix();
1557                         glDisable(GL_TEXTURE_2D);
1558                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1559                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1560                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1561                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1562                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1563                         glEnable(GL_CULL_FACE);
1564                         glDisable(GL_BLEND);
1565                         glDepthMask(1);
1566                 }
1567
1568                 if(loading&&!stealthloading&&(!campaign||player[0].dead)){
1569                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1570                         glDisable(GL_CULL_FACE);
1571                         glDisable(GL_LIGHTING);
1572                         glDisable(GL_TEXTURE_2D);
1573                         glDepthMask(0);
1574                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1575                         glPushMatrix();                                                                         // Store The Projection Matrix
1576                         glLoadIdentity();                                                                       // Reset The Projection Matrix
1577                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
1578                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1579                         glPushMatrix();                                                                         // Store The Modelview Matrix
1580                         glLoadIdentity();                                                               // Reset The Modelview Matrix
1581                         glScalef(screenwidth,screenheight,1);
1582                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1583                         glEnable(GL_BLEND);
1584                         glColor4f(0,0,0,.7);
1585                         glBegin(GL_QUADS);
1586                         glVertex3f(0,           0,       0.0f);
1587                         glVertex3f(256, 0,       0.0f);
1588                         glVertex3f(256, 256, 0.0f);
1589                         glVertex3f(0,   256, 0.0f);
1590                         glEnd();
1591                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1592                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1593                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1594                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1595                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1596                         glEnable(GL_CULL_FACE);
1597                         glDisable(GL_BLEND);
1598                         glDepthMask(1);
1599
1600                         //logo
1601                         glDisable(GL_DEPTH_TEST);
1602                         glColor3f (1.0, 1.0, 1.0); // no coloring
1603
1604                         glEnable(GL_TEXTURE_2D);
1605
1606                         //Minimap
1607
1608                         if(loading!=4){                         
1609                                 glEnable(GL_TEXTURE_2D);
1610                                 glColor4f(1,1,1,1);
1611                                 sprintf (string, "Loading...");
1612                                 text.glPrint(1024/2-90,768/2,string,1,2,1024,768);
1613                         }
1614                         loading=2;
1615                         //if(ismotionblur)drawmode=motionblurmode;
1616                         drawmode=normalmode;
1617                 }
1618
1619                 if(winfreeze&&!campaign){
1620                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1621                         glDisable(GL_CULL_FACE);
1622                         glDisable(GL_LIGHTING);
1623                         glDisable(GL_TEXTURE_2D);
1624                         glDepthMask(0);
1625                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1626                         glPushMatrix();                                                                         // Store The Projection Matrix
1627                         glLoadIdentity();                                                                       // Reset The Projection Matrix
1628                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
1629                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1630                         glPushMatrix();                                                                         // Store The Modelview Matrix
1631                         glLoadIdentity();                                                               // Reset The Modelview Matrix
1632                         glScalef(screenwidth,screenheight,1);
1633                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1634                         glEnable(GL_BLEND);
1635                         glColor4f(0,0,0,.4);
1636                         glBegin(GL_QUADS);
1637                         glVertex3f(0,           0,       0.0f);
1638                         glVertex3f(256, 0,       0.0f);
1639                         glVertex3f(256, 256, 0.0f);
1640                         glVertex3f(0,   256, 0.0f);
1641                         glEnd();
1642                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1643                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1644                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1645                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1646                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1647                         glEnable(GL_CULL_FACE);
1648                         glDisable(GL_BLEND);
1649                         glDepthMask(1);
1650
1651                         //logo
1652                         glDisable(GL_DEPTH_TEST);
1653                         glColor3f (1.0, 1.0, 1.0); // no coloring
1654
1655                         glEnable(GL_TEXTURE_2D);
1656
1657                         //Win Screen Won Victory
1658
1659                         glEnable(GL_TEXTURE_2D);
1660                         glColor4f(1,1,1,1);
1661                         sprintf (string, "Level Cleared!");
1662                         text.glPrintOutlined(1024/2-strlen(string)*10,768*7/8,string,1,2,1024,768);
1663
1664                         sprintf (string, "Score:     %d",(int)(bonustotal-startbonustotal));
1665                         text.glPrintOutlined(1024/30,768*6/8,string,1,2,1024,768);
1666
1667                         if(campaign)
1668                                 sprintf (string, "Press Escape or Space to continue");
1669                         else
1670                                 sprintf (string, "Press Escape to return to menu or Space to continue");
1671                         text.glPrintOutlined(640/2-strlen(string)*5,480*1/16,string,1,1,640,480);
1672
1673                         char temp[255];
1674
1675                         for(i=0;i<255;i++)string[i]='\0';
1676                         sprintf (temp, "Time:      %d:",(int)(((int)leveltime-(int)(leveltime)%60)/60));
1677                         strcat(string,temp);
1678                         if((int)(leveltime)%60<10)strcat(string,"0");
1679                         sprintf (temp, "%d",(int)(leveltime)%60);
1680                         strcat(string,temp);
1681                         text.glPrintOutlined(1024/30,768*6/8-40,string,1,2,1024,768);
1682
1683                         //Awards
1684                         int awards[award_count];
1685                         int numawards = award_awards(awards);
1686
1687                         for (i = 0; i < numawards && i < 6; i++)
1688                           text.glPrintOutlined(1024/30,768*6/8-90-40*i,award_names[awards[i]],1,2,1024,768);
1689                 }
1690
1691                 if(drawmode!=normalmode){
1692                         glEnable(GL_TEXTURE_2D);
1693                         glFinish();
1694                         if(!drawtoggle||drawmode!=realmotionblurmode||(drawtoggle==2||change==1)){
1695                                 if(screentexture){
1696
1697                                         glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
1698                                         GLfloat subtractColor[4] = { 0.5, 0.5, 0.5, 0.0 };
1699                                         glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, subtractColor);
1700                                         //glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_SUBTRACT);
1701                                         glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
1702                                         glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_CONSTANT_EXT);
1703                                         glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 2.0f);
1704
1705                                         glBindTexture( GL_TEXTURE_2D, screentexture);
1706                                         glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texviewwidth, texviewheight);         
1707                                 }
1708                         }
1709                         if((drawtoggle||change==1)&&drawmode==realmotionblurmode){
1710                                 if(screentexture2){
1711                                         glBindTexture( GL_TEXTURE_2D, screentexture2);
1712                                         glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texviewwidth, texviewheight);         
1713                                 }
1714                                 if(!screentexture2){
1715                                         glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
1716
1717                                         glGenTextures( 1, &screentexture2 );
1718                                         glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1719
1720                                         glEnable(GL_TEXTURE_2D);
1721                                         glBindTexture( GL_TEXTURE_2D, screentexture2);
1722                                         glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
1723                                         glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
1724
1725                                         glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);                
1726                                 }
1727                         }
1728                         //glFlush();
1729                 }
1730
1731                 glClear(GL_DEPTH_BUFFER_BIT);
1732                 ReSizeGLScene(90,.1f);
1733                 glViewport(0,0,screenwidth,screenheight);       
1734
1735                 if(drawmode!=normalmode){
1736                         glDisable(GL_DEPTH_TEST);
1737                         if(drawmode==motionblurmode){
1738                                 glDrawBuffer(GL_FRONT);
1739                                 glReadBuffer(GL_BACK);
1740                         }
1741                         glColor3f (1.0, 1.0, 1.0); // no coloring
1742
1743                         glEnable(GL_TEXTURE_2D);
1744                         glBindTexture( GL_TEXTURE_2D, screentexture);
1745                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
1746                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
1747                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1748                         glDisable(GL_CULL_FACE);
1749                         glDisable(GL_LIGHTING);
1750                         glDepthMask(0);
1751                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1752                         glPushMatrix();                                                                         // Store The Projection Matrix
1753                         glLoadIdentity();                                                                       // Reset The Projection Matrix
1754                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
1755                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1756                         glPushMatrix();                                                                         // Store The Modelview Matrix
1757                         glLoadIdentity();                                                               // Reset The Modelview Matrix
1758                         glScalef((float)screenwidth/2,(float)screenheight/2,1);
1759                         glTranslatef(1,1,0);
1760                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1761                         glEnable(GL_BLEND);
1762                         if(drawmode==motionblurmode){
1763                                 if(motionbluramount<.2)motionbluramount=.2;
1764                                 //glColor4f(1,1,1,fast_sqrt(multiplier)*2.9*motionbluramount);
1765                                 glColor4f(1,1,1,motionbluramount);
1766                                 glPushMatrix();
1767                                 glBegin(GL_QUADS);
1768                                 glTexCoord2f(0,0);
1769                                 glVertex3f(-1,          -1,      0.0f);
1770                                 glTexCoord2f(texcoordwidth,0);
1771                                 glVertex3f(1,   -1,      0.0f);
1772                                 glTexCoord2f(texcoordwidth,texcoordheight);
1773                                 glVertex3f(1,   1, 0.0f);
1774                                 glTexCoord2f(0,texcoordheight);
1775                                 glVertex3f(-1,  1, 0.0f);
1776                                 glEnd();
1777                                 glPopMatrix();
1778                         }
1779                         if(drawmode==realmotionblurmode){
1780                                 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
1781                                 glClear(GL_COLOR_BUFFER_BIT);
1782                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
1783                                 glBindTexture( GL_TEXTURE_2D, screentexture);
1784                                 glColor4f(1,1,1,.5);
1785                                 glPushMatrix();
1786                                 glBegin(GL_QUADS);
1787                                 glTexCoord2f(0,0);
1788                                 glVertex3f(-1,          -1,      0.0f);
1789                                 glTexCoord2f(texcoordwidth,0);
1790                                 glVertex3f(1,   -1,      0.0f);
1791                                 glTexCoord2f(texcoordwidth,texcoordheight);
1792                                 glVertex3f(1,   1, 0.0f);
1793                                 glTexCoord2f(0,texcoordheight);
1794                                 glVertex3f(-1,  1, 0.0f);
1795                                 glEnd();
1796                                 glPopMatrix();
1797                                 glBindTexture( GL_TEXTURE_2D, screentexture2);
1798                                 glColor4f(1,1,1,.5);
1799                                 glPushMatrix();
1800                                 glBegin(GL_QUADS);
1801                                 glTexCoord2f(0,0);
1802                                 glVertex3f(-1,          -1,      0.0f);
1803                                 glTexCoord2f(texcoordwidth,0);
1804                                 glVertex3f(1,   -1,      0.0f);
1805                                 glTexCoord2f(texcoordwidth,texcoordheight);
1806                                 glVertex3f(1,   1, 0.0f);
1807                                 glTexCoord2f(0,texcoordheight);
1808                                 glVertex3f(-1,  1, 0.0f);
1809                                 glEnd();
1810                                 glPopMatrix();
1811                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1812                         }
1813                         if(drawmode==doublevisionmode){
1814                                 static float crosseyedness;
1815                                 crosseyedness=abs(player[0].damage-player[0].superpermanentdamage-(player[0].damagetolerance-player[0].superpermanentdamage)*1/2)/30;
1816                                 if(crosseyedness>1)crosseyedness=1;
1817                                 if(crosseyedness<0)crosseyedness=0;
1818                                 glColor4f(1,1,1,1);
1819                                 glDisable(GL_BLEND);
1820                                 glPushMatrix();
1821                                 glScalef(1,1,1);
1822                                 glBegin(GL_QUADS);
1823                                 glTexCoord2f(0,0);
1824                                 glVertex3f(-1,          -1,      0.0f);
1825                                 glTexCoord2f(texcoordwidth,0);
1826                                 glVertex3f(1,   -1,      0.0f);
1827                                 glTexCoord2f(texcoordwidth,texcoordheight);
1828                                 glVertex3f(1,   1, 0.0f);
1829                                 glTexCoord2f(0,texcoordheight);
1830                                 glVertex3f(-1,  1, 0.0f);
1831                                 glEnd();
1832                                 glPopMatrix();
1833                                 if(crosseyedness){
1834                                         glColor4f(1,1,1,.5);
1835                                         glEnable(GL_BLEND);
1836                                         glPushMatrix();
1837                                         glTranslatef(.015*crosseyedness,0,0);
1838                                         glScalef(1,1,1);
1839                                         glBegin(GL_QUADS);
1840                                         glTexCoord2f(0,0);
1841                                         glVertex3f(-1,          -1,      0.0f);
1842                                         glTexCoord2f(texcoordwidth,0);
1843                                         glVertex3f(1,   -1,      0.0f);
1844                                         glTexCoord2f(texcoordwidth,texcoordheight);
1845                                         glVertex3f(1,   1, 0.0f);
1846                                         glTexCoord2f(0,texcoordheight);
1847                                         glVertex3f(-1,  1, 0.0f);
1848                                         glEnd();
1849                                         glPopMatrix();
1850                                 }
1851                         }
1852                         if(drawmode==glowmode){
1853                                 glColor4f(.5,.5,.5,.5);
1854                                 glEnable(GL_BLEND);
1855                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
1856                                 glPushMatrix();
1857                                 glTranslatef(.01,0,0);
1858                                 glBegin(GL_QUADS);
1859                                 glTexCoord2f(0,0);
1860                                 glVertex3f(-1,          -1,      0.0f);
1861                                 glTexCoord2f(texcoordwidth,0);
1862                                 glVertex3f(1,   -1,      0.0f);
1863                                 glTexCoord2f(texcoordwidth,texcoordheight);
1864                                 glVertex3f(1,   1, 0.0f);
1865                                 glTexCoord2f(0,texcoordheight);
1866                                 glVertex3f(-1,  1, 0.0f);
1867                                 glEnd();
1868                                 glPopMatrix();
1869                                 glPushMatrix();
1870                                 glTranslatef(-.01,0,0);
1871                                 glBegin(GL_QUADS);
1872                                 glTexCoord2f(0,0);
1873                                 glVertex3f(-1,          -1,      0.0f);
1874                                 glTexCoord2f(texcoordwidth,0);
1875                                 glVertex3f(1,   -1,      0.0f);
1876                                 glTexCoord2f(texcoordwidth,texcoordheight);
1877                                 glVertex3f(1,   1, 0.0f);
1878                                 glTexCoord2f(0,texcoordheight);
1879                                 glVertex3f(-1,  1, 0.0f);
1880                                 glEnd();
1881                                 glPopMatrix();
1882                                 glPushMatrix();
1883                                 glTranslatef(.0,.01,0);
1884                                 glBegin(GL_QUADS);
1885                                 glTexCoord2f(0,0);
1886                                 glVertex3f(-1,          -1,      0.0f);
1887                                 glTexCoord2f(texcoordwidth,0);
1888                                 glVertex3f(1,   -1,      0.0f);
1889                                 glTexCoord2f(texcoordwidth,texcoordheight);
1890                                 glVertex3f(1,   1, 0.0f);
1891                                 glTexCoord2f(0,texcoordheight);
1892                                 glVertex3f(-1,  1, 0.0f);
1893                                 glEnd();
1894                                 glPopMatrix();
1895                                 glPushMatrix();
1896                                 glTranslatef(0,-.01,0);
1897                                 glBegin(GL_QUADS);
1898                                 glTexCoord2f(0,0);
1899                                 glVertex3f(-1,          -1,      0.0f);
1900                                 glTexCoord2f(texcoordwidth,0);
1901                                 glVertex3f(1,   -1,      0.0f);
1902                                 glTexCoord2f(texcoordwidth,texcoordheight);
1903                                 glVertex3f(1,   1, 0.0f);
1904                                 glTexCoord2f(0,texcoordheight);
1905                                 glVertex3f(-1,  1, 0.0f);
1906                                 glEnd();
1907                                 glPopMatrix();
1908                         }
1909                         if(drawmode==radialzoommode){
1910                                 for(i=0;i<3;i++){
1911                                         //glRotatef((float)i*.1,0,0,1);
1912                                         glColor4f(1,1,1,1/((float)i+1));
1913                                         glPushMatrix();
1914                                         glScalef(1+(float)i*.01,1+(float)i*.01,1);
1915                                         glBegin(GL_QUADS);
1916                                         glTexCoord2f(0,0);
1917                                         glVertex3f(-1,          -1,      0.0f);
1918                                         glTexCoord2f(texcoordwidth,0);
1919                                         glVertex3f(1,   -1,      0.0f);
1920                                         glTexCoord2f(texcoordwidth,texcoordheight);
1921                                         glVertex3f(1,   1, 0.0f);
1922                                         glTexCoord2f(0,texcoordheight);
1923                                         glVertex3f(-1,  1, 0.0f);
1924                                         glEnd();
1925                                         glPopMatrix();
1926                                 }
1927                         }
1928                         glDisable(GL_TEXTURE_2D);
1929                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1930                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1931                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1932                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1933                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1934                         glEnable(GL_CULL_FACE);
1935                         glDisable(GL_BLEND);
1936                         glDepthMask(1);
1937                 }
1938
1939                 if(console){
1940                         glEnable(GL_TEXTURE_2D);
1941                         glColor4f(1,1,1,1);
1942                         int offset = 0;
1943                         if(consoleselected>=60)
1944                                 offset=consoleselected-60;
1945                         sprintf (string, " ]");
1946                         text.glPrint(10,30,string,0,1,1024,768);
1947                         if(consoleblink){
1948                                 sprintf (string, "_");
1949                                 text.glPrint(30+(float)(consoleselected)*10-offset*10,30,string,0,1,1024,768);
1950                         }
1951                         for(i=0;i<15;i++){
1952                                 for(j=0;j<consolechars[i];j++){
1953                                         glColor4f(1,1,1,1-(float)(i)/16);
1954                                         if(j<consolechars[i]){
1955                                                 sprintf (string, "%c",consoletext[i][j]);
1956                                                 text.glPrint(30+j*10-offset*10,30+i*20,string,0,1,1024,768);
1957                                         }
1958                                 }
1959                         }
1960                 }
1961         }
1962
1963         if(freeze||winfreeze||(mainmenu&&gameon)||(!gameon&&gamestarted)){
1964                 multiplier=tempmult;
1965         }
1966
1967         if(mainmenu){
1968                 DrawMenu();
1969         }
1970
1971         if(freeze||winfreeze||(mainmenu&&gameon)||(!gameon&&gamestarted)){
1972                 tempmult=multiplier;
1973                 multiplier=0;
1974         }
1975
1976         //glFlush();
1977         if ( side == stereoRight || side == stereoCenter ) {
1978                 if(drawmode!=motionblurmode||mainmenu){
1979                         swap_gl_buffers();
1980                 }
1981         }
1982
1983         //myassert(glGetError() == GL_NO_ERROR);
1984         glDrawBuffer(GL_BACK);
1985         glReadBuffer(GL_BACK);
1986         //glFlush();
1987
1988         weapons.DoStuff();
1989
1990         if(drawtoggle==2)drawtoggle=0;
1991
1992         if(freeze||winfreeze||(mainmenu&&gameon)||(!gameon&&gamestarted)){
1993                 multiplier=tempmult;
1994         }
1995         //Jordan fixed your warning!
1996         return 0;
1997 }
1998
1999 void Game::LoadCampaign() {
2000         ifstream ipstream(ConvertFileName(":Data:Campaigns:main.txt"));
2001         ipstream.ignore(256,':');
2002         ipstream >> campaignnumlevels;
2003         for(int i=0;i<campaignnumlevels;i++){
2004                 ipstream.ignore(256,':');
2005                 ipstream.ignore(256,':');
2006                 ipstream.ignore(256,' ');
2007                 ipstream >> campaignmapname[i];
2008                 ipstream.ignore(256,':');
2009                 ipstream >> campaigndescription[i];
2010                 for(int j=0;j<256;j++){
2011                         if(campaigndescription[i][j]=='_')campaigndescription[i][j]=' ';
2012                 }
2013                 ipstream.ignore(256,':');
2014                 ipstream >> campaignchoosenext[i];
2015                 ipstream.ignore(256,':');
2016                 ipstream >> campaignnumnext[i];
2017                 for(int j=0;j<campaignnumnext[i];j++){
2018                         ipstream.ignore(256,':');
2019                         ipstream >> campaignnextlevel[i][j];
2020                         campaignnextlevel[i][j]-=1;
2021                 }
2022                 ipstream.ignore(256,':');
2023                 ipstream >> campaignlocationx[i];
2024                 ipstream.ignore(256,':');
2025                 ipstream >> campaignlocationy[i];
2026         }
2027         ipstream.close();
2028
2029         for(int i=0;i<campaignnumlevels;i++){
2030                 levelvisible[i]=0;
2031                 levelhighlight[i]=0;
2032         }
2033
2034         levelorder[0]=0;
2035         levelvisible[0]=1;
2036         for(int i=0;i<accountactive->getCampaignChoicesMade();i++){
2037                 levelorder[i+1]=campaignnextlevel[levelorder[i]][accountactive->getCampaignChoice(i)];
2038                 levelvisible[levelorder[i+1]]=1;
2039         }
2040         int whichlevelstart = (accountactive?accountactive->getCampaignChoicesMade():0)-1;
2041         if(whichlevelstart<0){
2042                 if(accountactive) {
2043                         accountactive->setCampaignScore(0);
2044                         accountactive->resetFasttime();
2045                 }
2046                 campaignchoicenum=1;
2047                 campaignchoicewhich[0]=0;
2048         }
2049         else
2050         {
2051                 campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
2052                 for(int i=0;i<campaignchoicenum;i++){
2053                         campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
2054                         levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
2055                         levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
2056                 }
2057         }
2058 }
2059
2060 void Game::DrawMenu()
2061 {
2062         int i,j;
2063         static float lastcheck;
2064
2065         lastcheck+=multiplier;
2066         
2067         // !!! FIXME: hack: clamp framerate in menu so text input works correctly on fast systems.
2068         SDL_Delay(15);
2069
2070         glDrawBuffer(GL_BACK);
2071         glReadBuffer(GL_BACK);
2072         glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
2073         ReSizeGLScene(90,.1f);
2074
2075         int temptexdetail;
2076         temptexdetail=texdetail;
2077         if(texdetail>2)texdetail=2;
2078         if(mainmenu!=oldmainmenu&&oldmainmenu!=0){
2079                 if(mainmenu==1){
2080                         LoadTexture(":Data:Textures:Newgame.png",&Mainmenuitems[1],0,0);
2081                         LoadTexture(":Data:Textures:Quit.png",&Mainmenuitems[3],0,0);
2082                 }
2083                 if(mainmenu==2){
2084                         LoadTexture(":Data:Textures:Resume.png",&Mainmenuitems[1],0,0);
2085                         LoadTexture(":Data:Textures:Endgame.png",&Mainmenuitems[3],0,0);
2086                 }
2087         }
2088         if(lastcheck>.5||oldmainmenu!=mainmenu){
2089                 if(mainmenu==5){
2090                         LoadCampaign();
2091                 }
2092         }
2093         if(mainmenu==5){
2094                 lastcheck=0;
2095         }
2096
2097         texdetail=temptexdetail;
2098
2099         oldmainmenu=mainmenu;
2100
2101         if(mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==8||mainmenu==9||mainmenu==10||mainmenu==119||mainmenu==18){
2102                 glClear(GL_DEPTH_BUFFER_BIT);
2103                 glEnable(GL_ALPHA_TEST);
2104                 glAlphaFunc(GL_GREATER, 0.001f);
2105                 glEnable(GL_TEXTURE_2D);
2106                 glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
2107                 glDisable(GL_CULL_FACE);
2108                 glDisable(GL_LIGHTING);
2109                 glDepthMask(0);
2110                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
2111                 glPushMatrix();                                                                         // Store The Projection Matrix
2112                         glLoadIdentity();                                                                       // Reset The Projection Matrix
2113                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
2114                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
2115                                 glPushMatrix();                                                                         // Store The Modelview Matrix
2116                                 glLoadIdentity();                                                               // Reset The Modelview Matrix
2117                                 glTranslatef(screenwidth/2,screenheight/2,0);
2118                                 glPushMatrix();
2119                                         glScalef((float)screenwidth/2,(float)screenheight/2,1);
2120                                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
2121                                         glDisable(GL_BLEND);
2122                                         glColor4f(0,0,0,1.0);
2123                                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
2124                                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
2125                                         glDisable(GL_TEXTURE_2D);
2126                                         glPushMatrix();
2127                                                 //glScalef(.25,.25,.25);
2128                                                 glBegin(GL_QUADS);
2129                                                 glTexCoord2f(0,0);
2130                                                 glVertex3f(-1,          -1,      0.0f);
2131                                                 glTexCoord2f(1,0);
2132                                                 glVertex3f(1,   -1,      0.0f);
2133                                                 glTexCoord2f(1,1);
2134                                                 glVertex3f(1,   1, 0.0f);
2135                                                 glTexCoord2f(0,1);
2136                                                 glVertex3f(-1,  1, 0.0f);
2137                                                 glEnd();
2138                                         glPopMatrix();
2139                                         glEnable(GL_BLEND);
2140                                         glColor4f(0.4,0.4,0.4,1.0);
2141                                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
2142                                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
2143                                         glEnable(GL_TEXTURE_2D);
2144                                         glBindTexture( GL_TEXTURE_2D, Mainmenuitems[4]);
2145                                         glPushMatrix();
2146                                                 //glScalef(.25,.25,.25);
2147                                                 glBegin(GL_QUADS);
2148                                                 glTexCoord2f(0,0);
2149                                                 glVertex3f(-1,          -1,      0.0f);
2150                                                 glTexCoord2f(1,0);
2151                                                 glVertex3f(1,   -1,      0.0f);
2152                                                 glTexCoord2f(1,1);
2153                                                 glVertex3f(1,   1, 0.0f);
2154                                                 glTexCoord2f(0,1);
2155                                                 glVertex3f(-1,  1, 0.0f);
2156                                                 glEnd();
2157                                         glPopMatrix();
2158                                 glPopMatrix();
2159                         glPopMatrix();
2160                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
2161                 glPopMatrix();
2162                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
2163
2164                 if(mainmenu==3){
2165                         nummenuitems=14;
2166                         if((float)newscreenwidth>(float)newscreenheight*1.61||(float)newscreenwidth<(float)newscreenheight*1.59)sprintf (menustring[0], "Resolution: %d*%d",(int)newscreenwidth,(int)newscreenheight);
2167                         else sprintf (menustring[0], "Resolution: %d*%d (widescreen)",(int)newscreenwidth,(int)newscreenheight);
2168                         startx[0]=10+20;
2169                         starty[0]=440;
2170                         endx[0]=startx[0]+strlen(menustring[0])*10;
2171                         endy[0]=starty[0]+20;
2172
2173                         if(newdetail==2)sprintf (menustring[1], "Detail: High");
2174                         else if(newdetail==1)sprintf (menustring[1], "Detail: Medium");
2175                         else sprintf (menustring[1], "Detail: Low");
2176                         startx[1]=10+60;
2177                         starty[1]=405;
2178                         endx[1]=startx[1]+strlen(menustring[1])*10;
2179                         endy[1]=starty[1]+20;
2180
2181                         if(bloodtoggle==2)sprintf (menustring[2], "Blood: On, high detail (slower)");
2182                         if(bloodtoggle==1)sprintf (menustring[2], "Blood: On, low detail");
2183                         if(bloodtoggle==0)sprintf (menustring[2], "Blood: Off");
2184                         startx[2]=10+70;
2185                         starty[2]=370;
2186                         endx[2]=startx[2]+strlen(menustring[2])*10;
2187                         endy[2]=starty[2]+20;
2188
2189                         if(difficulty==2)sprintf (menustring[3], "Difficulty: Insane");
2190                         if(difficulty==1)sprintf (menustring[3], "Difficulty: Difficult");
2191                         if(difficulty==0)sprintf (menustring[3], "Difficulty: Easier");
2192                         startx[3]=10+20-1000;
2193                         starty[3]=335-1000;
2194                         endx[3]=startx[3]+strlen(menustring[3])*10;
2195                         endy[3]=starty[3]+20;
2196
2197                         if(ismotionblur==1)sprintf (menustring[4], "Blur Effects: Enabled (less compatible)");
2198                         if(ismotionblur==0)sprintf (menustring[4], "Blur Effects: Disabled (more compatible)");
2199                         startx[4]=10;
2200                         starty[4]=335;
2201                         endx[4]=startx[4]+strlen(menustring[4])*10;
2202                         endy[4]=starty[4]+20;
2203
2204                         if(decals==1)sprintf (menustring[5], "Decals: Enabled (slower)");
2205                         if(decals==0)sprintf (menustring[5], "Decals: Disabled");
2206                         startx[5]=10+60;
2207                         starty[5]=300;
2208                         endx[5]=startx[5]+strlen(menustring[5])*10;
2209                         endy[5]=starty[5]+20;
2210
2211                         if(musictoggle==1)sprintf (menustring[6], "Music: Enabled");
2212                         if(musictoggle==0)sprintf (menustring[6], "Music: Disabled");
2213                         startx[6]=10+70;
2214                         starty[6]=265;
2215                         endx[6]=startx[6]+strlen(menustring[6])*10;
2216                         endy[6]=starty[6]+20;
2217
2218                         if(invertmouse==1)sprintf (menustring[9], "Invert mouse: Yes");
2219                         if(invertmouse==0)sprintf (menustring[9], "Invert mouse: No");
2220                         startx[9]=10;
2221                         starty[9]=230;
2222                         endx[9]=startx[9]+strlen(menustring[9])*10;
2223                         endy[9]=starty[9]+20;
2224
2225                         sprintf (menustring[10], "Mouse Speed: %d", (int)(usermousesensitivity*5));
2226                         startx[10]=20;
2227                         starty[10]=195;
2228                         endx[10]=startx[10]+strlen(menustring[10])*10;
2229                         endy[10]=starty[10]+20;
2230                         
2231                         sprintf (menustring[11], "Volume: %d%%", (int)(volume*100));
2232                         startx[11]=10+60;
2233                         starty[11]=160;
2234                         endx[11]=startx[11]+strlen(menustring[11])*10;
2235                         endy[11]=starty[11]+20;
2236                         
2237                         sprintf (menustring[13], "Damage Bar: %s",(showdamagebar?"on":"off"));
2238                         startx[13]=30;
2239                         starty[13]=125;
2240                         endx[13]=startx[13]+strlen(menustring[13])*10;
2241                         endy[13]=starty[13]+20;
2242                         
2243                         sprintf (menustring[7], "-Configure Controls-");
2244                         startx[7]=10+15;
2245                         starty[7]=90;
2246                         endx[7]=startx[7]+strlen(menustring[7])*10;
2247                         endy[7]=starty[7]+20;
2248
2249                         sprintf (menustring[12], "-Configure Stereo -");
2250                         startx[12]=10+15;
2251                         starty[12]=55;
2252                         endx[12]=startx[12]+strlen(menustring[7])*10;
2253                         endy[12]=starty[12]+20;
2254                         
2255                         if(newdetail==detail&&newscreenheight==(int)screenheight&&newscreenwidth==(int)screenwidth)sprintf (menustring[8], "Back");
2256                         else sprintf (menustring[8], "Back (some changes take effect next time Lugaru is opened)");
2257                         startx[8]=10;
2258                         endx[8]=startx[8]+strlen(menustring[8])*10;
2259                         starty[8]=10;
2260                         endy[8]=starty[8]+20;
2261                 }
2262
2263                 if(mainmenu==4){                        
2264                         nummenuitems=10;
2265                         if(keyselect!=0)sprintf (menustring[0], "Forwards: %s",Input::keyToChar(forwardkey));
2266                         else sprintf (menustring[0], "Forwards: _");
2267                         startx[0]=10;
2268                         starty[0]=400;
2269                         endx[0]=startx[0]+strlen(menustring[0])*10;
2270                         endy[0]=starty[0]+20;
2271
2272                         if(keyselect!=1)sprintf (menustring[1], "Back: %s",Input::keyToChar(backkey));
2273                         else sprintf (menustring[1], "Back: _");
2274                         startx[1]=10+40;
2275                         starty[1]=360;
2276                         endx[1]=startx[1]+strlen(menustring[1])*10;
2277                         endy[1]=starty[1]+20;
2278
2279                         if(keyselect!=2)sprintf (menustring[2], "Left: %s",Input::keyToChar(leftkey));
2280                         else sprintf (menustring[2], "Left: _");
2281                         startx[2]=10+40;
2282                         starty[2]=320;
2283                         endx[2]=startx[2]+strlen(menustring[2])*10;
2284                         endy[2]=starty[2]+20;
2285
2286                         if(keyselect!=3)sprintf (menustring[3], "Right: %s",Input::keyToChar(rightkey));
2287                         else sprintf (menustring[3], "Right: _");
2288                         startx[3]=10+30;
2289                         starty[3]=280;
2290                         endx[3]=startx[3]+strlen(menustring[3])*10;
2291                         endy[3]=starty[3]+20;
2292
2293                         if(keyselect!=4)sprintf (menustring[4], "Crouch: %s",Input::keyToChar(crouchkey));
2294                         else sprintf (menustring[4], "Crouch: _");
2295                         startx[4]=10+20;
2296                         starty[4]=240;
2297                         endx[4]=startx[4]+strlen(menustring[4])*10;
2298                         endy[4]=starty[4]+20;
2299
2300                         if(keyselect!=5)sprintf (menustring[5], "Jump: %s",Input::keyToChar(jumpkey));
2301                         else sprintf (menustring[5], "Jump: _");
2302                         startx[5]=10+40;
2303                         starty[5]=200;
2304                         endx[5]=startx[5]+strlen(menustring[5])*10;
2305                         endy[5]=starty[5]+20;
2306
2307                         if(keyselect!=6)sprintf (menustring[6], "Draw: %s",Input::keyToChar(drawkey));
2308                         else sprintf (menustring[6], "Draw: _");
2309                         startx[6]=10+40;
2310                         starty[6]=160;
2311                         endx[6]=startx[6]+strlen(menustring[6])*10;
2312                         endy[6]=starty[6]+20;
2313
2314                         if(keyselect!=7)sprintf (menustring[7], "Throw: %s",Input::keyToChar(throwkey));
2315                         else sprintf (menustring[7], "Throw: _");
2316                         startx[7]=10+30;
2317                         starty[7]=120;
2318                         endx[7]=startx[7]+strlen(menustring[7])*10;
2319                         endy[7]=starty[7]+20;
2320
2321                         if(keyselect!=8)sprintf (menustring[8], "Attack: %s",Input::keyToChar(attackkey));
2322                         else sprintf (menustring[8], "Attack: _");
2323                         startx[8]=10+20;
2324                         starty[8]=80;
2325                         endx[8]=startx[8]+strlen(menustring[8])*10;
2326                         endy[8]=starty[8]+20;
2327
2328
2329
2330                         sprintf (menustring[9], "Back");
2331                         startx[9]=10;
2332                         endx[9]=startx[9]+strlen(menustring[9])*10;
2333                         starty[9]=10;
2334                         endy[9]=starty[9]+20;
2335                 }
2336                 if(mainmenu==5){                        
2337                         nummenuitems=7+(accountactive?accountactive->getCampaignChoicesMade():0)+campaignchoicenum;
2338
2339                         sprintf (menustring[0], "%s",accountactive->getName());
2340                         startx[0]=5;
2341                         starty[0]=400;
2342                         endx[0]=startx[0]+strlen(menustring[0])*10;
2343                         endy[0]=starty[0]+20;
2344
2345                         sprintf (menustring[1], "Tutorial");
2346                         startx[1]=5;
2347                         starty[1]=300;
2348                         endx[1]=startx[1]+strlen(menustring[1])*10;
2349                         endy[1]=starty[1]+20;
2350
2351                         sprintf (menustring[2], "Challenge");
2352                         startx[2]=5;
2353                         starty[2]=240;
2354                         endx[2]=startx[2]+strlen(menustring[2])*10;
2355                         endy[2]=starty[2]+20;
2356
2357                         sprintf (menustring[3], "Delete User");
2358                         startx[3]=400;
2359                         starty[3]=10;
2360                         endx[3]=startx[3]+strlen(menustring[3])*10;
2361                         endy[3]=starty[3]+20;
2362
2363                         sprintf (menustring[4], "Main Menu");
2364                         startx[4]=5;
2365                         starty[4]=10;
2366                         endx[4]=startx[4]+strlen(menustring[4])*10;
2367                         endy[4]=starty[4]+20;
2368
2369                         sprintf (menustring[5], "Change User");
2370                         startx[5]=5;
2371                         endx[5]=startx[5]+strlen(menustring[5])*10;
2372                         starty[5]=180;
2373                         endy[5]=starty[5]+20;
2374
2375                         //World
2376
2377                         sprintf (menustring[6], "World");
2378                         startx[6]=30+120;
2379                         starty[6]=30+480-400-50;
2380                         endx[6]=startx[6]+400;
2381                         endy[6]=30+480-50;
2382
2383                         if((accountactive?accountactive->getCampaignChoicesMade():0)) {
2384                                 for(i=0;i<(accountactive?accountactive->getCampaignChoicesMade():0);i++) {
2385                                         sprintf (menustring[7+i], "%s", campaigndescription[levelorder[i]]);
2386                                         startx[7+i]=30+120+campaignlocationx[levelorder[i]]*400/512;
2387                                         starty[7+i]=30+30+(512-campaignlocationy[levelorder[i]])*400/512;
2388                                         endx[7+i]=startx[7+i]+10;
2389                                         endy[7+i]=starty[7+i]+10;
2390                                 }
2391                         }
2392
2393                         if(campaignchoicenum>0)
2394                                 for(i=(accountactive?accountactive->getCampaignChoicesMade():0);i<(accountactive?accountactive->getCampaignChoicesMade():0)+campaignchoicenum;i++){
2395                                         sprintf (menustring[7+i], "%s", campaigndescription[levelorder[i]]);
2396                                         startx[7+i]=30+120+campaignlocationx[campaignchoicewhich[i-((accountactive?accountactive->getCampaignChoicesMade():0))]]*400/512;
2397                                         starty[7+i]=30+30+(512-campaignlocationy[campaignchoicewhich[i-((accountactive?accountactive->getCampaignChoicesMade():0))]])*400/512;
2398                                         endx[7+i]=startx[7+i]+10;
2399                                         endy[7+i]=starty[7+i]+10;
2400                                 }
2401                 }
2402
2403                 if(mainmenu==6){                        
2404                         nummenuitems=3;
2405
2406                         sprintf (menustring[0], "Are you sure you want to delete this user?");
2407                         startx[0]=10;
2408                         starty[0]=400;
2409                         endx[0]=startx[0]+strlen(menustring[0])*10;
2410                         endy[0]=starty[0]+20;
2411
2412                         sprintf (menustring[1], "Yes");
2413                         startx[1]=10;
2414                         starty[1]=360;
2415                         endx[1]=startx[1]+strlen(menustring[1])*10;
2416                         endy[1]=starty[1]+20;
2417
2418                         sprintf (menustring[2], "No");
2419                         startx[2]=10;
2420                         starty[2]=320;
2421                         endx[2]=startx[2]+strlen(menustring[2])*10;
2422                         endy[2]=starty[2]+20;
2423
2424                         sprintf (menustring[3], "Extra 4");
2425                         startx[3]=10;
2426                         starty[3]=280;
2427                         endx[3]=startx[3]+strlen(menustring[3])*10;
2428                         endy[3]=starty[3]+20;
2429
2430                         sprintf (menustring[4], "Extra 5");
2431                         startx[4]=10;
2432                         starty[4]=240;
2433                         endx[4]=startx[4]+strlen(menustring[4])*10;
2434                         endy[4]=starty[4]+20;
2435
2436                         sprintf (menustring[5], "Back");
2437                         startx[5]=10;
2438                         endx[5]=startx[5]+strlen(menustring[5])*10;
2439                         starty[5]=10;
2440                         endy[5]=starty[5]+20;
2441                 }
2442
2443                 if(mainmenu==7){        
2444                         nummenuitems=Account::getNbAccounts()+2;
2445
2446                         int num;
2447
2448                         if(Account::getNbAccounts()<8)
2449                                 sprintf (menustring[0], "New User");
2450                         else
2451                                 sprintf (menustring[0], "No More Users");
2452                         startx[0]=10;
2453                         starty[0]=400;
2454                         endx[0]=startx[0]+strlen(menustring[0])*10;
2455                         endy[0]=starty[0]+20;
2456
2457                         if(entername)
2458                                 startx[0]+=10;
2459
2460
2461                         num=1;
2462                         for(i=0;i<Account::getNbAccounts();i++){
2463                                 sprintf (menustring[num], "%s",Account::get(i)->getName());
2464                                 startx[num]=10;
2465                                 starty[num]=360-20-20*num;
2466                                 endx[num]=startx[num]+strlen(menustring[num])*10;
2467                                 endy[num]=starty[num]+20;
2468
2469                                 num++;
2470                         }
2471
2472                         sprintf (menustring[num], "Back");
2473                         startx[num]=10;
2474                         endx[num]=startx[num]+strlen(menustring[num])*10;
2475                         starty[num]=10;
2476                         endy[num]=starty[num]+20;
2477                 }
2478                 if(mainmenu==8){                        
2479                         nummenuitems=3;
2480
2481                         sprintf (menustring[0], "Easier");
2482                         startx[0]=10;
2483                         starty[0]=400;
2484                         endx[0]=startx[0]+strlen(menustring[0])*10;
2485                         endy[0]=starty[0]+20;
2486
2487                         sprintf (menustring[1], "Difficult");
2488                         startx[1]=10;
2489                         starty[1]=360;
2490                         endx[1]=startx[1]+strlen(menustring[1])*10;
2491                         endy[1]=starty[1]+20;
2492
2493                         sprintf (menustring[2], "Insane");
2494                         startx[2]=10;
2495                         starty[2]=320;
2496                         endx[2]=startx[2]+strlen(menustring[2])*10;
2497                         endy[2]=starty[2]+20;
2498                 }
2499                 if(mainmenu==9){                        
2500                         nummenuitems=2+numchallengelevels;
2501                         char temp[255];
2502
2503                         for(j=0;j<numchallengelevels;j++){
2504                                 for(i=0;i<255;i++)menustring[j][i]='\0';
2505                                 sprintf (temp, "Level %d",j+1);
2506                                 strcpy(menustring[j],temp);
2507                                 for(i=0;i<17;i++)if(menustring[j][i]=='\0')menustring[j][i]=' ';
2508                                 menustring[j][17]='\0';
2509                                 sprintf (temp, "%d",(int)accountactive->getHighScore(j));
2510                                 strcat(menustring[j],temp);
2511                                 for(i=18;i<32;i++)if(menustring[j][i]=='\0')menustring[j][i]=' ';
2512                                 menustring[j][32]='\0';
2513                                 sprintf (temp, "%d:",(int)(((int)accountactive->getFastTime(j)-(int)(accountactive->getFastTime(j))%60)/60));
2514                                 strcat(menustring[j],temp);
2515                                 if((int)(accountactive->getFastTime(j))%60<10)strcat(menustring[j],"0");
2516                                 sprintf (temp, "%d",(int)(accountactive->getFastTime(j))%60);
2517                                 strcat(menustring[j],temp);
2518
2519                                 startx[j]=10;
2520                                 starty[j]=400-j*25;
2521                                 endx[j]=startx[j]+strlen(menustring[j])*10;
2522                                 endy[j]=starty[j]+20;
2523                         }
2524
2525                         sprintf (menustring[numchallengelevels], "Back");
2526                         startx[numchallengelevels]=10;
2527                         endx[numchallengelevels]=startx[numchallengelevels]+strlen(menustring[numchallengelevels])*10;
2528                         starty[numchallengelevels]=10;
2529                         endy[numchallengelevels]=starty[numchallengelevels]+20;
2530
2531                         sprintf (menustring[numchallengelevels+1], "             High Score      Best Time");
2532                         startx[numchallengelevels+1]=10;
2533                         starty[numchallengelevels+1]=440;
2534                         endx[numchallengelevels+1]=startx[numchallengelevels+1]+strlen(menustring[numchallengelevels+1])*10;
2535                         endy[numchallengelevels+1]=starty[numchallengelevels+1]+20;
2536
2537                         //numchallengelevels=tempncl;
2538
2539                 }
2540                 if(mainmenu==10){                       
2541                         nummenuitems=6;
2542                         char temp[255];
2543
2544                         sprintf (menustring[0], "Congratulations!");
2545                         startx[0]=220;
2546                         starty[0]=330;
2547                         endx[0]=startx[0]+strlen(menustring[0])*10;
2548                         endy[0]=starty[0]+20;
2549
2550                         sprintf (menustring[1], "You have avenged your family and");
2551                         startx[1]=140;
2552                         starty[1]=300;
2553                         endx[1]=startx[1]+strlen(menustring[1])*10;
2554                         endy[1]=starty[1]+20;
2555
2556                         sprintf (menustring[2], "restored peace to the island of Lugaru.");
2557                         startx[2]=110;
2558                         starty[2]=270;
2559                         endx[2]=startx[2]+strlen(menustring[2])*10;
2560                         endy[2]=starty[2]+20;
2561
2562                         sprintf (menustring[3], "Back");
2563                         startx[3]=10;
2564                         endx[3]=startx[3]+strlen(menustring[3])*10;
2565                         starty[3]=10;
2566                         endy[3]=starty[3]+20;
2567
2568                         for(i=0;i<255;i++)menustring[4][i]='\0';
2569                         sprintf (temp, "Your score:");
2570                         strcpy(menustring[4],temp);
2571                         for(i=0;i<20;i++)if(menustring[4][i]=='\0')menustring[4][i]=' ';
2572                         menustring[4][20]='\0';
2573                         sprintf (temp, "%d",(int)accountactive->getCampaignScore());
2574                         strcat(menustring[4],temp);
2575                         startx[4]=190;
2576                         endx[4]=startx[4]+strlen(menustring[4])*10;
2577                         starty[4]=200;
2578                         endy[4]=starty[4]+20;
2579                         for(i=0;i<255;i++)menustring[5][i]='\0';
2580                         sprintf (temp, "Highest score:");
2581                         strcpy(menustring[5],temp);
2582                         for(i=0;i<20;i++)if(menustring[5][i]=='\0')menustring[5][i]=' ';
2583                         menustring[5][20]='\0';
2584                         sprintf (temp, "%d",(int)accountactive->getCampaignHighScore());
2585                         strcat(menustring[5],temp);
2586                         startx[5]=190;
2587                         endx[5]=startx[5]+strlen(menustring[5])*10;
2588                         starty[5]=180;
2589                         endy[5]=starty[5]+20;
2590                 }
2591                 if (mainmenu==18) {
2592                         nummenuitems=4;
2593                         sprintf (menustring[0], "Stereo mode: %s", StereoModeName(newstereomode));
2594                         startx[0]=70;
2595                         starty[0]=400;
2596                         endx[0]=startx[0]+strlen(menustring[0])*10;
2597                         endy[0]=starty[0]+20;
2598                         
2599                         sprintf (menustring[1], "Stereo separation: %.3f", stereoseparation);
2600                         startx[1]=10;
2601                         starty[1]=360;
2602                         endx[1]=startx[1]+strlen(menustring[1])*10;
2603                         endy[1]=starty[1]+20;
2604
2605                         sprintf (menustring[2], "Reverse stereo: %s", stereoreverse ? "Yes" : "No");
2606                         startx[2]=40;
2607                         starty[2]=320;
2608                         endx[2]=startx[2]+strlen(menustring[2])*10;
2609                         endy[2]=starty[2]+20;
2610                         
2611                         sprintf (menustring[3], "Back");
2612                         startx[3]=10;
2613                         endx[3]=startx[3]+strlen(menustring[3])*10;
2614                         starty[3]=10;
2615                         endy[3]=starty[3]+20;
2616                 }
2617         }
2618
2619         if(mainmenu==1||mainmenu==2){
2620                 nummenuitems=7;
2621                 startx[0]=150;
2622                 starty[0]=480-128;
2623                 endx[0]=150+256;
2624                 endy[0]=480;
2625
2626                 startx[1]=18;
2627                 starty[1]=480-152-32;
2628                 endx[1]=18+128;
2629                 endy[1]=480-152;
2630
2631                 startx[2]=18;
2632                 starty[2]=480-228-32;
2633                 endx[2]=2+128;
2634                 endy[2]=480-228;
2635
2636                 if(mainmenu==1){
2637                         startx[3]=18;
2638                         starty[3]=480-306-32;
2639                         endx[3]=22+64;
2640                         endy[3]=480-306;
2641                 }
2642
2643                 if(mainmenu==2){
2644                         startx[3]=18;
2645                         starty[3]=480-306-32;
2646                         endx[3]=22+128;
2647                         endy[3]=480-306;
2648                 }
2649
2650                 /*startx[4]=150;
2651                 starty[4]=480-256;
2652                 endx[4]=150+256;
2653                 endy[4]=480;
2654                 */
2655                 /*if(anim==0){
2656                         startx[4]=380;
2657                         starty[4]=480-140-256;
2658                         endx[4]=380+256;
2659                         endy[4]=480-140;
2660
2661                         startx[5]=145;
2662                         starty[5]=480-138-256;
2663                         endx[5]=145+256;
2664                         endy[5]=480-138;
2665
2666                         startx[6]=254;
2667                         starty[6]=480-144-256;
2668                         endx[6]=254+256;
2669                         endy[6]=480-144;
2670                 }*/
2671         }
2672
2673         selected=-1;
2674
2675         if(mainmenu==1||mainmenu==2)
2676                 for(i=1;i<4;i++){
2677                         if((mousecoordh/screenwidth*640)>startx[i]&&(mousecoordh/screenwidth*640)<endx[i]&&480-(mousecoordv/screenheight*480)>starty[i]&&480-(mousecoordv/screenheight*480)<endy[i]){
2678                                 selected=i;
2679                         }
2680                 }
2681
2682         if(mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==8||mainmenu==9||mainmenu==10||mainmenu==18)
2683                 for(i=0;i<nummenuitems;i++){
2684                         if((mousecoordh/screenwidth*640)>startx[i]&&(mousecoordh/screenwidth*640)<endx[i]&&480-(mousecoordv/screenheight*480)>starty[i]&&480-(mousecoordv/screenheight*480)<endy[i]){
2685                                 if(mainmenu!=5)selected=i;
2686                                 if(mainmenu==5&&(i!=0&&i!=6))selected=i;
2687                                 if(mainmenu==9&&(i!=numchallengelevels+1))selected=i; // seem useless, if mainmenu==9 then mainmenu!=5, so selected==i.
2688                         }
2689                 }
2690
2691         for(i=0;i<nummenuitems;i++){
2692                 if(selected==i) {
2693                         selectedlong[i]+=multiplier*5;
2694                         if(selectedlong[i]>1) selectedlong[i]=1;
2695                 } else {
2696                         selectedlong[i]-=multiplier*5;
2697                         if(selectedlong[i]<0) selectedlong[i]=0;        
2698                 }
2699                 offsetx[i]=(startx[i]+endx[i])/2-(mousecoordh/screenwidth*640);
2700                 offsety[i]=(starty[i]+endy[i])/2-(480-(mousecoordv/screenheight*480));
2701                 offsetx[i]*=.06f;
2702                 offsety[i]*=.06f;
2703                 offsetx[i]=0;
2704                 offsety[i]=0;
2705                 if(i>=4&&(mainmenu==1||mainmenu==2)){
2706                         selectedlong[i]=0;
2707                         offsetx[i]=(startx[i]+endx[i])/2-(640+190)/2;
2708                         offsety[i]=(starty[i]+endy[i])/2-(336+150)/2;
2709                         offsetx[i]*=.06f;
2710                         offsety[i]*=.06f;
2711                 }
2712         }
2713
2714         if(mainmenu==1||mainmenu==2){
2715                 glClear(GL_DEPTH_BUFFER_BIT);
2716                 glEnable(GL_ALPHA_TEST);
2717                 glAlphaFunc(GL_GREATER, 0.001f);
2718                 glEnable(GL_TEXTURE_2D);
2719                 glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
2720                 glDisable(GL_CULL_FACE);
2721                 glDisable(GL_LIGHTING);
2722                 glDepthMask(0);
2723                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
2724                 glPushMatrix();                                                                         // Store The Projection Matrix
2725                         glLoadIdentity();                                                                       // Reset The Projection Matrix
2726                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
2727                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
2728                         glPushMatrix();                                                                         // Store The Modelview Matrix
2729                                 glLoadIdentity();                                                               // Reset The Modelview Matrix
2730                                 glTranslatef(screenwidth/2,screenheight/2,0);
2731                                 glPushMatrix();
2732                                         glScalef((float)screenwidth/2,(float)screenheight/2,1);
2733                                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
2734                                         glDisable(GL_BLEND);
2735                                         glColor4f(0,0,0,1.0);
2736                                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
2737                                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
2738                                         glDisable(GL_TEXTURE_2D);
2739                                         glPushMatrix();
2740                                                 //glScalef(.25,.25,.25);
2741                                                 glBegin(GL_QUADS);
2742                                                 glTexCoord2f(0,0);
2743                                                 glVertex3f(-1,          -1,      0.0f);
2744                                                 glTexCoord2f(1,0);
2745                                                 glVertex3f(1,   -1,      0.0f);
2746                                                 glTexCoord2f(1,1);
2747                                                 glVertex3f(1,   1, 0.0f);
2748                                                 glTexCoord2f(0,1);
2749                                                 glVertex3f(-1,  1, 0.0f);
2750                                                 glEnd();
2751                                         glPopMatrix();
2752                                         glEnable(GL_BLEND);
2753                                         glColor4f(0.4,0.4,0.4,1.0);
2754                                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
2755                                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
2756                                         glEnable(GL_TEXTURE_2D);
2757                                         glBindTexture( GL_TEXTURE_2D, Mainmenuitems[4]);
2758                                         glPushMatrix();
2759                                                 //glScalef(.25,.25,.25);
2760                                                 glBegin(GL_QUADS);
2761                                                 glTexCoord2f(0,0);
2762                                                 glVertex3f(-1,          -1,      0.0f);
2763                                                 glTexCoord2f(1,0);
2764                                                 glVertex3f(1,   -1,      0.0f);
2765                                                 glTexCoord2f(1,1);
2766                                                 glVertex3f(1,   1, 0.0f);
2767                                                 glTexCoord2f(0,1);
2768                                                 glVertex3f(-1,  1, 0.0f);
2769                                                 glEnd();
2770                                         glPopMatrix();
2771                                 glPopMatrix();
2772                         glPopMatrix();
2773                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
2774                 glPopMatrix();
2775
2776                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
2777                 glPushMatrix();                                                                         // Store The Projection Matrix
2778                         glLoadIdentity();                                                                       // Reset The Projection Matrix
2779                         glOrtho(0,640,0,480,-100,100);                                          // Set Up An Ortho Screen
2780                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
2781                         glPushMatrix();                                                                         // Store The Modelview Matrix
2782                                 glLoadIdentity();                                                               // Reset The Modelview Matrix
2783                                 glPushMatrix();
2784                                         glDisable(GL_TEXTURE_2D);
2785                                         glColor4f(1,0,0,1);
2786                                 glPopMatrix();
2787                         glPopMatrix();
2788                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
2789                 glPopMatrix();
2790                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
2791
2792         }
2793
2794         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
2795         glPushMatrix();                                                                         // Store The Projection Matrix
2796         glLoadIdentity();                                                                       // Reset The Projection Matrix
2797         glOrtho(0,640,0,480,-100,100);                                          // Set Up An Ortho Screen
2798         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
2799         glPushMatrix();                                                                         // Store The Modelview Matrix
2800         glLoadIdentity();                                                               // Reset The Modelview Matrix
2801         glEnable(GL_TEXTURE_2D);
2802         for(j=0;j<nummenuitems;j++)
2803         {
2804                 if(j>3 && (mainmenu==1||mainmenu==2))
2805                         continue;
2806                 //glDisable(GL_BLEND);
2807                 glEnable(GL_ALPHA_TEST);
2808                 glEnable(GL_BLEND);
2809                 //glDisable(GL_ALPHA_TEST);
2810                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
2811                 if(mainmenu==1||mainmenu==2)
2812                 {
2813                         glColor4f(1,1,1,1);
2814                         glBlendFunc(GL_SRC_ALPHA,GL_ONE);
2815                         glBindTexture( GL_TEXTURE_2D, Mainmenuitems[j]);
2816                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
2817                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
2818                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
2819                         glPushMatrix();
2820                                 glBegin(GL_QUADS);
2821                                 glTexCoord2f(0,0);
2822                                 glVertex3f(startx[j],   starty[j],       0.0f);
2823                                 glTexCoord2f(1,0);
2824                                 glVertex3f(endx[j],             starty[j],       0.0f);
2825                                 glTexCoord2f(1,1);
2826                                 glVertex3f(endx[j],             endy[j], 0.0f);
2827                                 glTexCoord2f(0,1);
2828                                 glVertex3f(startx[j],   endy[j], 0.0f);
2829                                 glEnd();
2830                         glPopMatrix();
2831                         glEnable(GL_BLEND);
2832                         //glDisable(GL_ALPHA_TEST);
2833                         if(j<4)glBlendFunc(GL_SRC_ALPHA,GL_ONE);
2834                         for(i=0;i<10;i++)
2835                         {
2836                                 if(1-((float)i)/10-(1-selectedlong[j])>0)
2837                                 {
2838                                         glColor4f(1,1,1,(1-((float)i)/10-(1-selectedlong[j]))*.25);
2839                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
2840                                         glPushMatrix();
2841                                                 glBegin(GL_QUADS);
2842                                                 glTexCoord2f(0,0);
2843                                                 glVertex3f(startx[j]-((float)i)*1/2+offsetx[j]*((float)i)/2,    starty[j]-((float)i)*1/2+offsety[j]*((float)i)/2,        0.0f);
2844                                                 glTexCoord2f(1,0);
2845                                                 glVertex3f(endx[j]+((float)i)*1/2+offsetx[j]*((float)i)/2,      starty[j]-((float)i)*1/2+offsety[j]*((float)i)/2,        0.0f);
2846                                                 glTexCoord2f(1,1);
2847                                                 glVertex3f(endx[j]+((float)i)*1/2+offsetx[j]*((float)i)/2,      endy[j]+((float)i)*1/2+offsety[j]*((float)i)/2, 0.0f);
2848                                                 glTexCoord2f(0,1);
2849                                                 glVertex3f(startx[j]-((float)i)*1/2+offsetx[j]*((float)i)/2, endy[j]+((float)i)*1/2+offsety[j]*((float)i)/2, 0.0f);
2850                                                 glEnd();
2851                                         glPopMatrix();
2852                                 }
2853                         }
2854                 }
2855                 if(mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==8||mainmenu==9||mainmenu==10||mainmenu==18)
2856                 {
2857                         if(mainmenu!=5||j<6)
2858                         {
2859                                 glColor4f(1,0,0,1);
2860                                 if( (mainmenu==9) && j>accountactive->getProgress() && (j<numchallengelevels) )
2861                                         glColor4f(0.5,0,0,1);
2862                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
2863                                 glPushMatrix();
2864                                         if(mainmenu!=7||j!=0||!entername)
2865                                                 text.glPrint(startx[j],starty[j],menustring[j],0,1,640,480);
2866                                         else
2867                                         {
2868                                                 char string[2]="_";
2869                                                 if(displayblink) {
2870                                                         //~ sprintf (string, "_");
2871                                                         text.glPrint(startx[j]+(float)(displayselected)*10,starty[j],string,0,1,640,480);
2872                                                 }
2873                                                 for(int l=0;l<displaychars[0];l++) {
2874                                                         sprintf (string, "%c",displaytext[0][l]);
2875                                                         text.glPrint(startx[j]+l*10,starty[j],string,0,1,640,480);
2876                                                 }
2877                                         }
2878                                 glPopMatrix();
2879                                 glEnable(GL_BLEND);
2880                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
2881                                 for(i=0;i<15;i++)
2882                                 {
2883                                         if(1-((float)i)/15-(1-selectedlong[j])>0)
2884                                         {
2885                                                 glColor4f(1,0,0,(1-((float)i)/10-(1-selectedlong[j]))*.25);
2886                                                 if(mainmenu==9&&j>accountactive->getProgress()&&j<numchallengelevels)glColor4f(0.5,0,0,(1-((float)i)/10-(1-selectedlong[j]))*.25);
2887                                                 if(mainmenu==11&&j>accountactive->getProgress()&&j<numchallengelevels)glColor4f(0.5,0,0,(1-((float)i)/10-(1-selectedlong[j]))*.25);
2888                                                 if(mainmenu==3)text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4-((/*1*/+((float)i)/70)*strlen(menustring[j]))*3,starty[j]+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
2889                                                 if(mainmenu==4)text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4,starty[j]+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
2890                                                 if(mainmenu==5)text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4,starty[j]+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
2891                                                 if(mainmenu==6)text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4,starty[j]+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
2892                                                 if(mainmenu==7&&(j!=0||!entername)) text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4,starty[j]+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
2893                                                 if(mainmenu==8)text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4,starty[j]+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
2894                                                 if(mainmenu==9)text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4,starty[j]+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
2895                                                 if(mainmenu==10)text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4,starty[j]+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
2896                                                 if(mainmenu==18)text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4,starty[j]+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
2897                                         }
2898                                 }
2899                         }
2900                         else
2901                         {
2902                                 glClear(GL_DEPTH_BUFFER_BIT);
2903                                 glEnable(GL_ALPHA_TEST);
2904                                 glAlphaFunc(GL_GREATER, 0.001f);
2905                                 glEnable(GL_TEXTURE_2D);
2906                                 glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
2907                                 glDisable(GL_CULL_FACE);
2908                                 glDisable(GL_LIGHTING);
2909                                 if(j==6)glColor4f(1,1,1,1);
2910                                 else glColor4f(1,0,0,1);
2911
2912                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
2913                                 glPushMatrix();                                                                         // Store The Projection Matrix
2914                                         glLoadIdentity();                                                                       // Reset The Projection Matrix
2915                                         glOrtho(0,640,0,480,-100,100);                                          // Set Up An Ortho Screen
2916                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
2917                                         glPushMatrix();                                                                         // Store The Modelview Matrix
2918                                                 glLoadIdentity();                                                               // Reset The Modelview Matrix
2919                                                 glPushMatrix();
2920
2921                                                         //Draw world, draw map
2922                                                         glTranslatef(2,-5,0);
2923
2924                                                         if(j>6&&j<nummenuitems-1)
2925                                                         {
2926                                                                 XYZ linestart,lineend,offset;
2927                                                                 XYZ fac;
2928                                                                 float startsize;
2929                                                                 float endsize;
2930                                                                 linestart=0;
2931                                                                 lineend=0;
2932                                                                 offset=0;
2933                                                                 //float linestartx,lineendx,linestarty,lineendy,offsetx,offsety;
2934                                                                 linestart.x=(startx[j]+endx[j])/2;
2935                                                                 linestart.y=(starty[j]+endy[j])/2;
2936                                                                 if(j>=6+(accountactive?accountactive->getCampaignChoicesMade():0)){
2937                                                                         linestart.x=(startx[6+(accountactive?accountactive->getCampaignChoicesMade():0)]+endx[6+(accountactive?accountactive->getCampaignChoicesMade():0)])/2;
2938                                                                         linestart.y=(starty[6+(accountactive?accountactive->getCampaignChoicesMade():0)]+endy[6+(accountactive?accountactive->getCampaignChoicesMade():0)])/2;
2939                                                                 }
2940                                                                 lineend.x=(startx[j+1]+endx[j+1])/2;
2941                                                                 lineend.y=(starty[j+1]+endy[j+1])/2;
2942                                                                 offset=lineend-linestart;
2943                                                                 fac=offset;
2944                                                                 Normalise(&fac);
2945                                                                 offset=DoRotation(offset,0,0,90);
2946                                                                 Normalise(&offset);
2947                                                                 glDisable(GL_TEXTURE_2D);                                                       
2948
2949                                                                 if(j<6+(accountactive?accountactive->getCampaignChoicesMade():0)){
2950                                                                         glColor4f(0.5,0,0,1);
2951                                                                         endsize=.5;
2952                                                                 } else {
2953                                                                         glColor4f(1,0,0,1);
2954                                                                         endsize=1;
2955                                                                 }
2956                                                                 startsize=.5;
2957
2958                                                                 linestart+=fac*4*startsize;
2959                                                                 lineend-=fac*4*endsize;
2960
2961                                                                 if(!(j>7+(accountactive?accountactive->getCampaignChoicesMade():0)+campaignchoicenum)){
2962                                                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
2963                                                                         glPushMatrix();
2964                                                                                 glBegin(GL_QUADS);
2965                                                                                 glTexCoord2f(0,0);
2966                                                                                 glVertex3f(linestart.x-offset.x*startsize,      linestart.y-offset.y*startsize,          0.0f);
2967                                                                                 glTexCoord2f(1,0);
2968                                                                                 glVertex3f(linestart.x+offset.x*startsize,      linestart.y+offset.y*startsize,          0.0f);
2969                                                                                 glTexCoord2f(1,1);
2970                                                                                 glVertex3f(lineend.x+offset.x*endsize,          lineend.y+offset.y*endsize, 0.0f);
2971                                                                                 glTexCoord2f(0,1);
2972                                                                                 glVertex3f(lineend.x-offset.x*endsize,          lineend.y-offset.y*endsize, 0.0f);
2973                                                                                 glEnd();
2974                                                                         glPopMatrix();
2975                                                                 }
2976                                                                 glEnable(GL_TEXTURE_2D);
2977                                                         }
2978
2979
2980                                                         if(j==6)glBindTexture( GL_TEXTURE_2D, Mainmenuitems[7]);
2981                                                         else glBindTexture( GL_TEXTURE_2D, Mapcircletexture);
2982                                                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
2983                                                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
2984                                                         if(j-7<(accountactive?accountactive->getCampaignChoicesMade():0))glColor4f(0.5,0,0,1);
2985                                                         if(j-7>=(accountactive?accountactive->getCampaignChoicesMade():0))glColor4f(1,0,0,1);
2986                                                         if(j==6)glColor4f(1,1,1,1);
2987                                                         XYZ midpoint;
2988                                                         float itemsize;
2989                                                         itemsize=abs(startx[j]-endx[j])/2;
2990                                                         midpoint=0;
2991                                                         midpoint.x=(startx[j]+endx[j])/2;
2992                                                         midpoint.y=(starty[j]+endy[j])/2;
2993                                                         if(j>6&&(j-7<(accountactive?accountactive->getCampaignChoicesMade():0)))itemsize*=.5;
2994                                                         if(!(j-7>(accountactive?accountactive->getCampaignChoicesMade():0)+campaignchoicenum))
2995                                                         {
2996                                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
2997                                                                 glPushMatrix();
2998                                                                         glBegin(GL_QUADS);
2999                                                                         glTexCoord2f(0,0);
3000                                                                         glVertex3f(midpoint.x-itemsize, midpoint.y-itemsize,     0.0f);
3001                                                                         glTexCoord2f(1,0);
3002                                                                         glVertex3f(midpoint.x+itemsize,         midpoint.y-itemsize,     0.0f);
3003                                                                         glTexCoord2f(1,1);
3004                                                                         glVertex3f(midpoint.x+itemsize,         midpoint.y+itemsize, 0.0f);
3005                                                                         glTexCoord2f(0,1);
3006                                                                         glVertex3f(midpoint.x-itemsize,         midpoint.y+itemsize, 0.0f);
3007                                                                         glEnd();
3008                                                                 glPopMatrix();
3009                                                                 glEnable(GL_BLEND);
3010                                                                 //glDisable(GL_ALPHA_TEST);
3011                                                                 if(j<4)glBlendFunc(GL_SRC_ALPHA,GL_ONE);
3012                                                                 for(i=0;i<10;i++)
3013                                                                 {
3014                                                                         if(1-((float)i)/10-(1-selectedlong[j])>0)
3015                                                                         {
3016                                                                                 glColor4f(1,0,0,(1-((float)i)/10-(1-selectedlong[j]))*.25);
3017                                                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3018                                                                                 glPushMatrix();
3019                                                                                         glBegin(GL_QUADS);
3020                                                                                         glTexCoord2f(0,0);
3021                                                                                         glVertex3f(midpoint.x-itemsize-((float)i)*1/2+offsetx[j]*((float)i)/2,  midpoint.y-itemsize-((float)i)*1/2+offsety[j]*((float)i)/2,      0.0f);
3022                                                                                         glTexCoord2f(1,0);
3023                                                                                         glVertex3f(midpoint.x+itemsize+((float)i)*1/2+offsetx[j]*((float)i)/2,  midpoint.y-itemsize-((float)i)*1/2+offsety[j]*((float)i)/2,      0.0f);
3024                                                                                         glTexCoord2f(1,1);
3025                                                                                         glVertex3f(midpoint.x+itemsize+((float)i)*1/2+offsetx[j]*((float)i)/2,  midpoint.y+itemsize+((float)i)*1/2+offsety[j]*((float)i)/2, 0.0f);
3026                                                                                         glTexCoord2f(0,1);
3027                                                                                         glVertex3f(midpoint.x-itemsize-((float)i)*1/2+offsetx[j]*((float)i)/2, midpoint.y+itemsize+((float)i)*1/2+offsety[j]*((float)i)/2, 0.0f);
3028                                                                                         glEnd();
3029                                                                                 glPopMatrix();
3030                                                                         }
3031                                                                 }
3032                                                         }
3033                                                 glPopMatrix();
3034                                         glPopMatrix();
3035                                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3036                                 glPopMatrix();
3037                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3038
3039                                 if(j-7>=(accountactive?accountactive->getCampaignChoicesMade():0)){
3040                                         text.glPrintOutlined(0.9,0,0,startx[j]+10,starty[j]-4,menustring[j],0,0.6,640,480);
3041                                         glDisable(GL_DEPTH_TEST);
3042                                 }
3043                         }
3044                 }
3045         }
3046         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3047         glPopMatrix();
3048         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3049         glPopMatrix();
3050
3051                 if(mainmenu==1||mainmenu==2)
3052                         //if(transition<.1||transition>.9){
3053                                 glClear(GL_DEPTH_BUFFER_BIT);
3054                                 glEnable(GL_ALPHA_TEST);
3055                                 glAlphaFunc(GL_GREATER, 0.001f);
3056                                 glEnable(GL_TEXTURE_2D);
3057                                 glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
3058                                 glDisable(GL_CULL_FACE);
3059                                 glDisable(GL_LIGHTING);
3060                                 glDepthMask(0);
3061                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3062                                 glPushMatrix();                                                                         // Store The Projection Matrix
3063                                         glLoadIdentity();                                                                       // Reset The Projection Matrix
3064                                         glOrtho(0,640,0,480,-100,100);                                          // Set Up An Ortho Screen
3065                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3066                                         glPushMatrix();                                                                         // Store The Modelview Matrix
3067                                                 glLoadIdentity();                                                               // Reset The Modelview Matrix
3068                                                 glPushMatrix();
3069                                                         glDisable(GL_TEXTURE_2D);
3070                                                         //if(transition<.1)
3071                                                                 //glColor4f(1,0,0,1-(transition*10));
3072                                                         //if(transition>.9)
3073                                                                 //glColor4f(1,0,0,1-((1-transition)*10));
3074                             glColor4f(1,0,0,1);
3075                                                 glPopMatrix();
3076                                         glPopMatrix();
3077                                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3078                                 glPopMatrix();
3079                         //}
3080
3081                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3082                 glPushMatrix();                                                                         // Store The Projection Matrix
3083                         glLoadIdentity();                                                                       // Reset The Projection Matrix
3084                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
3085                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3086                         glPushMatrix();                                                                         // Store The Modelview Matrix
3087                                 glLoadIdentity();                                                               // Reset The Modelview Matrix
3088                                 glTranslatef(screenwidth/2,screenheight/2,0);
3089                                 glPushMatrix();
3090                                         glScalef((float)screenwidth/2,(float)screenheight/2,1);
3091                                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
3092                                         glEnable(GL_BLEND);
3093                                         glEnable(GL_TEXTURE_2D);
3094                                         glColor4f(1,1,1,1);
3095                                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
3096                                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
3097                                 glPopMatrix();
3098                                 if(!waiting) { // hide the cursor while waiting for a key
3099                                         glPushMatrix();
3100                                                 glTranslatef(mousecoordh-screenwidth/2,mousecoordv*-1+screenheight/2,0);
3101                                                 glScalef((float)screenwidth/64,(float)screenwidth/64,1);
3102                                                 glTranslatef(1,-1,0);
3103                                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
3104                                                 glColor4f(1,1,1,1);
3105                                                 glBindTexture( GL_TEXTURE_2D, cursortexture);
3106                                                 glPushMatrix();
3107                                                         //glScalef(.25,.25,.25);
3108                                                         glBegin(GL_QUADS);
3109                                                         glTexCoord2f(0,0);
3110                                                         glVertex3f(-1,          -1,      0.0f);
3111                                                         glTexCoord2f(1,0);
3112                                                         glVertex3f(1,   -1,      0.0f);
3113                                                         glTexCoord2f(1,1);
3114                                                         glVertex3f(1,   1, 0.0f);
3115                                                         glTexCoord2f(0,1);
3116                                                         glVertex3f(-1,  1, 0.0f);
3117                                                         glEnd();
3118                                                 glPopMatrix();
3119                                         glPopMatrix();
3120                                 }
3121                         glPopMatrix();
3122                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3123                 glPopMatrix();
3124
3125
3126                 if(flashamount>0)
3127                 {
3128                         //printf("Flash amount: %f, delay %i\n", flashamount, flashdelay);
3129                         if(flashamount>1)flashamount=1;
3130                         if(flashdelay<=0)flashamount-=multiplier;
3131                         flashdelay--;
3132                         if(flashamount<0)flashamount=0;
3133                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
3134                         glDisable(GL_CULL_FACE);
3135                         glDisable(GL_LIGHTING);
3136                         glDisable(GL_TEXTURE_2D);
3137                         glDepthMask(0);
3138                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3139                         glPushMatrix();                                                                         // Store The Projection Matrix
3140                                 glLoadIdentity();                                                                       // Reset The Projection Matrix
3141                                 glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
3142                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3143                                 glPushMatrix();                                                                         // Store The Modelview Matrix
3144                                         glLoadIdentity();                                                               // Reset The Modelview Matrix
3145                                         glScalef(screenwidth,screenheight,1);
3146                                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
3147                                         glEnable(GL_BLEND);
3148                                         glColor4f(flashr,flashg,flashb,flashamount);
3149                                         glBegin(GL_QUADS);
3150                                         glVertex3f(0,           0,       0.0f);
3151                                         glVertex3f(256, 0,       0.0f);
3152                                         glVertex3f(256, 256, 0.0f);
3153                                         glVertex3f(0,   256, 0.0f);
3154                                         glEnd();
3155                                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3156                                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
3157                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3158                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
3159                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
3160                         glEnable(GL_CULL_FACE);
3161                         glDisable(GL_BLEND);
3162                         glDepthMask(1);
3163                 }
3164 }