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