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