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