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