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