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