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