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