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