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