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