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