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