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