]> git.jsancho.org Git - lugaru.git/blob - Source/GameDraw.cpp
5286b5ddf6585f18b27680b92838ab041cbbc858
[lugaru.git] / Source / GameDraw.cpp
1 /*
2 Copyright (C) 2003, 2010 - Wolfire Games
3
4 This file is part of Lugaru.
5
6 Lugaru is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
14
15 See the GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 */
21
22 #include "Game.h"
23 #include "openal_wrapper.h"
24 #include "Input.h"
25
26 using namespace std;
27
28 extern XYZ viewer;
29 extern int environment;
30 extern float texscale;
31 extern Light light;
32 extern Terrain terrain;
33 //extern Sprites sprites;
34 extern float multiplier;
35 extern float sps;
36 extern float viewdistance;
37 extern float fadestart;
38 extern float screenwidth,screenheight;
39 extern int kTextureSize;
40 extern FRUSTUM frustum;
41 extern Light light;
42 extern Objects objects;
43 extern int detail;
44 extern float usermousesensitivity;
45 extern bool osx;
46 extern float camerashake;
47 extern Weapons weapons;
48 extern Person player[maxplayers];
49 extern int slomo;
50 extern float slomodelay;
51 extern bool ismotionblur;
52 extern float woozy;
53 extern float blackout;
54 extern bool damageeffects;
55 extern float volume;
56 extern int numplayers;
57 extern bool texttoggle;
58 extern float blurness;
59 extern float targetblurness;
60 extern float playerdist;
61 extern bool cellophane;
62 extern bool freeze;
63 extern float flashamount,flashr,flashg,flashb;
64 extern int flashdelay;
65 extern int netstate;
66 extern float motionbluramount;
67 extern bool isclient;
68 extern bool alwaysblur;
69 extern int test;
70 extern bool tilt2weird;
71 extern bool tiltweird;
72 extern bool midweird;
73 extern bool proportionweird;
74 extern bool vertexweird[6];
75 extern bool velocityblur;
76 extern bool debugmode;
77 extern int mainmenu;
78 extern int oldmainmenu;
79 extern int bloodtoggle;
80 extern int difficulty;
81 extern bool decals;
82 // MODIFIED GWC
83 //extern int texdetail;
84 extern float texdetail;
85 extern bool musictoggle;
86 extern int bonus;
87 extern float bonusvalue;
88 extern float bonustotal;
89 extern float bonustime;
90 extern int oldbonus;
91 extern float startbonustotal;
92 extern float bonusnum[100];
93 extern int tutoriallevel;
94 extern float smoketex;
95 extern float tutorialstagetime;
96 extern float tutorialmaxtime;
97 extern int tutorialstage;
98 extern bool againbonus;
99 extern float damagedealt;
100 extern float damagetaken;
101 extern bool invertmouse;
102
103 extern int numhotspots;
104 extern int winhotspot;
105 extern int killhotspot;
106 extern XYZ hotspot[40];
107 extern int hotspottype[40];
108 extern float hotspotsize[40];
109 extern char hotspottext[40][256];
110 extern int currenthotspot;;
111
112 extern int numfalls;
113 extern int numflipfail;
114 extern int numseen;
115 extern int numstaffattack;
116 extern int numswordattack;
117 extern int numknifeattack;
118 extern int numunarmedattack;
119 extern int numescaped;
120 extern int numflipped;
121 extern int numwallflipped;
122 extern int numthrowkill;
123 extern int numafterkill;
124 extern int numreversals;
125 extern int numattacks;
126 extern int maxalarmed;
127 extern int numresponded;
128
129 extern bool campaign;
130 extern bool winfreeze;
131
132 extern float menupulse;
133
134 extern bool gamestart;
135
136 extern int numdialogues;
137 extern int numdialogueboxes[max_dialogues];
138 extern int dialoguetype[max_dialogues];
139 extern int dialogueboxlocation[max_dialogues][max_dialoguelength];
140 extern float dialogueboxcolor[max_dialogues][max_dialoguelength][3];
141 extern int dialogueboxsound[max_dialogues][max_dialoguelength];
142 extern char dialoguetext[max_dialogues][max_dialoguelength][128];
143 extern char dialoguename[max_dialogues][max_dialoguelength][64];
144 extern XYZ dialoguecamera[max_dialogues][max_dialoguelength];
145 extern XYZ participantlocation[max_dialogues][10];
146 extern int participantfocus[max_dialogues][max_dialoguelength];
147 extern int participantaction[max_dialogues][max_dialoguelength];
148 extern float participantrotation[max_dialogues][10];
149 extern XYZ participantfacing[max_dialogues][max_dialoguelength][10];
150 extern float dialoguecamerarotation[max_dialogues][max_dialoguelength];
151 extern float dialoguecamerarotation2[max_dialogues][max_dialoguelength];
152 extern int indialogue;
153 extern int whichdialogue;
154 extern int directing;
155 extern float dialoguetime;
156 extern int dialoguegonethrough[20];
157
158 extern bool gamestarted;
159
160 extern bool showdamagebar;
161
162 extern OPENAL_SAMPLE    *samp[100];
163 extern int channels[100];
164 extern "C"      void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
165
166 void Game::flash() { // shouldn't be that way, these should be attributes and Person class should not change rendering.
167         flashr=1;
168         flashg=0;
169         flashb=0;
170         flashamount=1;
171         flashdelay=1;
172 }
173 /*********************> DrawGLScene() <*****/
174 int Game::DrawGLScene(StereoSide side)
175 {       
176         static float texcoordwidth,texcoordheight;
177         static float texviewwidth, texviewheight;
178         static int i,j,k,l;
179         static GLubyte color;
180         static float newbrightness;
181         static float changespeed;
182         static XYZ checkpoint;
183         static float tempmult;
184         float tutorialopac;
185         static char string[256]="";
186         static char string2[256]="";
187         static char string3[256]="";
188
189         static float lastcheck;
190
191         lastcheck+=multiplier;
192
193         if ( stereomode == stereoAnaglyph ) {
194                 switch(side) {
195                         case stereoLeft: glColorMask( 0.0, 1.0, 1.0, 1.0 ); break;
196                         case stereoRight: glColorMask( 1.0, 0.0, 0.0, 1.0 ); break;
197                 }
198         } else {
199                 glColorMask( 1.0, 1.0, 1.0, 1.0 );
200                 
201                 if ( stereomode == stereoHorizontalInterlaced || stereomode == stereoVerticalInterlaced ) {
202                         glStencilFunc(side == stereoLeft ? GL_NOTEQUAL : GL_EQUAL, 0x01, 0x01);
203                 }
204         }
205
206         if(freeze||winfreeze||(mainmenu&&gameon)||(!gameon&&gamestarted)){
207                 tempmult=multiplier;
208                 multiplier=0;
209         }
210
211         if(!mainmenu){
212                 if(editorenabled){
213                         numboundaries=mapradius*2;
214                         if(numboundaries>360)numboundaries=360;
215                         for(i=0;i<numboundaries;i++){
216                                 boundary[i]=0;
217                                 boundary[i].z=1;
218                                 boundary[i]=mapcenter+DoRotation(boundary[i]*mapradius,0,i*(360/((float)(numboundaries))),0);
219                         }
220                 }
221
222                 SetUpLighting();
223
224                 static int changed;
225                 changed=0;
226
227                 olddrawmode=drawmode;
228                 if(ismotionblur&&!loading){
229                         if((findLengthfast(&player[0].velocity)>200)&&velocityblur&&!cameramode){
230                                 drawmode=motionblurmode;
231                                 motionbluramount=200/(findLengthfast(&player[0].velocity));
232                                 changed=1;
233                         }
234                         if(player[0].damage-player[0].superpermanentdamage>(player[0].damagetolerance-player[0].superpermanentdamage)*1/2&&damageeffects&&!cameramode){
235                                 drawmode=doublevisionmode;
236                                 changed=1;
237                         }
238                 }
239
240                 if(slomo&&!loading){
241                         if(ismotionblur)
242                                 drawmode=motionblurmode;
243                         motionbluramount=.2;
244                         slomodelay-=multiplier;
245                         if(slomodelay<0)slomo=0;
246                         camerashake=0;
247                         changed=1;
248                 }
249                 if((!changed&&!slomo)||loading){
250                         drawmode=normalmode;
251                         if(ismotionblur&&(/*fps>100||*/alwaysblur)){
252                                 if(olddrawmode!=realmotionblurmode)change=1;
253                                 else change=0;
254                                 drawmode=realmotionblurmode;
255                         }
256                         else if(olddrawmode==realmotionblurmode)change=2;
257                         else change=0;
258                 }
259
260                 if(freeze||winfreeze||(mainmenu&&gameon)||(!gameon&&gamestarted))drawmode=normalmode;
261                 if((freeze||winfreeze)&&ismotionblur&&!mainmenu)drawmode=radialzoommode;
262
263                 if(winfreeze||mainmenu)drawmode=normalmode;
264
265 #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++){
1848                                 if(i<6){
1849                                         if(awards[i]==awardklutz)sprintf (string, "Suicidal");
1850                                         if(awards[i]==awardflawless)sprintf (string, "Flawless!");
1851                                         if(awards[i]==awardalldead)sprintf (string, "Take no prisoners");
1852                                         if(awards[i]==awardnodead)sprintf (string, "Merciful");
1853                                         if(awards[i]==awardstealth)sprintf (string, "One with the shadows!");
1854                                         if(awards[i]==awardswordsman)sprintf (string, "Swordsman");
1855                                         if(awards[i]==awardkungfu)sprintf (string, "Unarmed!");
1856                                         if(awards[i]==awardknifefighter)sprintf (string, "Knife fighter");
1857                                         if(awards[i]==awardcoward)sprintf (string, "Coward");
1858                                         if(awards[i]==awardevasion)sprintf (string, "Escape artist");
1859                                         if(awards[i]==awardacrobat)sprintf (string, "Gymnast");
1860                                         if(awards[i]==awardlongrange)sprintf (string, "Blade slinger");
1861                                         if(awards[i]==awardbrutal)sprintf (string, "Brutal");
1862                                         if(awards[i]==awardhyper)sprintf (string, "Hyper");
1863                                         if(awards[i]==awardaikido)sprintf (string, "Aikido master!");
1864                                         if(awards[i]==awardrambo)sprintf (string, "Rambo");
1865                                         if(awards[i]==awardfast)sprintf (string, "Fast");
1866                                         if(awards[i]==awardrealfast)sprintf (string, "Real fast");
1867                                         if(awards[i]==awarddamnfast)sprintf (string, "Damn fast");
1868                                         if(awards[i]==awardstrategy)sprintf (string, "Divide and conquer");
1869                                         if(awards[i]==awardbojutsu)sprintf (string, "Bojutsu");
1870                                         text.glPrintOutlined(1024/30,768*6/8-90-40*i,string,1,2,1024,768);
1871                                 }
1872                         }
1873                 }
1874
1875                 if(drawmode!=normalmode){
1876                         glEnable(GL_TEXTURE_2D);
1877                         glFinish();
1878                         if(!drawtoggle||drawmode!=realmotionblurmode||(drawtoggle==2||change==1)){
1879                                 if(screentexture){
1880
1881                                         glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
1882                                         GLfloat subtractColor[4] = { 0.5, 0.5, 0.5, 0.0 };
1883                                         glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, subtractColor);
1884                                         //glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_SUBTRACT);
1885                                         glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
1886                                         glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_CONSTANT_EXT);
1887                                         glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 2.0f);
1888
1889                                         glBindTexture( GL_TEXTURE_2D, screentexture);
1890                                         glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texviewwidth, texviewheight);         
1891                                 }
1892                         }
1893                         if((drawtoggle||change==1)&&drawmode==realmotionblurmode){
1894                                 if(screentexture2){
1895                                         glBindTexture( GL_TEXTURE_2D, screentexture2);
1896                                         glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texviewwidth, texviewheight);         
1897                                 }
1898                                 if(!screentexture2){
1899                                         glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
1900
1901                                         glGenTextures( 1, &screentexture2 );
1902                                         glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1903
1904                                         glEnable(GL_TEXTURE_2D);
1905                                         glBindTexture( GL_TEXTURE_2D, screentexture2);
1906                                         glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
1907                                         glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
1908
1909                                         glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);                
1910                                 }
1911                         }
1912                         //glFlush();
1913                 }
1914
1915                 glClear(GL_DEPTH_BUFFER_BIT);
1916                 ReSizeGLScene(90,.1f);
1917                 glViewport(0,0,screenwidth,screenheight);       
1918
1919                 if(drawmode!=normalmode){
1920                         glDisable(GL_DEPTH_TEST);
1921                         if(drawmode==motionblurmode){
1922                                 glDrawBuffer(GL_FRONT);
1923                                 glReadBuffer(GL_BACK);
1924                         }
1925                         glColor3f (1.0, 1.0, 1.0); // no coloring
1926
1927                         glEnable(GL_TEXTURE_2D);
1928                         glBindTexture( GL_TEXTURE_2D, screentexture);
1929                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
1930                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
1931                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1932                         glDisable(GL_CULL_FACE);
1933                         glDisable(GL_LIGHTING);
1934                         glDepthMask(0);
1935                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1936                         glPushMatrix();                                                                         // Store The Projection Matrix
1937                         glLoadIdentity();                                                                       // Reset The Projection Matrix
1938                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
1939                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1940                         glPushMatrix();                                                                         // Store The Modelview Matrix
1941                         glLoadIdentity();                                                               // Reset The Modelview Matrix
1942                         glScalef((float)screenwidth/2,(float)screenheight/2,1);
1943                         glTranslatef(1,1,0);
1944                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1945                         glEnable(GL_BLEND);
1946                         if(drawmode==motionblurmode){
1947                                 if(motionbluramount<.2)motionbluramount=.2;
1948                                 //glColor4f(1,1,1,fast_sqrt(multiplier)*2.9*motionbluramount);
1949                                 glColor4f(1,1,1,motionbluramount);
1950                                 glPushMatrix();
1951                                 glBegin(GL_QUADS);
1952                                 glTexCoord2f(0,0);
1953                                 glVertex3f(-1,          -1,      0.0f);
1954                                 glTexCoord2f(texcoordwidth,0);
1955                                 glVertex3f(1,   -1,      0.0f);
1956                                 glTexCoord2f(texcoordwidth,texcoordheight);
1957                                 glVertex3f(1,   1, 0.0f);
1958                                 glTexCoord2f(0,texcoordheight);
1959                                 glVertex3f(-1,  1, 0.0f);
1960                                 glEnd();
1961                                 glPopMatrix();
1962                         }
1963                         if(drawmode==realmotionblurmode){
1964                                 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
1965                                 glClear(GL_COLOR_BUFFER_BIT);
1966                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
1967                                 glBindTexture( GL_TEXTURE_2D, screentexture);
1968                                 glColor4f(1,1,1,.5);
1969                                 glPushMatrix();
1970                                 glBegin(GL_QUADS);
1971                                 glTexCoord2f(0,0);
1972                                 glVertex3f(-1,          -1,      0.0f);
1973                                 glTexCoord2f(texcoordwidth,0);
1974                                 glVertex3f(1,   -1,      0.0f);
1975                                 glTexCoord2f(texcoordwidth,texcoordheight);
1976                                 glVertex3f(1,   1, 0.0f);
1977                                 glTexCoord2f(0,texcoordheight);
1978                                 glVertex3f(-1,  1, 0.0f);
1979                                 glEnd();
1980                                 glPopMatrix();
1981                                 glBindTexture( GL_TEXTURE_2D, screentexture2);
1982                                 glColor4f(1,1,1,.5);
1983                                 glPushMatrix();
1984                                 glBegin(GL_QUADS);
1985                                 glTexCoord2f(0,0);
1986                                 glVertex3f(-1,          -1,      0.0f);
1987                                 glTexCoord2f(texcoordwidth,0);
1988                                 glVertex3f(1,   -1,      0.0f);
1989                                 glTexCoord2f(texcoordwidth,texcoordheight);
1990                                 glVertex3f(1,   1, 0.0f);
1991                                 glTexCoord2f(0,texcoordheight);
1992                                 glVertex3f(-1,  1, 0.0f);
1993                                 glEnd();
1994                                 glPopMatrix();
1995                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1996                         }
1997                         if(drawmode==doublevisionmode){
1998                                 static float crosseyedness;
1999                                 crosseyedness=abs(player[0].damage-player[0].superpermanentdamage-(player[0].damagetolerance-player[0].superpermanentdamage)*1/2)/30;
2000                                 if(crosseyedness>1)crosseyedness=1;
2001                                 if(crosseyedness<0)crosseyedness=0;
2002                                 glColor4f(1,1,1,1);
2003                                 glDisable(GL_BLEND);
2004                                 glPushMatrix();
2005                                 glScalef(1,1,1);
2006                                 glBegin(GL_QUADS);
2007                                 glTexCoord2f(0,0);
2008                                 glVertex3f(-1,          -1,      0.0f);
2009                                 glTexCoord2f(texcoordwidth,0);
2010                                 glVertex3f(1,   -1,      0.0f);
2011                                 glTexCoord2f(texcoordwidth,texcoordheight);
2012                                 glVertex3f(1,   1, 0.0f);
2013                                 glTexCoord2f(0,texcoordheight);
2014                                 glVertex3f(-1,  1, 0.0f);
2015                                 glEnd();
2016                                 glPopMatrix();
2017                                 if(crosseyedness){
2018                                         glColor4f(1,1,1,.5);
2019                                         glEnable(GL_BLEND);
2020                                         glPushMatrix();
2021                                         glTranslatef(.015*crosseyedness,0,0);
2022                                         glScalef(1,1,1);
2023                                         glBegin(GL_QUADS);
2024                                         glTexCoord2f(0,0);
2025                                         glVertex3f(-1,          -1,      0.0f);
2026                                         glTexCoord2f(texcoordwidth,0);
2027                                         glVertex3f(1,   -1,      0.0f);
2028                                         glTexCoord2f(texcoordwidth,texcoordheight);
2029                                         glVertex3f(1,   1, 0.0f);
2030                                         glTexCoord2f(0,texcoordheight);
2031                                         glVertex3f(-1,  1, 0.0f);
2032                                         glEnd();
2033                                         glPopMatrix();
2034                                 }
2035                         }
2036                         if(drawmode==glowmode){
2037                                 glColor4f(.5,.5,.5,.5);
2038                                 glEnable(GL_BLEND);
2039                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
2040                                 glPushMatrix();
2041                                 glTranslatef(.01,0,0);
2042                                 glBegin(GL_QUADS);
2043                                 glTexCoord2f(0,0);
2044                                 glVertex3f(-1,          -1,      0.0f);
2045                                 glTexCoord2f(texcoordwidth,0);
2046                                 glVertex3f(1,   -1,      0.0f);
2047                                 glTexCoord2f(texcoordwidth,texcoordheight);
2048                                 glVertex3f(1,   1, 0.0f);
2049                                 glTexCoord2f(0,texcoordheight);
2050                                 glVertex3f(-1,  1, 0.0f);
2051                                 glEnd();
2052                                 glPopMatrix();
2053                                 glPushMatrix();
2054                                 glTranslatef(-.01,0,0);
2055                                 glBegin(GL_QUADS);
2056                                 glTexCoord2f(0,0);
2057                                 glVertex3f(-1,          -1,      0.0f);
2058                                 glTexCoord2f(texcoordwidth,0);
2059                                 glVertex3f(1,   -1,      0.0f);
2060                                 glTexCoord2f(texcoordwidth,texcoordheight);
2061                                 glVertex3f(1,   1, 0.0f);
2062                                 glTexCoord2f(0,texcoordheight);
2063                                 glVertex3f(-1,  1, 0.0f);
2064                                 glEnd();
2065                                 glPopMatrix();
2066                                 glPushMatrix();
2067                                 glTranslatef(.0,.01,0);
2068                                 glBegin(GL_QUADS);
2069                                 glTexCoord2f(0,0);
2070                                 glVertex3f(-1,          -1,      0.0f);
2071                                 glTexCoord2f(texcoordwidth,0);
2072                                 glVertex3f(1,   -1,      0.0f);
2073                                 glTexCoord2f(texcoordwidth,texcoordheight);
2074                                 glVertex3f(1,   1, 0.0f);
2075                                 glTexCoord2f(0,texcoordheight);
2076                                 glVertex3f(-1,  1, 0.0f);
2077                                 glEnd();
2078                                 glPopMatrix();
2079                                 glPushMatrix();
2080                                 glTranslatef(0,-.01,0);
2081                                 glBegin(GL_QUADS);
2082                                 glTexCoord2f(0,0);
2083                                 glVertex3f(-1,          -1,      0.0f);
2084                                 glTexCoord2f(texcoordwidth,0);
2085                                 glVertex3f(1,   -1,      0.0f);
2086                                 glTexCoord2f(texcoordwidth,texcoordheight);
2087                                 glVertex3f(1,   1, 0.0f);
2088                                 glTexCoord2f(0,texcoordheight);
2089                                 glVertex3f(-1,  1, 0.0f);
2090                                 glEnd();
2091                                 glPopMatrix();
2092                         }
2093                         if(drawmode==radialzoommode){
2094                                 for(i=0;i<3;i++){
2095                                         //glRotatef((float)i*.1,0,0,1);
2096                                         glColor4f(1,1,1,1/((float)i+1));
2097                                         glPushMatrix();
2098                                         glScalef(1+(float)i*.01,1+(float)i*.01,1);
2099                                         glBegin(GL_QUADS);
2100                                         glTexCoord2f(0,0);
2101                                         glVertex3f(-1,          -1,      0.0f);
2102                                         glTexCoord2f(texcoordwidth,0);
2103                                         glVertex3f(1,   -1,      0.0f);
2104                                         glTexCoord2f(texcoordwidth,texcoordheight);
2105                                         glVertex3f(1,   1, 0.0f);
2106                                         glTexCoord2f(0,texcoordheight);
2107                                         glVertex3f(-1,  1, 0.0f);
2108                                         glEnd();
2109                                         glPopMatrix();
2110                                 }
2111                         }
2112                         glDisable(GL_TEXTURE_2D);
2113                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
2114                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
2115                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
2116                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
2117                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
2118                         glEnable(GL_CULL_FACE);
2119                         glDisable(GL_BLEND);
2120                         glDepthMask(1);
2121                 }
2122
2123                 if(console){
2124                         glEnable(GL_TEXTURE_2D);
2125                         glColor4f(1,1,1,1);
2126                         int offset = 0;
2127                         if(consoleselected>=60)
2128                                 offset=consoleselected-60;
2129                         sprintf (string, " ]");
2130                         text.glPrint(10,30,string,0,1,1024,768);
2131                         if(consoleblink){
2132                                 sprintf (string, "_");
2133                                 text.glPrint(30+(float)(consoleselected)*10-offset*10,30,string,0,1,1024,768);
2134                         }
2135                         for(i=0;i<15;i++){
2136                                 for(j=0;j<consolechars[i];j++){
2137                                         glColor4f(1,1,1,1-(float)(i)/16);
2138                                         if(j<consolechars[i]){
2139                                                 sprintf (string, "%c",consoletext[i][j]);
2140                                                 text.glPrint(30+j*10-offset*10,30+i*20,string,0,1,1024,768);
2141                                         }
2142                                 }
2143                         }
2144                 }
2145         }
2146
2147         if(freeze||winfreeze||(mainmenu&&gameon)||(!gameon&&gamestarted)||(mainmenu&&gameon)||(!gameon&&gamestarted)||(!gameon&&gamestarted)){
2148                 multiplier=tempmult;
2149         }
2150
2151         if(mainmenu){
2152
2153         // !!! FIXME: hack: clamp framerate in menu so text input works correctly on fast systems.
2154         SDL_Delay(15);
2155
2156                 glDrawBuffer(GL_BACK);
2157                 glReadBuffer(GL_BACK);
2158                 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
2159                 ReSizeGLScene(90,.1f);
2160
2161                 int temptexdetail;
2162                 temptexdetail=texdetail;
2163                 if(texdetail>2)texdetail=2;
2164                 if(mainmenu!=oldmainmenu&&oldmainmenu!=0){
2165                         if(mainmenu==1){
2166                                 LoadTexture(":Data:Textures:Newgame.png",&Mainmenuitems[1],0,0);
2167                                 LoadTexture(":Data:Textures:Quit.png",&Mainmenuitems[3],0,0);
2168                         }
2169                         if(mainmenu==2){
2170                                 LoadTexture(":Data:Textures:Resume.png",&Mainmenuitems[1],0,0);
2171                                 LoadTexture(":Data:Textures:Endgame.png",&Mainmenuitems[3],0,0);
2172                         }
2173                 }
2174                 if(lastcheck>.5||oldmainmenu!=mainmenu){
2175                         if(mainmenu==5){
2176                                 ifstream ipstream(ConvertFileName(":Data:Campaigns:main.txt"));
2177                                 ipstream.ignore(256,':');
2178                                 ipstream >> campaignnumlevels;
2179                                 for(i=0;i<campaignnumlevels;i++){
2180                                         ipstream.ignore(256,':');
2181                                         ipstream.ignore(256,':');
2182                                         ipstream.ignore(256,' ');
2183                                         ipstream >> campaignmapname[i];
2184                                         ipstream.ignore(256,':');
2185                                         ipstream >> campaigndescription[i];
2186                                         for(j=0;j<256;j++){
2187                                                 if(campaigndescription[i][j]=='_')campaigndescription[i][j]=' ';
2188                                         }
2189                                         ipstream.ignore(256,':');
2190                                         ipstream >> campaignchoosenext[i];
2191                                         ipstream.ignore(256,':');
2192                                         ipstream >> campaignnumnext[i];
2193                                         for(j=0;j<campaignnumnext[i];j++){
2194                                                 ipstream.ignore(256,':');
2195                                                 ipstream >> campaignnextlevel[i][j];
2196                                                 campaignnextlevel[i][j]-=1;
2197                                         }
2198                                         ipstream.ignore(256,':');
2199                                         ipstream >> campaignlocationx[i];
2200                                         ipstream.ignore(256,':');
2201                                         ipstream >> campaignlocationy[i];
2202                                 }
2203                                 ipstream.close();
2204
2205                                 for(i=0;i<campaignnumlevels;i++){
2206                                         levelvisible[i]=0;
2207                                         levelhighlight[i]=0;
2208                                 }
2209
2210                                 levelorder[0]=0;
2211                                 levelvisible[0]=1;
2212                                 for(i=0;i<accountactive->getCampaignChoicesMade();i++){
2213                                         levelorder[i+1]=campaignnextlevel[levelorder[i]][accountactive->getCampaignChoice(i)];
2214                                         levelvisible[levelorder[i+1]]=1;
2215                                 }
2216                                 int whichlevelstart = accountactive->getCampaignChoicesMade()-1;
2217                                 if(whichlevelstart<0){
2218                                         accountactive->setCampaignScore(0);
2219                                         accountactive->resetFasttime();
2220                                         campaignchoicenum=1;
2221                                         campaignchoicewhich[0]=0;
2222                                 }
2223                                 else
2224                                 {
2225                                         campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
2226                                         for(i=0;i<campaignchoicenum;i++){
2227                                                 campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
2228                                                 levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
2229                                                 levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
2230                                         }
2231                                 }
2232                         }
2233                 }
2234                 if(mainmenu==5){
2235                         lastcheck=0;
2236                 }
2237
2238                 texdetail=temptexdetail;
2239
2240                 oldmainmenu=mainmenu;
2241
2242                 if(mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==8||mainmenu==9||mainmenu==10||mainmenu==119||mainmenu==18){
2243                         glClear(GL_DEPTH_BUFFER_BIT);
2244                         glEnable(GL_ALPHA_TEST);
2245                         glAlphaFunc(GL_GREATER, 0.001f);
2246                         glEnable(GL_TEXTURE_2D);
2247                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
2248                         glDisable(GL_CULL_FACE);
2249                         glDisable(GL_LIGHTING);
2250                         glDepthMask(0);
2251                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
2252                         glPushMatrix();                                                                         // Store The Projection Matrix
2253                                 glLoadIdentity();                                                                       // Reset The Projection Matrix
2254                                 glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
2255                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
2256                                         glPushMatrix();                                                                         // Store The Modelview Matrix
2257                                         glLoadIdentity();                                                               // Reset The Modelview Matrix
2258                                         glTranslatef(screenwidth/2,screenheight/2,0);
2259                                         glPushMatrix();
2260                                                 glScalef((float)screenwidth/2,(float)screenheight/2,1);
2261                                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
2262                                                 glDisable(GL_BLEND);
2263                                                 glColor4f(0,0,0,1.0);
2264                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
2265                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
2266                                                 glDisable(GL_TEXTURE_2D);
2267                                                 glPushMatrix();
2268                                                         //glScalef(.25,.25,.25);
2269                                                         glBegin(GL_QUADS);
2270                                                         glTexCoord2f(0,0);
2271                                                         glVertex3f(-1,          -1,      0.0f);
2272                                                         glTexCoord2f(1,0);
2273                                                         glVertex3f(1,   -1,      0.0f);
2274                                                         glTexCoord2f(1,1);
2275                                                         glVertex3f(1,   1, 0.0f);
2276                                                         glTexCoord2f(0,1);
2277                                                         glVertex3f(-1,  1, 0.0f);
2278                                                         glEnd();
2279                                                 glPopMatrix();
2280                                                 glEnable(GL_BLEND);
2281                                                 glColor4f(0.4,0.4,0.4,1.0);
2282                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
2283                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
2284                                                 glEnable(GL_TEXTURE_2D);
2285                                                 glBindTexture( GL_TEXTURE_2D, Mainmenuitems[4]);
2286                                                 glPushMatrix();
2287                                                         //glScalef(.25,.25,.25);
2288                                                         glBegin(GL_QUADS);
2289                                                         glTexCoord2f(0,0);
2290                                                         glVertex3f(-1,          -1,      0.0f);
2291                                                         glTexCoord2f(1,0);
2292                                                         glVertex3f(1,   -1,      0.0f);
2293                                                         glTexCoord2f(1,1);
2294                                                         glVertex3f(1,   1, 0.0f);
2295                                                         glTexCoord2f(0,1);
2296                                                         glVertex3f(-1,  1, 0.0f);
2297                                                         glEnd();
2298                                                 glPopMatrix();
2299                                         glPopMatrix();
2300                                 glPopMatrix();
2301                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
2302                         glPopMatrix();
2303                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
2304
2305                         if(mainmenu==3){                        
2306                                 nummenuitems=14;
2307                                 if((float)newscreenwidth>(float)newscreenheight*1.61||(float)newscreenwidth<(float)newscreenheight*1.59)sprintf (menustring[0], "Resolution: %d*%d",(int)newscreenwidth,(int)newscreenheight);
2308                                 else sprintf (menustring[0], "Resolution: %d*%d (widescreen)",(int)newscreenwidth,(int)newscreenheight);
2309                                 startx[0]=10+20;
2310                                 starty[0]=440;
2311                                 endx[0]=startx[0]+strlen(menustring[0])*10;
2312                                 endy[0]=starty[0]+20;
2313                                 movex[0]=0;
2314                                 movey[0]=0;
2315
2316                                 if(newdetail==2)sprintf (menustring[1], "Detail: High");
2317                                 else if(newdetail==1)sprintf (menustring[1], "Detail: Medium");
2318                                 else sprintf (menustring[1], "Detail: Low");
2319                                 startx[1]=10+60;
2320                                 starty[1]=405;
2321                                 endx[1]=startx[1]+strlen(menustring[1])*10;
2322                                 endy[1]=starty[1]+20;
2323                                 movex[1]=0;
2324                                 movey[1]=0;
2325
2326                                 if(bloodtoggle==2)sprintf (menustring[2], "Blood: On, high detail (slower)");
2327                                 if(bloodtoggle==1)sprintf (menustring[2], "Blood: On, low detail");
2328                                 if(bloodtoggle==0)sprintf (menustring[2], "Blood: Off");
2329                                 startx[2]=10+70;
2330                                 starty[2]=370;
2331                                 endx[2]=startx[2]+strlen(menustring[2])*10;
2332                                 endy[2]=starty[2]+20;
2333                                 movex[2]=0;
2334                                 movey[2]=0;
2335
2336                                 if(difficulty==2)sprintf (menustring[3], "Difficulty: Insane");
2337                                 if(difficulty==1)sprintf (menustring[3], "Difficulty: Difficult");
2338                                 if(difficulty==0)sprintf (menustring[3], "Difficulty: Easier");
2339                                 startx[3]=10+20-1000;
2340                                 starty[3]=335-1000;
2341                                 endx[3]=startx[3]+strlen(menustring[3])*10;
2342                                 endy[3]=starty[3]+20;
2343                                 movex[3]=0;
2344                                 movey[3]=0;
2345
2346                                 if(ismotionblur==1)sprintf (menustring[4], "Blur Effects: Enabled (less compatible)");
2347                                 if(ismotionblur==0)sprintf (menustring[4], "Blur Effects: Disabled (more compatible)");
2348                                 startx[4]=10;
2349                                 starty[4]=335;
2350                                 endx[4]=startx[4]+strlen(menustring[4])*10;
2351                                 endy[4]=starty[4]+20;
2352                                 movex[4]=0;
2353                                 movey[4]=0;
2354
2355                                 if(decals==1)sprintf (menustring[5], "Decals: Enabled (slower)");
2356                                 if(decals==0)sprintf (menustring[5], "Decals: Disabled");
2357                                 startx[5]=10+60;
2358                                 starty[5]=300;
2359                                 endx[5]=startx[5]+strlen(menustring[5])*10;
2360                                 endy[5]=starty[5]+20;
2361                                 movex[5]=0;
2362                                 movey[5]=0;
2363
2364                                 if(musictoggle==1)sprintf (menustring[6], "Music: Enabled");
2365                                 if(musictoggle==0)sprintf (menustring[6], "Music: Disabled");
2366                                 startx[6]=10+70;
2367                                 starty[6]=265;
2368                                 endx[6]=startx[6]+strlen(menustring[6])*10;
2369                                 endy[6]=starty[6]+20;
2370                                 movex[6]=0;
2371                                 movey[6]=0;
2372
2373                                 if(invertmouse==1)sprintf (menustring[9], "Invert mouse: Yes");
2374                                 if(invertmouse==0)sprintf (menustring[9], "Invert mouse: No");
2375                                 startx[9]=10;
2376                                 starty[9]=230;
2377                                 endx[9]=startx[9]+strlen(menustring[9])*10;
2378                                 endy[9]=starty[9]+20;
2379                                 movex[9]=0;
2380                                 movey[9]=0;
2381
2382                                 sprintf (menustring[10], "Mouse Speed: %d", (int)(usermousesensitivity*5));
2383                                 startx[10]=20;
2384                                 starty[10]=195;
2385                                 endx[10]=startx[10]+strlen(menustring[10])*10;
2386                                 endy[10]=starty[10]+20;
2387                                 movex[10]=0;
2388                                 movey[10]=0;
2389                                 
2390                                 sprintf (menustring[11], "Volume: %d%%", (int)(volume*100));
2391                                 startx[11]=10+60;
2392                                 starty[11]=160;
2393                                 endx[11]=startx[11]+strlen(menustring[11])*10;
2394                                 endy[11]=starty[11]+20;
2395                                 movex[11]=0;
2396                                 movey[11]=0;
2397                                 
2398                                 sprintf (menustring[13], "Damage Bar: %s",(showdamagebar?"on":"off"));
2399                                 startx[13]=30;
2400                                 starty[13]=125;
2401                                 endx[13]=startx[13]+strlen(menustring[13])*10;
2402                                 endy[13]=starty[13]+20;
2403                                 movex[13]=0;
2404                                 movey[13]=0;
2405                                 
2406                                 sprintf (menustring[7], "-Configure Controls-");
2407                                 startx[7]=10+15;
2408                                 starty[7]=90;
2409                                 endx[7]=startx[7]+strlen(menustring[7])*10;
2410                                 endy[7]=starty[7]+20;
2411                                 movex[7]=0;
2412                                 movey[7]=0;
2413
2414                                 sprintf (menustring[12], "-Configure Stereo -");
2415                                 startx[12]=10+15;
2416                                 starty[12]=55;
2417                                 endx[12]=startx[12]+strlen(menustring[7])*10;
2418                                 endy[12]=starty[12]+20;
2419                                 movex[12]=0;
2420                                 movey[12]=0;
2421                                 
2422                                 if(newdetail==detail&&newscreenheight==(int)screenheight&&newscreenwidth==(int)screenwidth)sprintf (menustring[8], "Back");
2423                                 else sprintf (menustring[8], "Back (some changes take effect next time Lugaru is opened)");
2424                                 startx[8]=10;
2425                                 endx[8]=startx[8]+strlen(menustring[8])*10;
2426                                 starty[8]=10;
2427                                 endy[8]=starty[8]+20;
2428                                 movex[8]=0;
2429                                 movey[8]=0;
2430                         }
2431
2432                         if(mainmenu==4){                        
2433                                 nummenuitems=10;
2434                                 if(keyselect!=0)sprintf (menustring[0], "Forwards: %s",Input::keyToChar(forwardkey));
2435                                 else sprintf (menustring[0], "Forwards: _");
2436                                 startx[0]=10;
2437                                 starty[0]=400;
2438                                 endx[0]=startx[0]+strlen(menustring[0])*10;
2439                                 endy[0]=starty[0]+20;
2440                                 movex[0]=0;
2441                                 movey[0]=0;
2442
2443                                 if(keyselect!=1)sprintf (menustring[1], "Back: %s",Input::keyToChar(backkey));
2444                                 else sprintf (menustring[1], "Back: _");
2445                                 startx[1]=10+40;
2446                                 starty[1]=360;
2447                                 endx[1]=startx[1]+strlen(menustring[1])*10;
2448                                 endy[1]=starty[1]+20;
2449                                 movex[1]=0;
2450                                 movey[1]=0;
2451
2452                                 if(keyselect!=2)sprintf (menustring[2], "Left: %s",Input::keyToChar(leftkey));
2453                                 else sprintf (menustring[2], "Left: _");
2454                                 startx[2]=10+40;
2455                                 starty[2]=320;
2456                                 endx[2]=startx[2]+strlen(menustring[2])*10;
2457                                 endy[2]=starty[2]+20;
2458                                 movex[2]=0;
2459                                 movey[2]=0;
2460
2461                                 if(keyselect!=3)sprintf (menustring[3], "Right: %s",Input::keyToChar(rightkey));
2462                                 else sprintf (menustring[3], "Right: _");
2463                                 startx[3]=10+30;
2464                                 starty[3]=280;
2465                                 endx[3]=startx[3]+strlen(menustring[3])*10;
2466                                 endy[3]=starty[3]+20;
2467                                 movex[3]=0;
2468                                 movey[3]=0;
2469
2470                                 if(keyselect!=4)sprintf (menustring[4], "Crouch: %s",Input::keyToChar(crouchkey));
2471                                 else sprintf (menustring[4], "Crouch: _");
2472                                 startx[4]=10+20;
2473                                 starty[4]=240;
2474                                 endx[4]=startx[4]+strlen(menustring[4])*10;
2475                                 endy[4]=starty[4]+20;
2476                                 movex[4]=0;
2477                                 movey[4]=0;
2478
2479                                 if(keyselect!=5)sprintf (menustring[5], "Jump: %s",Input::keyToChar(jumpkey));
2480                                 else sprintf (menustring[5], "Jump: _");
2481                                 startx[5]=10+40;
2482                                 starty[5]=200;
2483                                 endx[5]=startx[5]+strlen(menustring[5])*10;
2484                                 endy[5]=starty[5]+20;
2485                                 movex[5]=0;
2486                                 movey[5]=0;
2487
2488                                 if(keyselect!=6)sprintf (menustring[6], "Draw: %s",Input::keyToChar(drawkey));
2489                                 else sprintf (menustring[6], "Draw: _");
2490                                 startx[6]=10+40;
2491                                 starty[6]=160;
2492                                 endx[6]=startx[6]+strlen(menustring[6])*10;
2493                                 endy[6]=starty[6]+20;
2494                                 movex[6]=0;
2495                                 movey[6]=0;
2496
2497                                 if(keyselect!=7)sprintf (menustring[7], "Throw: %s",Input::keyToChar(throwkey));
2498                                 else sprintf (menustring[7], "Throw: _");
2499                                 startx[7]=10+30;
2500                                 starty[7]=120;
2501                                 endx[7]=startx[7]+strlen(menustring[7])*10;
2502                                 endy[7]=starty[7]+20;
2503                                 movex[7]=0;
2504                                 movey[7]=0;
2505
2506                                 if(keyselect!=8)sprintf (menustring[8], "Attack: %s",Input::keyToChar(attackkey));
2507                                 else sprintf (menustring[8], "Attack: _");
2508                                 startx[8]=10+20;
2509                                 starty[8]=80;
2510                                 endx[8]=startx[8]+strlen(menustring[8])*10;
2511                                 endy[8]=starty[8]+20;
2512                                 movex[8]=0;
2513                                 movey[8]=0;
2514
2515
2516
2517                                 sprintf (menustring[9], "Back");
2518                                 startx[9]=10;
2519                                 endx[9]=startx[9]+strlen(menustring[9])*10;
2520                                 starty[9]=10;
2521                                 endy[9]=starty[9]+20;
2522                                 movex[9]=0;
2523                                 movey[9]=0;
2524                         }
2525                         if(mainmenu==5){                        
2526                                 nummenuitems=7+accountactive->getCampaignChoicesMade()+campaignchoicenum;
2527
2528                                 sprintf (menustring[0], "%s",accountactive->getName());
2529                                 startx[0]=5;
2530                                 starty[0]=400;
2531                                 endx[0]=startx[0]+strlen(menustring[0])*10;
2532                                 endy[0]=starty[0]+20;
2533                                 movex[0]=0;
2534                                 movey[0]=0;
2535
2536                                 sprintf (menustring[1], "Tutorial");
2537                                 startx[1]=5;
2538                                 starty[1]=300;
2539                                 endx[1]=startx[1]+strlen(menustring[1])*10;
2540                                 endy[1]=starty[1]+20;
2541                                 movex[1]=0;
2542                                 movey[1]=0;
2543
2544                                 sprintf (menustring[2], "Challenge");
2545                                 startx[2]=5;
2546                                 starty[2]=240;
2547                                 endx[2]=startx[2]+strlen(menustring[2])*10;
2548                                 endy[2]=starty[2]+20;
2549                                 movex[2]=0;
2550                                 movey[2]=0;
2551
2552                                 sprintf (menustring[3], "Delete User");
2553                                 startx[3]=400;
2554                                 starty[3]=10;
2555                                 endx[3]=startx[3]+strlen(menustring[3])*10;
2556                                 endy[3]=starty[3]+20;
2557                                 movex[3]=0;
2558                                 movey[3]=0;
2559
2560                                 sprintf (menustring[4], "Main Menu");
2561                                 startx[4]=5;
2562                                 starty[4]=10;
2563                                 endx[4]=startx[4]+strlen(menustring[4])*10;
2564                                 endy[4]=starty[4]+20;
2565                                 movex[4]=0;
2566                                 movey[4]=0;
2567
2568                                 sprintf (menustring[5], "Change User");
2569                                 startx[5]=5;
2570                                 endx[5]=startx[5]+strlen(menustring[5])*10;
2571                                 starty[5]=180;
2572                                 endy[5]=starty[5]+20;
2573                                 movex[5]=0;
2574                                 movey[5]=0;
2575
2576                                 //World
2577
2578                                 sprintf (menustring[6], "World");
2579                                 startx[6]=30+120;
2580                                 starty[6]=30+480-400-50;
2581                                 endx[6]=startx[6]+400;
2582                                 endy[6]=30+480-50;
2583                                 movex[6]=0;
2584                                 movey[6]=0;
2585
2586                                 if(accountactive->getCampaignChoicesMade())
2587                                         for(i=0;i<accountactive->getCampaignChoicesMade();i++){
2588                                                 sprintf (menustring[7+i], "%s", campaigndescription[levelorder[i]]);
2589                                                 startx[7+i]=30+120+campaignlocationx[levelorder[i]]*400/512;
2590                                                 starty[7+i]=30+30+(512-campaignlocationy[levelorder[i]])*400/512;
2591                                                 endx[7+i]=startx[7+i]+10;
2592                                                 endy[7+i]=starty[7+i]+10;
2593                                                 movex[7+i]=0;
2594                                                 movey[7+i]=0;
2595                                         }
2596
2597                                         if(campaignchoicenum>0)
2598                                                 for(i=accountactive->getCampaignChoicesMade();i<accountactive->getCampaignChoicesMade()+campaignchoicenum;i++){
2599                                                         sprintf (menustring[7+i], "%s", campaigndescription[levelorder[i]]);
2600                                                         startx[7+i]=30+120+campaignlocationx[campaignchoicewhich[i-(accountactive->getCampaignChoicesMade())]]*400/512;
2601                                                         starty[7+i]=30+30+(512-campaignlocationy[campaignchoicewhich[i-(accountactive->getCampaignChoicesMade())]])*400/512;
2602                                                         endx[7+i]=startx[7+i]+10;
2603                                                         endy[7+i]=starty[7+i]+10;
2604                                                         movex[7+i]=0;
2605                                                         movey[7+i]=0;
2606                                                 }
2607
2608                                                 /*sprintf (menustring[7], "Dot");
2609                                                 startx[7]=120+260*400/512;
2610                                                 starty[7]=30+(512-184)*400/512;
2611                                                 endx[7]=startx[7]+10;
2612                                                 endy[7]=starty[7]+10;
2613                                                 movex[7]=0;
2614                                                 movey[7]=0;
2615
2616                                                 sprintf (menustring[8], "Dot");
2617                                                 startx[8]=120+129*400/512;
2618                                                 starty[8]=30+(512-284)*400/512;
2619                                                 endx[8]=startx[8]+10;
2620                                                 endy[8]=starty[8]+10;
2621                                                 movex[8]=0;
2622                                                 movey[8]=0;
2623
2624                                                 sprintf (menustring[9], "Dot");
2625                                                 startx[9]=120+358*400/512;
2626                                                 starty[9]=30+(512-235)*400/512;
2627                                                 endx[9]=startx[9]+10;
2628                                                 endy[9]=starty[9]+10;
2629                                                 movex[9]=0;
2630                                                 movey[9]=0;
2631
2632                                                 sprintf (menustring[10], "Dot");
2633                                                 startx[10]=120+359*400/512;
2634                                                 starty[10]=30+(512-308)*400/512;
2635                                                 endx[10]=startx[10]+10;
2636                                                 endy[10]=starty[10]+10;
2637                                                 movex[10]=0;
2638                                                 movey[10]=0;
2639
2640                                                 sprintf (menustring[11], "Dot");
2641                                                 startx[11]=120+288*400/512;
2642                                                 starty[11]=30+(512-277)*400/512;
2643                                                 endx[11]=startx[11]+10;
2644                                                 endy[11]=starty[11]+10;
2645                                                 movex[11]=0;
2646                                                 movey[11]=0;*/
2647                         }
2648
2649                         if(mainmenu==6){                        
2650                                 nummenuitems=3;
2651
2652                                 sprintf (menustring[0], "Are you sure you want to delete this user?");
2653                                 startx[0]=10;
2654                                 starty[0]=400;
2655                                 endx[0]=startx[0]+strlen(menustring[0])*10;
2656                                 endy[0]=starty[0]+20;
2657                                 movex[0]=0;
2658                                 movey[0]=0;
2659
2660                                 sprintf (menustring[1], "Yes");
2661                                 startx[1]=10;
2662                                 starty[1]=360;
2663                                 endx[1]=startx[1]+strlen(menustring[1])*10;
2664                                 endy[1]=starty[1]+20;
2665                                 movex[1]=0;
2666                                 movey[1]=0;
2667
2668                                 sprintf (menustring[2], "No");
2669                                 startx[2]=10;
2670                                 starty[2]=320;
2671                                 endx[2]=startx[2]+strlen(menustring[2])*10;
2672                                 endy[2]=starty[2]+20;
2673                                 movex[2]=0;
2674                                 movey[2]=0;
2675
2676                                 sprintf (menustring[3], "Extra 4");
2677                                 startx[3]=10;
2678                                 starty[3]=280;
2679                                 endx[3]=startx[3]+strlen(menustring[3])*10;
2680                                 endy[3]=starty[3]+20;
2681                                 movex[3]=0;
2682                                 movey[3]=0;
2683
2684                                 sprintf (menustring[4], "Extra 5");
2685                                 startx[4]=10;
2686                                 starty[4]=240;
2687                                 endx[4]=startx[4]+strlen(menustring[4])*10;
2688                                 endy[4]=starty[4]+20;
2689                                 movex[4]=0;
2690                                 movey[4]=0;
2691
2692                                 sprintf (menustring[5], "Back");
2693                                 startx[5]=10;
2694                                 endx[5]=startx[5]+strlen(menustring[5])*10;
2695                                 starty[5]=10;
2696                                 endy[5]=starty[5]+20;
2697                                 movex[5]=0;
2698                                 movey[5]=0;
2699                         }
2700
2701                         if(mainmenu==7){        
2702                                 nummenuitems=Account::getNbAccounts()+2;
2703
2704                                 int num;
2705
2706                                 if(Account::getNbAccounts()<8)
2707                                         sprintf (menustring[0], "New User");
2708                                 else
2709                                         sprintf (menustring[0], "No More Users");
2710                                 startx[0]=10;
2711                                 starty[0]=400;
2712                                 endx[0]=startx[0]+strlen(menustring[0])*10;
2713                                 endy[0]=starty[0]+20;
2714                                 movex[0]=0;
2715                                 movey[0]=0;
2716
2717                                 if(entername)
2718                                         startx[0]+=10;
2719
2720
2721                                 num=1;
2722                                 for(i=0;i<Account::getNbAccounts();i++){
2723                                         sprintf (menustring[num], "%s",Account::get(i)->getName());
2724                                         startx[num]=10;
2725                                         starty[num]=360-20-20*num;
2726                                         endx[num]=startx[num]+strlen(menustring[num])*10;
2727                                         endy[num]=starty[num]+20;
2728                                         movex[num]=0;
2729                                         movey[num]=0;
2730
2731                                         num++;
2732                                 }
2733
2734                                 sprintf (menustring[num], "Back");
2735                                 startx[num]=10;
2736                                 endx[num]=startx[num]+strlen(menustring[num])*10;
2737                                 starty[num]=10;
2738                                 endy[num]=starty[num]+20;
2739                                 movex[num]=0;
2740                                 movey[num]=0;
2741                         }
2742                         if(mainmenu==8){                        
2743                                 nummenuitems=3;
2744
2745                                 sprintf (menustring[0], "Easier");
2746                                 startx[0]=10;
2747                                 starty[0]=400;
2748                                 endx[0]=startx[0]+strlen(menustring[0])*10;
2749                                 endy[0]=starty[0]+20;
2750                                 movex[0]=0;
2751                                 movey[0]=0;
2752
2753                                 sprintf (menustring[1], "Difficult");
2754                                 startx[1]=10;
2755                                 starty[1]=360;
2756                                 endx[1]=startx[1]+strlen(menustring[1])*10;
2757                                 endy[1]=starty[1]+20;
2758                                 movex[1]=0;
2759                                 movey[1]=0;
2760
2761                                 sprintf (menustring[2], "Insane");
2762                                 startx[2]=10;
2763                                 starty[2]=320;
2764                                 endx[2]=startx[2]+strlen(menustring[2])*10;
2765                                 endy[2]=starty[2]+20;
2766                                 movex[2]=0;
2767                                 movey[2]=0;
2768                         }
2769                         if(mainmenu==9){                        
2770                                 int tempncl;
2771                                 //tempncl=numchallengelevels;
2772                                 //numchallengelevels=9;
2773                                 nummenuitems=2+numchallengelevels;
2774                                 char temp[255];
2775
2776                                 for(j=0;j<numchallengelevels;j++){
2777                                         for(i=0;i<255;i++)menustring[j][i]='\0';
2778                                         sprintf (temp, "Level %d",j+1);
2779                                         strcpy(menustring[j],temp);
2780                                         for(i=0;i<17;i++)if(menustring[j][i]=='\0')menustring[j][i]=' ';
2781                                         menustring[j][17]='\0';
2782                                         sprintf (temp, "%d",(int)accountactive->getHighScore(j));
2783                                         strcat(menustring[j],temp);
2784                                         for(i=18;i<32;i++)if(menustring[j][i]=='\0')menustring[j][i]=' ';
2785                                         menustring[j][32]='\0';
2786                                         sprintf (temp, "%d:",(int)(((int)accountactive->getFastTime(j)-(int)(accountactive->getFastTime(j))%60)/60));
2787                                         strcat(menustring[j],temp);
2788                                         if((int)(accountactive->getFastTime(j))%60<10)strcat(menustring[j],"0");
2789                                         sprintf (temp, "%d",(int)(accountactive->getFastTime(j))%60);
2790                                         strcat(menustring[j],temp);
2791
2792                                         startx[j]=10;
2793                                         starty[j]=400-j*25;
2794                                         endx[j]=startx[j]+strlen(menustring[j])*10;
2795                                         endy[j]=starty[j]+20;
2796                                         movex[j]=0;
2797                                         movey[j]=0;
2798                                 }
2799
2800                                 sprintf (menustring[numchallengelevels], "Back");
2801                                 startx[numchallengelevels]=10;
2802                                 endx[numchallengelevels]=startx[numchallengelevels]+strlen(menustring[numchallengelevels])*10;
2803                                 starty[numchallengelevels]=10;
2804                                 endy[numchallengelevels]=starty[numchallengelevels]+20;
2805                                 movex[numchallengelevels]=0;
2806                                 movey[numchallengelevels]=0;
2807
2808                                 sprintf (menustring[numchallengelevels+1], "             High Score      Best Time");
2809                                 startx[numchallengelevels+1]=10;
2810                                 starty[numchallengelevels+1]=440;
2811                                 endx[numchallengelevels+1]=startx[numchallengelevels+1]+strlen(menustring[numchallengelevels+1])*10;
2812                                 endy[numchallengelevels+1]=starty[numchallengelevels+1]+20;
2813                                 movex[numchallengelevels+1]=0;
2814                                 movey[numchallengelevels+1]=0;
2815
2816                                 //numchallengelevels=tempncl;
2817
2818                         }
2819                         if(mainmenu==10){                       
2820                                 nummenuitems=6;
2821                                 char temp[255];
2822
2823                                 sprintf (menustring[0], "Congratulations!");
2824                                 startx[0]=220;
2825                                 starty[0]=330;
2826                                 endx[0]=startx[0]+strlen(menustring[0])*10;
2827                                 endy[0]=starty[0]+20;
2828                                 movex[0]=0;
2829                                 movey[0]=0;
2830
2831                                 sprintf (menustring[1], "You have avenged your family and");
2832                                 startx[1]=140;
2833                                 starty[1]=300;
2834                                 endx[1]=startx[1]+strlen(menustring[1])*10;
2835                                 endy[1]=starty[1]+20;
2836                                 movex[1]=0;
2837                                 movey[1]=0;
2838
2839                                 sprintf (menustring[2], "restored peace to the island of Lugaru.");
2840                                 startx[2]=110;
2841                                 starty[2]=270;
2842                                 endx[2]=startx[2]+strlen(menustring[2])*10;
2843                                 endy[2]=starty[2]+20;
2844                                 movex[2]=0;
2845                                 movey[2]=0;
2846
2847                                 sprintf (menustring[3], "Back");
2848                                 startx[3]=10;
2849                                 endx[3]=startx[3]+strlen(menustring[3])*10;
2850                                 starty[3]=10;
2851                                 endy[3]=starty[3]+20;
2852                                 movex[3]=0;
2853                                 movey[3]=0;
2854
2855                                 for(i=0;i<255;i++)menustring[4][i]='\0';
2856                                 sprintf (temp, "Your score:");
2857                                 strcpy(menustring[4],temp);
2858                                 for(i=0;i<20;i++)if(menustring[4][i]=='\0')menustring[4][i]=' ';
2859                                 menustring[4][20]='\0';
2860                                 sprintf (temp, "%d",(int)accountactive->getCampaignScore());
2861                                 strcat(menustring[4],temp);
2862                                 startx[4]=190;
2863                                 endx[4]=startx[4]+strlen(menustring[4])*10;
2864                                 starty[4]=200;
2865                                 endy[4]=starty[4]+20;
2866                                 movex[4]=0;
2867                                 movey[4]=0;
2868                                 /*
2869                                 for(i=0;i<255;i++)menustring[5][i]='\0';
2870                                 sprintf (temp, "Your time:");
2871                                 strcpy(menustring[5],temp);
2872                                 for(i=0;i<20;i++)if(menustring[5][i]=='\0')menustring[5][i]=' ';
2873                                 menustring[5][20]='\0';
2874                                 sprintf (temp, "%d",(int)accountcampaigntime[accountactive]);
2875                                 strcat(menustring[5],temp);
2876                                 startx[5]=200;
2877                                 endx[5]=startx[5]+strlen(menustring[5])*10;
2878                                 starty[5]=180;
2879                                 endy[5]=starty[5]+20;
2880                                 movex[5]=0;
2881                                 movey[5]=0;
2882                                 */
2883                                 for(i=0;i<255;i++)menustring[5][i]='\0';
2884                                 sprintf (temp, "Highest score:");
2885                                 strcpy(menustring[5],temp);
2886                                 for(i=0;i<20;i++)if(menustring[5][i]=='\0')menustring[5][i]=' ';
2887                                 menustring[5][20]='\0';
2888                                 sprintf (temp, "%d",(int)accountactive->getCampaignHighScore());
2889                                 strcat(menustring[5],temp);
2890                                 startx[5]=190;
2891                                 endx[5]=startx[5]+strlen(menustring[5])*10;
2892                                 starty[5]=180;
2893                                 endy[5]=starty[5]+20;
2894                                 movex[5]=0;
2895                                 movey[5]=0;
2896                                 /*
2897                                 for(i=0;i<255;i++)menustring[7][i]='\0';
2898                                 sprintf (temp, "Lowest time:");
2899                                 strcpy(menustring[7],temp);
2900                                 for(i=0;i<20;i++)if(menustring[7][i]=='\0')menustring[7][i]=' ';
2901                                 menustring[7][20]='\0';
2902                                 sprintf (temp, "%d",(int)accountactive->getCampaignFasttime());
2903                                 strcat(menustring[7],temp);
2904                                 startx[7]=200;
2905                                 endx[7]=startx[7]+strlen(menustring[7])*10;
2906                                 starty[7]=130;
2907                                 endy[7]=starty[7]+20;
2908                                 movex[7]=0;
2909                                 movey[7]=0;*/
2910                         }
2911                         if (mainmenu==18) {
2912                                 nummenuitems=4;
2913                                 sprintf (menustring[0], "Stereo mode: %s", StereoModeName(newstereomode));
2914                                 startx[0]=70;
2915                                 starty[0]=400;
2916                                 endx[0]=startx[0]+strlen(menustring[0])*10;
2917                                 endy[0]=starty[0]+20;
2918                                 movex[0]=0;
2919                                 movey[0]=0;
2920                                 
2921                                 sprintf (menustring[1], "Stereo separation: %.3f", stereoseparation);
2922                                 startx[1]=10;
2923                                 starty[1]=360;
2924                                 endx[1]=startx[1]+strlen(menustring[1])*10;
2925                                 endy[1]=starty[1]+20;
2926                                 movex[1]=0;
2927                                 movey[1]=0;
2928
2929                                 sprintf (menustring[2], "Reverse stereo: %s", stereoreverse ? "Yes" : "No");
2930                                 startx[2]=40;
2931                                 starty[2]=320;
2932                                 endx[2]=startx[2]+strlen(menustring[2])*10;
2933                                 endy[2]=starty[2]+20;
2934                                 movex[2]=0;
2935                                 movey[2]=0;
2936                                 
2937                                 sprintf (menustring[3], "Back");
2938                                 startx[3]=10;
2939                                 endx[3]=startx[3]+strlen(menustring[3])*10;
2940                                 starty[3]=10;
2941                                 endy[3]=starty[3]+20;
2942                                 movex[3]=0;
2943                                 movey[3]=0;                             
2944                         }
2945                 }
2946
2947                 if(mainmenu==1||mainmenu==2){
2948                         nummenuitems=7;
2949                         startx[0]=150;
2950                         starty[0]=480-128;
2951                         endx[0]=150+256;
2952                         endy[0]=480;
2953                         movex[0]=0;
2954                         movey[0]=0;
2955
2956                         startx[1]=18;
2957                         starty[1]=480-152-32;
2958                         endx[1]=18+128;
2959                         endy[1]=480-152;
2960                         movex[1]=0;
2961                         movey[1]=0;
2962
2963                         startx[2]=18;
2964                         starty[2]=480-228-32;
2965                         endx[2]=2+128;
2966                         endy[2]=480-228;
2967                         movex[2]=0;
2968                         movey[2]=0;
2969
2970                         if(mainmenu==1){
2971                                 startx[3]=18;
2972                                 starty[3]=480-306-32;
2973                                 endx[3]=22+64;
2974                                 endy[3]=480-306;
2975                                 movex[3]=0;
2976                                 movey[3]=0;
2977                         }
2978
2979                         if(mainmenu==2){
2980                                 startx[3]=18;
2981                                 starty[3]=480-306-32;
2982                                 endx[3]=22+128;
2983                                 endy[3]=480-306;
2984                                 movex[3]=0;
2985                                 movey[3]=0;
2986                         }
2987
2988                         /*startx[4]=150;
2989                         starty[4]=480-256;
2990                         endx[4]=150+256;
2991                         endy[4]=480;
2992                         */
2993                         if(anim==0){
2994                                 startx[4]=380;
2995                                 starty[4]=480-140-256;
2996                                 endx[4]=380+256;
2997                                 endy[4]=480-140;
2998                                 movex[4]=80;
2999                                 movey[4]=0;
3000
3001                                 startx[5]=145;
3002                                 starty[5]=480-138-256;
3003                                 endx[5]=145+256;
3004                                 endy[5]=480-138;
3005                                 movex[5]=40;
3006                                 movey[5]=0;
3007
3008                                 startx[6]=254;
3009                                 starty[6]=480-144-256;
3010                                 endx[6]=254+256;
3011                                 endy[6]=480-144;
3012                                 movex[6]=20;
3013                                 movey[6]=0;
3014                         }
3015                         if(anim==1){
3016                                 startx[4]=180;
3017                                 starty[4]=480-140-256;
3018                                 endx[4]=180+256;
3019                                 endy[4]=480-140;
3020                                 movex[4]=80;
3021                                 movey[4]=0;
3022
3023                                 startx[5]=500;
3024                                 starty[5]=480-138-256;
3025                                 endx[5]=500+256;
3026                                 endy[5]=480-138;
3027                                 movex[5]=40;
3028                                 movey[5]=0;
3029
3030                                 startx[6]=340;
3031                                 starty[6]=480-144-256;
3032                                 endx[6]=340+256;
3033                                 endy[6]=480-144;
3034                                 movex[6]=20;
3035                                 movey[6]=0;
3036                         }
3037                         if(anim==2){
3038                                 startx[4]=460;
3039                                 starty[4]=480-140-256;
3040                                 endx[4]=460+256;
3041                                 endy[4]=480-140;
3042                                 movex[4]=50;
3043                                 movey[4]=0;
3044
3045                                 startx[5]=295;
3046                                 starty[5]=480-150-256;
3047                                 endx[5]=295+256;
3048                                 endy[5]=480-138;
3049                                 movex[5]=-10;
3050                                 movey[5]=0;
3051
3052                                 startx[6]=204;
3053                                 starty[6]=480-144-256;
3054                                 endx[6]=204+256;
3055                                 endy[6]=480-144;
3056                                 movex[6]=-30;
3057                                 movey[6]=0;
3058                         }
3059                         if(anim==3){
3060                                 startx[4]=150;
3061                                 starty[4]=480-140-256;
3062                                 endx[4]=200+256;
3063                                 endy[4]=480-140;
3064                                 movex[4]=80;
3065                                 movey[4]=0;
3066
3067                                 startx[5]=350;
3068                                 starty[5]=480-150-256;
3069                                 endx[5]=350+256;
3070                                 endy[5]=480-138;
3071                                 movex[5]=5;
3072                                 movey[5]=0;
3073
3074                                 startx[6]=500;
3075                                 starty[6]=480-144-256;
3076                                 endx[6]=500+256;
3077                                 endy[6]=480-144;
3078                                 movex[6]=-10;
3079                                 movey[6]=0;
3080                         }
3081                         if(anim==4){
3082                                 startx[4]=190;
3083                                 starty[4]=480-100-256;
3084                                 endx[4]=190+256;
3085                                 endy[4]=480-100;
3086                                 movex[4]=-30;
3087                                 movey[4]=0;
3088
3089                                 startx[5]=185;
3090                                 starty[5]=480-120-256;
3091                                 endx[5]=185+256;
3092                                 endy[5]=480-120;
3093                                 movex[5]=-5;
3094                                 movey[5]=0;
3095
3096                                 startx[6]=400;
3097                                 starty[6]=480-144-256;
3098                                 endx[6]=400+256;
3099                                 endy[6]=480-144;
3100                                 movex[6]=20;
3101                                 movey[6]=0;
3102                         }
3103                 }
3104
3105                 selected=-1;
3106
3107                 if(mainmenu==1||mainmenu==2)
3108                         for(i=1;i<4;i++){
3109                                 if((mousecoordh/screenwidth*640)>startx[i]&&(mousecoordh/screenwidth*640)<endx[i]&&480-(mousecoordv/screenheight*480)>starty[i]&&480-(mousecoordv/screenheight*480)<endy[i]){
3110                                         selected=i;
3111                                 }
3112                         }
3113
3114                 if(mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==8||mainmenu==9||mainmenu==10||mainmenu==18)
3115                         for(i=0;i<nummenuitems;i++){
3116                                 if((mousecoordh/screenwidth*640)>startx[i]&&(mousecoordh/screenwidth*640)<endx[i]&&480-(mousecoordv/screenheight*480)>starty[i]&&480-(mousecoordv/screenheight*480)<endy[i]){
3117                                         if(mainmenu!=5)selected=i;
3118                                         if(mainmenu==5&&(i!=0&&i!=6))selected=i;
3119                                         if(mainmenu==9&&(i!=numchallengelevels+1))selected=i; // seem useless, if mainmenu==9 then mainmenu!=5, so selected==i.
3120                                 }
3121                         }
3122
3123                 for(i=0;i<nummenuitems;i++){
3124                         if(selected==i) {
3125                                 selectedlong[i]+=multiplier*5;
3126                                 if(selectedlong[i]>1) selectedlong[i]=1;
3127                         } else {
3128                                 selectedlong[i]-=multiplier*5;
3129                                 if(selectedlong[i]<0) selectedlong[i]=0;        
3130                         }
3131                         offsetx[i]=(startx[i]+endx[i])/2-(mousecoordh/screenwidth*640);
3132                         offsety[i]=(starty[i]+endy[i])/2-(480-(mousecoordv/screenheight*480));
3133                         offsetx[i]*=.06f;
3134                         offsety[i]*=.06f;
3135                         offsetx[i]=0;
3136                         offsety[i]=0;
3137                         if(i>=4&&(mainmenu==1||mainmenu==2)){
3138                                 selectedlong[i]=0;
3139                                 offsetx[i]=(startx[i]+endx[i]+movex[i]*transition)/2-(640+190)/2;
3140                                 offsety[i]=(starty[i]+endy[i]+movey[i]*transition)/2-(336+150)/2;
3141                                 offsetx[i]*=.06f;
3142                                 offsety[i]*=.06f;
3143                         }
3144                 }
3145
3146                 if(mainmenu==1||mainmenu==2){
3147                         glClear(GL_DEPTH_BUFFER_BIT);
3148                         glEnable(GL_ALPHA_TEST);
3149                         glAlphaFunc(GL_GREATER, 0.001f);
3150                         glEnable(GL_TEXTURE_2D);
3151                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
3152                         glDisable(GL_CULL_FACE);
3153                         glDisable(GL_LIGHTING);
3154                         glDepthMask(0);
3155                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3156                         glPushMatrix();                                                                         // Store The Projection Matrix
3157                                 glLoadIdentity();                                                                       // Reset The Projection Matrix
3158                                 glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
3159                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3160                                 glPushMatrix();                                                                         // Store The Modelview Matrix
3161                                         glLoadIdentity();                                                               // Reset The Modelview Matrix
3162                                         glTranslatef(screenwidth/2,screenheight/2,0);
3163                                         glPushMatrix();
3164                                                 glScalef((float)screenwidth/2,(float)screenheight/2,1);
3165                                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
3166                                                 glDisable(GL_BLEND);
3167                                                 glColor4f(0,0,0,1.0);
3168                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
3169                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
3170                                                 glDisable(GL_TEXTURE_2D);
3171                                                 glPushMatrix();
3172                                                         //glScalef(.25,.25,.25);
3173                                                         glBegin(GL_QUADS);
3174                                                         glTexCoord2f(0,0);
3175                                                         glVertex3f(-1,          -1,      0.0f);
3176                                                         glTexCoord2f(1,0);
3177                                                         glVertex3f(1,   -1,      0.0f);
3178                                                         glTexCoord2f(1,1);
3179                                                         glVertex3f(1,   1, 0.0f);
3180                                                         glTexCoord2f(0,1);
3181                                                         glVertex3f(-1,  1, 0.0f);
3182                                                         glEnd();
3183                                                 glPopMatrix();
3184                                                 glEnable(GL_BLEND);
3185                                                 glColor4f(0.4,0.4,0.4,1.0);
3186                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
3187                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
3188                                                 glEnable(GL_TEXTURE_2D);
3189                                                 glBindTexture( GL_TEXTURE_2D, Mainmenuitems[4]);
3190                                                 glPushMatrix();
3191                                                         //glScalef(.25,.25,.25);
3192                                                         glBegin(GL_QUADS);
3193                                                         glTexCoord2f(0,0);
3194                                                         glVertex3f(-1,          -1,      0.0f);
3195                                                         glTexCoord2f(1,0);
3196                                                         glVertex3f(1,   -1,      0.0f);
3197                                                         glTexCoord2f(1,1);
3198                                                         glVertex3f(1,   1, 0.0f);
3199                                                         glTexCoord2f(0,1);
3200                                                         glVertex3f(-1,  1, 0.0f);
3201                                                         glEnd();
3202                                                 glPopMatrix();
3203                                         glPopMatrix();
3204                                 glPopMatrix();
3205                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3206                         glPopMatrix();
3207
3208                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3209                         glPushMatrix();                                                                         // Store The Projection Matrix
3210                                 glLoadIdentity();                                                                       // Reset The Projection Matrix
3211                                 glOrtho(0,640,0,480,-100,100);                                          // Set Up An Ortho Screen
3212                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3213                                 glPushMatrix();                                                                         // Store The Modelview Matrix
3214                                         glLoadIdentity();                                                               // Reset The Modelview Matrix
3215                                         glPushMatrix();
3216                                                 glDisable(GL_TEXTURE_2D);
3217                                                 glColor4f(1,0,0,1);
3218                                         glPopMatrix();
3219                                 glPopMatrix();
3220                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3221                         glPopMatrix();
3222                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3223
3224                 }
3225
3226                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3227                 glPushMatrix();                                                                         // Store The Projection Matrix
3228                 glLoadIdentity();                                                                       // Reset The Projection Matrix
3229                 glOrtho(0,640,0,480,-100,100);                                          // Set Up An Ortho Screen
3230                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3231                 glPushMatrix();                                                                         // Store The Modelview Matrix
3232                 glLoadIdentity();                                                               // Reset The Modelview Matrix
3233                 glEnable(GL_TEXTURE_2D);
3234                 for(j=0;j<nummenuitems;j++)
3235                 {
3236                         if(j<=3||(mainmenu!=1&&mainmenu!=2))
3237                         {
3238                                 //glDisable(GL_BLEND);
3239                                 glEnable(GL_ALPHA_TEST);
3240                                 glEnable(GL_BLEND);
3241                                 //glDisable(GL_ALPHA_TEST);
3242                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
3243                                 if(mainmenu==1||mainmenu==2)
3244                                 {
3245                                         glColor4f(1,1,1,1);
3246                                         glBlendFunc(GL_SRC_ALPHA,GL_ONE);
3247                                         glBindTexture( GL_TEXTURE_2D, Mainmenuitems[j]);
3248                                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
3249                                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
3250                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3251                                         glPushMatrix();
3252                                                 glBegin(GL_QUADS);
3253                                                 glTexCoord2f(0,0);
3254                                                 glVertex3f(startx[j]+movex[j]*transition,       starty[j]+movey[j]*transition,   0.0f);
3255                                                 glTexCoord2f(1,0);
3256                                                 glVertex3f(endx[j]+movex[j]*transition,         starty[j]+movey[j]*transition,   0.0f);
3257                                                 glTexCoord2f(1,1);
3258                                                 glVertex3f(endx[j]+movex[j]*transition,         endy[j]+movey[j]*transition, 0.0f);
3259                                                 glTexCoord2f(0,1);
3260                                                 glVertex3f(startx[j]+movex[j]*transition,       endy[j]+movey[j]*transition, 0.0f);
3261                                                 glEnd();
3262                                         glPopMatrix();
3263                                         glEnable(GL_BLEND);
3264                                         //glDisable(GL_ALPHA_TEST);
3265                                         if(j<4)glBlendFunc(GL_SRC_ALPHA,GL_ONE);
3266                                         for(i=0;i<10;i++)
3267                                         {
3268                                                 if(1-((float)i)/10-(1-selectedlong[j])>0)
3269                                                 {
3270                                                         glColor4f(1,1,1,(1-((float)i)/10-(1-selectedlong[j]))*.25);
3271                                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3272                                                         glPushMatrix();
3273                                                                 glBegin(GL_QUADS);
3274                                                                 glTexCoord2f(0,0);
3275                                                                 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);
3276                                                                 glTexCoord2f(1,0);
3277                                                                 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);
3278                                                                 glTexCoord2f(1,1);
3279                                                                 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);
3280                                                                 glTexCoord2f(0,1);
3281                                                                 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);
3282                                                                 glEnd();
3283                                                         glPopMatrix();
3284                                                 }
3285                                         }
3286                                 }
3287                                 if(mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==8||mainmenu==9||mainmenu==10||mainmenu==18)
3288                                 {
3289                                         if(mainmenu!=5||j<6)
3290                                         {
3291                                                 glColor4f(1,0,0,1);
3292                                                 if(mainmenu==9&&j>accountactive->getProgress()&&j<numchallengelevels)glColor4f(0.5,0,0,1);
3293                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3294                                                 glPushMatrix();
3295                                                         if(mainmenu!=7||j!=0||!entername)
3296                                                                 text.glPrint(startx[j],starty[j],menustring[j],0,1,640,480);
3297                                                         else
3298                                                         {
3299                                                                 if(displayblink){
3300                                                                         sprintf (string, "_");
3301                                                                         text.glPrint(startx[j]+(float)(displayselected)*10,starty[j],string,0,1,640,480);
3302                                                                 }
3303                                                                 for(l=0;l<displaychars[0];l++){
3304                                                                         sprintf (string, "%c",displaytext[0][l]);
3305                                                                         text.glPrint(startx[j]+l*10,starty[j],string,0,1,640,480);
3306                                                                 }
3307                                                         }
3308                                                 glPopMatrix();
3309                                                 glEnable(GL_BLEND);
3310                                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
3311                                                 for(i=0;i<15;i++)
3312                                                 {
3313                                                         if(1-((float)i)/15-(1-selectedlong[j])>0)
3314                                                         {
3315                                                                 glColor4f(1,0,0,(1-((float)i)/10-(1-selectedlong[j]))*.25);
3316                                                                 if(mainmenu==9&&j>accountactive->getProgress()&&j<numchallengelevels)glColor4f(0.5,0,0,(1-((float)i)/10-(1-selectedlong[j]))*.25);
3317                                                                 if(mainmenu==11&&j>accountactive->getProgress()&&j<numchallengelevels)glColor4f(0.5,0,0,(1-((float)i)/10-(1-selectedlong[j]))*.25);
3318                                                                 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);
3319                                                                 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);
3320                                                                 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);
3321                                                                 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);
3322                                                                 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);
3323                                                                 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);
3324                                                                 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);
3325                                                                 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);
3326                                                                 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);
3327                                                         }
3328                                                 }
3329                                         }
3330                                         else
3331                                         {
3332                                                 glClear(GL_DEPTH_BUFFER_BIT);
3333                                                 glEnable(GL_ALPHA_TEST);
3334                                                 glAlphaFunc(GL_GREATER, 0.001f);
3335                                                 glEnable(GL_TEXTURE_2D);
3336                                                 glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
3337                                                 glDisable(GL_CULL_FACE);
3338                                                 glDisable(GL_LIGHTING);
3339                                                 if(j==6)glColor4f(1,1,1,1);
3340                                                 else glColor4f(1,0,0,1);
3341
3342                                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3343                                                 glPushMatrix();                                                                         // Store The Projection Matrix
3344                                                         glLoadIdentity();                                                                       // Reset The Projection Matrix
3345                                                         glOrtho(0,640,0,480,-100,100);                                          // Set Up An Ortho Screen
3346                                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3347                                                         glPushMatrix();                                                                         // Store The Modelview Matrix
3348                                                                 glLoadIdentity();                                                               // Reset The Modelview Matrix
3349                                                                 glPushMatrix();
3350
3351                                                                         //Draw world, draw map
3352                                                                         glTranslatef(2,-5,0);
3353
3354                                                                         if(j>6&&j<nummenuitems-1)
3355                                                                         {
3356                                                                                 XYZ linestart,lineend,offset;
3357                                                                                 XYZ fac;
3358                                                                                 float startsize;
3359                                                                                 float endsize;
3360                                                                                 linestart=0;
3361                                                                                 lineend=0;
3362                                                                                 offset=0;
3363                                                                                 //float linestartx,lineendx,linestarty,lineendy,offsetx,offsety;
3364                                                                                 linestart.x=(startx[j]+endx[j])/2;
3365                                                                                 linestart.y=(starty[j]+endy[j])/2;
3366                                                                                 if(j>=6+accountactive->getCampaignChoicesMade()){
3367                                                                                         linestart.x=(startx[6+accountactive->getCampaignChoicesMade()]+endx[6+accountactive->getCampaignChoicesMade()])/2;
3368                                                                                         linestart.y=(starty[6+accountactive->getCampaignChoicesMade()]+endy[6+accountactive->getCampaignChoicesMade()])/2;
3369                                                                                 }
3370                                                                                 lineend.x=(startx[j+1]+endx[j+1])/2;
3371                                                                                 lineend.y=(starty[j+1]+endy[j+1])/2;
3372                                                                                 offset=lineend-linestart;
3373                                                                                 fac=offset;
3374                                                                                 Normalise(&fac);
3375                                                                                 offset=DoRotation(offset,0,0,90);
3376                                                                                 Normalise(&offset);
3377                                                                                 glDisable(GL_TEXTURE_2D);                                                       
3378
3379                                                                                 if(j<6+accountactive->getCampaignChoicesMade()){
3380                                                                                         glColor4f(0.5,0,0,1);
3381                                                                                         endsize=.5;
3382                                                                                 } else {
3383                                                                                         glColor4f(1,0,0,1);
3384                                                                                         endsize=1;
3385                                                                                 }
3386                                                                                 startsize=.5;
3387
3388                                                                                 linestart+=fac*4*startsize;
3389                                                                                 lineend-=fac*4*endsize;
3390
3391                                                                                 if(!(j>7+accountactive->getCampaignChoicesMade()+campaignchoicenum)){
3392                                                                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3393                                                                                         glPushMatrix();
3394                                                                                                 glBegin(GL_QUADS);
3395                                                                                                 glTexCoord2f(0,0);
3396                                                                                                 glVertex3f(linestart.x-offset.x*startsize,      linestart.y-offset.y*startsize,          0.0f);
3397                                                                                                 glTexCoord2f(1,0);
3398                                                                                                 glVertex3f(linestart.x+offset.x*startsize,      linestart.y+offset.y*startsize,          0.0f);
3399                                                                                                 glTexCoord2f(1,1);
3400                                                                                                 glVertex3f(lineend.x+offset.x*endsize,          lineend.y+offset.y*endsize, 0.0f);
3401                                                                                                 glTexCoord2f(0,1);
3402                                                                                                 glVertex3f(lineend.x-offset.x*endsize,          lineend.y-offset.y*endsize, 0.0f);
3403                                                                                                 glEnd();
3404                                                                                         glPopMatrix();
3405                                                                                 }
3406                                                                                 glEnable(GL_TEXTURE_2D);
3407                                                                         }
3408
3409
3410                                                                         if(j==6)glBindTexture( GL_TEXTURE_2D, Mainmenuitems[7]);
3411                                                                         else glBindTexture( GL_TEXTURE_2D, Mapcircletexture);
3412                                                                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
3413                                                                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
3414                                                                         if(j-7<accountactive->getCampaignChoicesMade())glColor4f(0.5,0,0,1);
3415                                                                         if(j-7>=accountactive->getCampaignChoicesMade())glColor4f(1,0,0,1);
3416                                                                         if(j==6)glColor4f(1,1,1,1);
3417                                                                         XYZ midpoint;
3418                                                                         float itemsize;
3419                                                                         itemsize=abs(startx[j]-endx[j])/2;
3420                                                                         midpoint=0;
3421                                                                         midpoint.x=(startx[j]+endx[j])/2;
3422                                                                         midpoint.y=(starty[j]+endy[j])/2;
3423                                                                         if(j>6&&(j-7<accountactive->getCampaignChoicesMade()))itemsize*=.5;
3424                                                                         if(!(j-7>accountactive->getCampaignChoicesMade()+campaignchoicenum))
3425                                                                         {
3426                                                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3427                                                                                 glPushMatrix();
3428                                                                                         glBegin(GL_QUADS);
3429                                                                                         glTexCoord2f(0,0);
3430                                                                                         glVertex3f(midpoint.x-itemsize+movex[j]*transition,     midpoint.y-itemsize+movey[j]*transition,         0.0f);
3431                                                                                         glTexCoord2f(1,0);
3432                                                                                         glVertex3f(midpoint.x+itemsize+movex[j]*transition,             midpoint.y-itemsize+movey[j]*transition,         0.0f);
3433                                                                                         glTexCoord2f(1,1);
3434                                                                                         glVertex3f(midpoint.x+itemsize+movex[j]*transition,             midpoint.y+itemsize+movey[j]*transition, 0.0f);
3435                                                                                         glTexCoord2f(0,1);
3436                                                                                         glVertex3f(midpoint.x-itemsize+movex[j]*transition,     midpoint.y+itemsize+movey[j]*transition, 0.0f);
3437                                                                                         glEnd();
3438                                                                                 glPopMatrix();
3439                                                                                 glEnable(GL_BLEND);
3440                                                                                 //glDisable(GL_ALPHA_TEST);
3441                                                                                 if(j<4)glBlendFunc(GL_SRC_ALPHA,GL_ONE);
3442                                                                                 for(i=0;i<10;i++)
3443                                                                                 {
3444                                                                                         if(1-((float)i)/10-(1-selectedlong[j])>0)
3445                                                                                         {
3446                                                                                                 glColor4f(1,0,0,(1-((float)i)/10-(1-selectedlong[j]))*.25);
3447                                                                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3448                                                                                                 glPushMatrix();
3449                                                                                                         glBegin(GL_QUADS);
3450                                                                                                         glTexCoord2f(0,0);
3451                                                                                                         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);
3452                                                                                                         glTexCoord2f(1,0);
3453                                                                                                         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);
3454                                                                                                         glTexCoord2f(1,1);
3455                                                                                                         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);
3456                                                                                                         glTexCoord2f(0,1);
3457                                                                                                         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);
3458                                                                                                         glEnd();
3459                                                                                                 glPopMatrix();
3460                                                                                         }
3461                                                                                 }
3462                                                                         }
3463                                                                 glPopMatrix();
3464                                                         glPopMatrix();
3465                                                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3466                                                 glPopMatrix();
3467                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3468
3469                                                 if(j-7>=accountactive->getCampaignChoicesMade()){
3470                                                         text.glPrintOutlined(0.9,0,0,startx[j]+10,starty[j]-4,menustring[j],0,0.6,640,480);
3471                                                         glDisable(GL_DEPTH_TEST);
3472                                                 }
3473                                         }
3474                                 }
3475                         }
3476                 }
3477                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3478                 glPopMatrix();
3479                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3480                 glPopMatrix();
3481
3482                         if(mainmenu==1||mainmenu==2)
3483                                 if(transition<.1||transition>.9){
3484                                         glClear(GL_DEPTH_BUFFER_BIT);
3485                                         glEnable(GL_ALPHA_TEST);
3486                                         glAlphaFunc(GL_GREATER, 0.001f);
3487                                         glEnable(GL_TEXTURE_2D);
3488                                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
3489                                         glDisable(GL_CULL_FACE);
3490                                         glDisable(GL_LIGHTING);
3491                                         glDepthMask(0);
3492                                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3493                                         glPushMatrix();                                                                         // Store The Projection Matrix
3494                                                 glLoadIdentity();                                                                       // Reset The Projection Matrix
3495                                                 glOrtho(0,640,0,480,-100,100);                                          // Set Up An Ortho Screen
3496                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3497                                                 glPushMatrix();                                                                         // Store The Modelview Matrix
3498                                                         glLoadIdentity();                                                               // Reset The Modelview Matrix
3499                                                         glPushMatrix();
3500                                                                 glDisable(GL_TEXTURE_2D);
3501                                                                 if(transition<.1)
3502                                                                         glColor4f(1,0,0,1-(transition*10));
3503                                                                 if(transition>.9)
3504                                                                         glColor4f(1,0,0,1-((1-transition)*10));
3505                                                         glPopMatrix();
3506                                                 glPopMatrix();
3507                                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3508                                         glPopMatrix();
3509                                 }
3510
3511                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3512                         glPushMatrix();                                                                         // Store The Projection Matrix
3513                                 glLoadIdentity();                                                                       // Reset The Projection Matrix
3514                                 glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
3515                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3516                                 glPushMatrix();                                                                         // Store The Modelview Matrix
3517                                         glLoadIdentity();                                                               // Reset The Modelview Matrix
3518                                         glTranslatef(screenwidth/2,screenheight/2,0);
3519                                         glPushMatrix();
3520                                                 glScalef((float)screenwidth/2,(float)screenheight/2,1);
3521                                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
3522                                                 glEnable(GL_BLEND);
3523                                                 glEnable(GL_TEXTURE_2D);
3524                                                 glColor4f(1,1,1,1);
3525                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
3526                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
3527                                         glPopMatrix();
3528                                         if(!waiting) { // hide the cursor while waiting for a key
3529                                                 glPushMatrix();
3530                                                         glTranslatef(mousecoordh-screenwidth/2,mousecoordv*-1+screenheight/2,0);
3531                                                         glScalef((float)screenwidth/64,(float)screenwidth/64,1);
3532                                                         glTranslatef(1,-1,0);
3533                                                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
3534                                                         glColor4f(1,1,1,1);
3535                                                         glBindTexture( GL_TEXTURE_2D, cursortexture);
3536                                                         glPushMatrix();
3537                                                                 //glScalef(.25,.25,.25);
3538                                                                 glBegin(GL_QUADS);
3539                                                                 glTexCoord2f(0,0);
3540                                                                 glVertex3f(-1,          -1,      0.0f);
3541                                                                 glTexCoord2f(1,0);
3542                                                                 glVertex3f(1,   -1,      0.0f);
3543                                                                 glTexCoord2f(1,1);
3544                                                                 glVertex3f(1,   1, 0.0f);
3545                                                                 glTexCoord2f(0,1);
3546                                                                 glVertex3f(-1,  1, 0.0f);
3547                                                                 glEnd();
3548                                                         glPopMatrix();
3549                                                 glPopMatrix();
3550                                         }
3551                                 glPopMatrix();
3552                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3553                         glPopMatrix();
3554
3555
3556                         if(flashamount>0)
3557                         {
3558                                 //printf("Flash amount: %f, delay %i\n", flashamount, flashdelay);
3559                                 if(flashamount>1)flashamount=1;
3560                                 if(flashdelay<=0)flashamount-=multiplier;
3561                                 flashdelay--;
3562                                 if(flashamount<0)flashamount=0;
3563                                 glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
3564                                 glDisable(GL_CULL_FACE);
3565                                 glDisable(GL_LIGHTING);
3566                                 glDisable(GL_TEXTURE_2D);
3567                                 glDepthMask(0);
3568                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3569                                 glPushMatrix();                                                                         // Store The Projection Matrix
3570                                         glLoadIdentity();                                                                       // Reset The Projection Matrix
3571                                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
3572                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3573                                         glPushMatrix();                                                                         // Store The Modelview Matrix
3574                                                 glLoadIdentity();                                                               // Reset The Modelview Matrix
3575                                                 glScalef(screenwidth,screenheight,1);
3576                                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
3577                                                 glEnable(GL_BLEND);
3578                                                 glColor4f(flashr,flashg,flashb,flashamount);
3579                                                 glBegin(GL_QUADS);
3580                                                 glVertex3f(0,           0,       0.0f);
3581                                                 glVertex3f(256, 0,       0.0f);
3582                                                 glVertex3f(256, 256, 0.0f);
3583                                                 glVertex3f(0,   256, 0.0f);
3584                                                 glEnd();
3585                                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3586                                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
3587                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3588                                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
3589                                 glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
3590                                 glEnable(GL_CULL_FACE);
3591                                 glDisable(GL_BLEND);
3592                                 glDepthMask(1);
3593                         }
3594         }
3595
3596         if(freeze||winfreeze||(mainmenu&&gameon)||(!gameon&&gamestarted)||(!gameon&&gamestarted)){
3597                 tempmult=multiplier;
3598                 multiplier=0;
3599         }
3600
3601         //glFlush();
3602         if ( side == stereoRight || side == stereoCenter ) {
3603                 if(drawmode!=motionblurmode||mainmenu){
3604                         swap_gl_buffers();
3605                 }
3606         }
3607
3608         //myassert(glGetError() == GL_NO_ERROR);
3609         glDrawBuffer(GL_BACK);
3610         glReadBuffer(GL_BACK);
3611         //glFlush();
3612
3613         weapons.DoStuff();
3614
3615         if(drawtoggle==2)drawtoggle=0;
3616
3617         if(freeze||winfreeze||(mainmenu&&gameon)||(!gameon&&gamestarted)){
3618                 multiplier=tempmult;
3619         }
3620         //Jordan fixed your warning!
3621         return 0;
3622 }
3623