2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010-2017 - Lugaru contributors (see AUTHORS file)
5 This file is part of Lugaru.
7 Lugaru is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 Lugaru is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Lugaru. If not, see <http://www.gnu.org/licenses/>.
23 #include "Audio/openal_wrapper.hpp"
24 #include "Level/Awards.hpp"
25 #include "Level/Dialog.hpp"
26 #include "Level/Hotspot.hpp"
27 #include "Menu/Menu.hpp"
28 #include "Tutorial.hpp"
29 #include "Utils/Input.hpp"
32 extern int environment;
33 extern float texscale;
35 extern Terrain terrain;
36 extern float multiplier;
37 extern float viewdistance;
38 extern float fadestart;
39 extern float screenwidth, screenheight;
40 extern int kTextureSize;
41 extern FRUSTUM frustum;
44 extern float usermousesensitivity;
45 extern float camerashake;
47 extern float slomodelay;
48 extern bool ismotionblur;
50 extern float blackout;
51 extern bool damageeffects;
53 extern bool texttoggle;
54 extern float blurness;
55 extern float targetblurness;
56 extern float playerdist;
57 extern bool cellophane;
59 extern float flashamount, flashr, flashg, flashb;
60 extern int flashdelay;
62 extern float motionbluramount;
64 extern bool alwaysblur;
65 extern bool velocityblur;
68 extern int bloodtoggle;
69 extern int difficulty;
70 extern bool decalstoggle;
71 extern float texdetail;
72 extern bool musictoggle;
73 extern float smoketex;
74 extern bool againbonus;
75 extern float damagedealt;
76 extern bool invertmouse;
79 extern bool winfreeze;
81 extern bool gamestart;
83 extern bool gamestarted;
85 extern bool showdamagebar;
88 int numboundaries = 0;
102 void Game::flash(float amount, int delay) // shouldn't be that way, these should be attributes and Person class should not change rendering.
107 flashamount = amount;
113 /*********************> DrawGLScene() <*****/
114 int Game::DrawGLScene(StereoSide side)
116 static float texcoordwidth, texcoordheight;
117 static float texviewwidth, texviewheight;
118 static XYZ checkpoint;
119 static float tempmult;
122 static int drawmode = 0;
124 if (stereomode == stereoAnaglyph) {
127 glColorMask(0.0, 1.0, 1.0, 1.0);
130 glColorMask(1.0, 0.0, 0.0, 1.0);
136 glColorMask(1.0, 1.0, 1.0, 1.0);
138 if (stereomode == stereoHorizontalInterlaced ||
139 stereomode == stereoVerticalInterlaced) {
140 glStencilFunc(side == stereoLeft ? GL_NOTEQUAL : GL_EQUAL, 0x01, 0x01);
144 if (freeze || winfreeze || (mainmenu && gameon) || (!gameon && gamestarted)) {
145 tempmult = multiplier;
151 numboundaries = mapradius * 2;
152 if (numboundaries > 360) {
155 for (int i = 0; i < numboundaries; i++) {
158 boundary[i] = mapcenter + DoRotation(boundary[i] * mapradius, 0, i * (360 / ((float)(numboundaries))), 0);
167 int olddrawmode = drawmode;
168 if (ismotionblur && !loading) {
169 if ((findLengthfast(&Person::players[0]->velocity) > 200) && velocityblur && !cameramode) {
170 drawmode = motionblurmode;
171 motionbluramount = 200 / (findLengthfast(&Person::players[0]->velocity));
174 if (Person::players[0]->damage - Person::players[0]->superpermanentdamage > (Person::players[0]->damagetolerance - Person::players[0]->superpermanentdamage) * 1 / 2 && damageeffects && !cameramode) {
175 drawmode = doublevisionmode;
180 if (slomo && !loading) {
182 drawmode = motionblurmode;
184 motionbluramount = .2;
185 slomodelay -= multiplier;
186 if (slomodelay < 0) {
192 if ((!changed && !slomo) || loading) {
193 drawmode = normalmode;
194 if (ismotionblur && (/*fps>100||*/ alwaysblur)) {
195 if (olddrawmode != realmotionblurmode) {
200 drawmode = realmotionblurmode;
201 } else if (olddrawmode == realmotionblurmode) {
208 if (freeze || winfreeze || (mainmenu && gameon) || (!gameon && gamestarted)) {
209 drawmode = normalmode;
211 if ((freeze || winfreeze) && ismotionblur && !mainmenu) {
212 drawmode = radialzoommode;
215 if (winfreeze || mainmenu) {
216 drawmode = normalmode;
219 if (drawtoggle != 2) {
220 drawtoggle = 1 - drawtoggle;
223 if (!texcoordwidth) {
224 texviewwidth = kTextureSize;
225 if (texviewwidth > screenwidth) {
226 texviewwidth = screenwidth;
228 texviewheight = kTextureSize;
229 if (texviewheight > screenheight) {
230 texviewheight = screenheight;
233 texcoordwidth = screenwidth / kTextureSize;
234 texcoordheight = screenheight / kTextureSize;
235 if (texcoordwidth > 1) {
238 if (texcoordheight > 1) {
243 glDrawBuffer(GL_BACK);
244 glReadBuffer(GL_BACK);
246 static XYZ terrainlight;
247 static float distance;
248 if (drawmode == normalmode) {
249 Game::ReSizeGLScene(90, .1f);
251 glViewport(0, 0, texviewwidth, texviewheight);
253 glDepthFunc(GL_LEQUAL);
255 glAlphaFunc(GL_GREATER, 0.0001f);
256 glEnable(GL_ALPHA_TEST);
257 glClearColor(0.25f, 0.25f, 0.25f, 1.0f);
258 glClear(GL_DEPTH_BUFFER_BIT);
260 glMatrixMode(GL_MODELVIEW);
261 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
264 // Move the camera for the current eye's point of view.
265 // Reverse the movement if we're reversing stereo
266 glTranslatef((stereoseparation / 2) * side * (stereoreverse ? -1 : 1), 0, 0);
269 if (!cameramode && !freeze && !winfreeze) {
271 glRotatef(float(Random() % 100) / 10 * camerashake /*+(woozy*woozy)/10*/, 0, 0, 1);
273 glRotatef(pitch + sin(woozy / 2) * (Person::players[0]->damage / Person::players[0]->damagetolerance) * 5, 1, 0, 0);
274 glRotatef(yaw + sin(woozy) * (Person::players[0]->damage / Person::players[0]->damagetolerance) * 5, 0, 1, 0);
276 if (cameramode || freeze || winfreeze) {
277 glRotatef(pitch, 1, 0, 0);
278 glRotatef(yaw, 0, 1, 0);
281 if (environment == desertenvironment) {
282 glRotatef((float)(abs(Random() % 100)) / 3000 - 1, 1, 0, 0);
283 glRotatef((float)(abs(Random() % 100)) / 3000 - 1, 0, 1, 0);
285 SetUpLight(&light, 0);
288 //heat blur effect in desert
289 if (abs(blurness - targetblurness) < multiplier * 10 || abs(blurness - targetblurness) > 2) {
290 blurness = targetblurness;
291 targetblurness = (float)(abs(Random() % 100)) / 40;
293 if (blurness < targetblurness) {
294 blurness += multiplier * 5;
296 blurness -= multiplier * 5;
299 if (environment == desertenvironment) {
301 glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, blurness + .4);
303 glRotatef((float)(abs(Random() % 100)) / 1000, 1, 0, 0);
304 glRotatef((float)(abs(Random() % 100)) / 1000, 0, 1, 0);
307 glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, 0);
309 glTranslatef(-viewer.x, -viewer.y, -viewer.z);
310 frustum.GetFrustum();
312 //make shadow decals on terrain and Object::objects
314 static float size, opacity, rotation;
316 for (unsigned int k = 0; k < Person::players.size(); k++) {
317 if (!Person::players[k]->skeleton.free && Person::players[k]->playerdetail && Person::players[k]->howactive < typesleeping) {
318 if (frustum.SphereInFrustum(Person::players[k]->coords.x, Person::players[k]->coords.y + Person::players[k]->scale * 3, Person::players[k]->coords.z, Person::players[k]->scale * 7) && Person::players[k]->occluded < 25) {
319 for (unsigned int i = 0; i < Person::players[k]->skeleton.joints.size(); i++) {
320 if (Person::players[k]->skeleton.joints[i].label == leftknee || Person::players[k]->skeleton.joints[i].label == rightknee || Person::players[k]->skeleton.joints[i].label == groin) {
321 point = DoRotation(Person::players[k]->skeleton.joints[i].position, 0, Person::players[k]->yaw, 0) * Person::players[k]->scale + Person::players[k]->coords;
323 opacity = .4 - Person::players[k]->skeleton.joints[i].position.y * Person::players[k]->scale / 5 - (Person::players[k]->coords.y - terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z)) / 10;
324 if (k != 0 && Tutorial::active) {
325 opacity = .2 + .2 * sin(smoketex * 6 + i) - Person::players[k]->skeleton.joints[i].position.y * Person::players[k]->scale / 5 - (Person::players[k]->coords.y - terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z)) / 10;
327 terrain.MakeDecal(shadowdecal, point, size, opacity, rotation);
328 for (unsigned int l = 0; l < terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz].size(); l++) {
329 unsigned int j = terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz][l];
330 if (Object::objects[j]->position.y < Person::players[k]->coords.y || Object::objects[j]->type == tunneltype || Object::objects[j]->type == weirdtype) {
331 point = DoRotation(DoRotation(Person::players[k]->skeleton.joints[i].position, 0, Person::players[k]->yaw, 0) * Person::players[k]->scale + Person::players[k]->coords - Object::objects[j]->position, 0, -Object::objects[j]->yaw, 0);
334 if (k != 0 && Tutorial::active) {
335 opacity = .2 + .2 * sin(smoketex * 6 + i);
337 Object::objects[j]->model.MakeDecal(shadowdecal, &point, &size, &opacity, &rotation);
344 if ((Person::players[k]->skeleton.free || Person::players[k]->howactive >= typesleeping) && Person::players[k]->playerdetail) {
345 if (frustum.SphereInFrustum(Person::players[k]->coords.x, Person::players[k]->coords.y, Person::players[k]->coords.z, Person::players[k]->scale * 5) && Person::players[k]->occluded < 25) {
346 for (unsigned i = 0; i < Person::players[k]->skeleton.joints.size(); i++) {
347 if (Person::players[k]->skeleton.joints[i].label == leftknee || Person::players[k]->skeleton.joints[i].label == rightknee || Person::players[k]->skeleton.joints[i].label == groin || Person::players[k]->skeleton.joints[i].label == leftelbow || Person::players[k]->skeleton.joints[i].label == rightelbow || Person::players[k]->skeleton.joints[i].label == neck) {
348 if (Person::players[k]->skeleton.free) {
349 point = Person::players[k]->skeleton.joints[i].position * Person::players[k]->scale + Person::players[k]->coords;
351 point = DoRotation(Person::players[k]->skeleton.joints[i].position, 0, Person::players[k]->yaw, 0) * Person::players[k]->scale + Person::players[k]->coords;
354 opacity = .4 - Person::players[k]->skeleton.joints[i].position.y * Person::players[k]->scale / 5 - (Person::players[k]->coords.y - terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z)) / 5;
355 if (k != 0 && Tutorial::active) {
356 opacity = .2 + .2 * sin(smoketex * 6 + i) - Person::players[k]->skeleton.joints[i].position.y * Person::players[k]->scale / 5 - (Person::players[k]->coords.y - terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z)) / 10;
358 terrain.MakeDecal(shadowdecal, point, size, opacity * .7, rotation);
359 for (unsigned int l = 0; l < terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz].size(); l++) {
360 unsigned int j = terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz][l];
361 if (Object::objects[j]->position.y < Person::players[k]->coords.y || Object::objects[j]->type == tunneltype || Object::objects[j]->type == weirdtype) {
362 if (Person::players[k]->skeleton.free) {
363 point = DoRotation(Person::players[k]->skeleton.joints[i].position * Person::players[k]->scale + Person::players[k]->coords - Object::objects[j]->position, 0, -Object::objects[j]->yaw, 0);
365 point = DoRotation(DoRotation(Person::players[k]->skeleton.joints[i].position, 0, Person::players[k]->yaw, 0) * Person::players[k]->scale + Person::players[k]->coords - Object::objects[j]->position, 0, -Object::objects[j]->yaw, 0);
369 if (k != 0 && Tutorial::active) {
370 opacity = .2 + .2 * sin(smoketex * 6 + i);
372 Object::objects[j]->model.MakeDecal(shadowdecal, &point, &size, &opacity, &rotation);
380 if (!Person::players[k]->playerdetail) {
381 if (frustum.SphereInFrustum(Person::players[k]->coords.x, Person::players[k]->coords.y, Person::players[k]->coords.z, Person::players[k]->scale * 5)) {
382 point = Person::players[k]->coords;
384 opacity = .4 - (Person::players[k]->coords.y - terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z)) / 5;
385 terrain.MakeDecal(shadowdecal, point, size, opacity * .7, rotation);
386 for (unsigned int l = 0; l < terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz].size(); l++) {
387 unsigned int j = terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz][l];
388 point = DoRotation(Person::players[k]->coords - Object::objects[j]->position, 0, -Object::objects[j]->yaw, 0);
391 Object::objects[j]->model.MakeDecal(shadowdecal, &point, &size, &opacity, &rotation);
398 glEnable(GL_TEXTURE_2D);
400 glEnable(GL_DEPTH_TEST);
401 glEnable(GL_CULL_FACE);
403 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
404 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
405 terraintexture.bind();
407 terraintexture2.bind();
410 terrain.drawdecals();
413 glEnable(GL_CULL_FACE);
414 glEnable(GL_LIGHTING);
416 glEnable(GL_TEXTURE_2D);
419 glEnable(GL_COLOR_MATERIAL);
422 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
423 glEnable(GL_CULL_FACE);
424 glCullFace(GL_FRONT);
426 for (unsigned k = 0; k < Person::players.size(); k++) {
427 if (k == 0 || !Tutorial::active) {
429 glEnable(GL_LIGHTING);
430 terrainlight = terrain.getLighting(Person::players[k]->coords.x, Person::players[k]->coords.z);
431 distance = distsq(&viewer, &Person::players[k]->coords);
432 distance = (viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance;
433 glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, distance);
437 if (distance >= .5) {
438 checkpoint = DoRotation(Person::players[k]->skeleton.joints[fabs(Random() % Person::players[k]->skeleton.joints.size())].position, 0, Person::players[k]->yaw, 0) * Person::players[k]->scale + Person::players[k]->coords;
441 if (Person::players[k]->occluded != 0) {
442 i = Object::checkcollide(viewer, checkpoint, Person::players[k]->lastoccluded);
445 i = Object::checkcollide(viewer, checkpoint);
448 Person::players[k]->occluded += 1;
449 Person::players[k]->lastoccluded = i;
451 Person::players[k]->occluded = 0;
453 if (Person::players[k]->occluded < 25) {
454 Person::players[k]->DrawSkeleton();
461 if (!cameramode && musictype == stream_fighttheme) {
462 playerdist = distsqflat(&Person::players[0]->coords, &viewer);
468 glEnable(GL_TEXTURE_2D);
474 if (frustum.SphereInFrustum(realhawkcoords.x + hawk.boundingspherecenter.x, realhawkcoords.y + hawk.boundingspherecenter.y, realhawkcoords.z + hawk.boundingspherecenter.z, 2)) {
475 glAlphaFunc(GL_GREATER, 0.0001f);
477 glDisable(GL_CULL_FACE);
478 glDisable(GL_LIGHTING);
480 glTranslatef(hawkcoords.x, hawkcoords.y, hawkcoords.z);
481 glRotatef(hawkyaw, 0, 1, 0);
482 glTranslatef(25, 0, 0);
483 distance = distsq(&viewer, &realhawkcoords) * 1.2;
484 glColor4f(light.color[0], light.color[1], light.color[2], (viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance);
485 if ((viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance > 1) {
486 glColor4f(light.color[0], light.color[1], light.color[2], 1);
488 if ((viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance > 0) {
489 hawk.drawdifftex(hawktexture);
494 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
495 glEnable(GL_CULL_FACE);
496 glCullFace(GL_FRONT);
498 for (unsigned k = 0; k < Person::players.size(); k++) {
499 if (!(k == 0 || !Tutorial::active)) {
501 glEnable(GL_LIGHTING);
502 terrainlight = terrain.getLighting(Person::players[k]->coords.x, Person::players[k]->coords.z);
503 distance = distsq(&viewer, &Person::players[k]->coords);
504 distance = (viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance;
505 glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, distance);
509 if (distance >= .5) {
510 checkpoint = DoRotation(Person::players[k]->skeleton.joints[fabs(Random() % Person::players[k]->skeleton.joints.size())].position, 0, Person::players[k]->yaw, 0) * Person::players[k]->scale + Person::players[k]->coords;
513 if (Person::players[k]->occluded != 0) {
514 i = Object::checkcollide(viewer, checkpoint, Person::players[k]->lastoccluded);
517 i = Object::checkcollide(viewer, checkpoint);
520 Person::players[k]->occluded += 1;
521 Person::players[k]->lastoccluded = i;
523 Person::players[k]->occluded = 0;
525 if (Person::players[k]->occluded < 25) {
526 Person::players[k]->DrawSkeleton();
533 glEnable(GL_TEXTURE_2D);
538 glDisable(GL_COLOR_MATERIAL);
540 glDisable(GL_LIGHTING);
541 glDisable(GL_TEXTURE_2D);
547 //waypoints, pathpoints in editor
550 glDisable(GL_LIGHTING);
551 glDisable(GL_TEXTURE_2D);
552 glDisable(GL_COLOR_MATERIAL);
553 glColor4f(1, 1, 0, 1);
555 for (unsigned k = 0; k < Person::players.size(); k++) {
556 if (Person::players[k]->numwaypoints > 1) {
557 glBegin(GL_LINE_LOOP);
558 for (int i = 0; i < Person::players[k]->numwaypoints; i++) {
559 glVertex3f(Person::players[k]->waypoints[i].x, Person::players[k]->waypoints[i].y + .5, Person::players[k]->waypoints[i].z);
565 if (numpathpoints > 1) {
566 glColor4f(0, 1, 0, 1);
567 for (unsigned k = 0; int(k) < numpathpoints; k++) {
568 if (numpathpointconnect[k]) {
569 for (int i = 0; i < numpathpointconnect[k]; i++) {
570 glBegin(GL_LINE_LOOP);
571 glVertex3f(pathpoint[k].x, pathpoint[k].y + .5, pathpoint[k].z);
572 glVertex3f(pathpoint[pathpointconnect[k][i]].x, pathpoint[pathpointconnect[k][i]].y + .5, pathpoint[pathpointconnect[k][i]].z);
577 glColor4f(1, 1, 1, 1);
580 glVertex3f(pathpoint[pathpointselected].x, pathpoint[pathpointselected].y + .5, pathpoint[pathpointselected].z);
587 glEnable(GL_TEXTURE_2D);
588 glColor4f(.5, .5, .5, 1);
590 if (!Tutorial::active) {
591 if (bonus > 0 && bonustime < 1 && !winfreeze && !Dialog::inDialog()) {
592 const char* bonus_name;
593 if (bonus < bonus_count) {
594 bonus_name = bonus_names[bonus];
596 bonus_name = "Excellent!"; // When does this happen?
598 text->glPrintOutlined(1, 0, 0, 1 - bonustime, 1024 / 2 - 10 * strlen(bonus_name), 768 / 16 + 768 * 4 / 5, bonus_name, 1, 2, 1024, 768);
600 string = to_string(bonusvalue);
601 text->glPrintOutlined(1, 0, 0, 1 - bonustime, 1024 / 2 - 10 * string.size(), 768 / 16 - 20 + 768 * 4 / 5, string, 1, 2 * .8, 1024, 768);
603 glColor4f(.5, .5, .5, 1);
607 if (Tutorial::active) {
608 Tutorial::DrawTextInfo();
612 if (Hotspot::hotspots.size() && (bonustime >= 1 || bonus <= 0 || bonustime < 0) && !Tutorial::active) {
613 float closestdist = -1;
614 int closest = Hotspot::current;
615 for (unsigned i = 0; i < Hotspot::hotspots.size(); i++) {
616 float distance = distsq(&Person::players[0]->coords, &Hotspot::hotspots[i].position);
617 if (closestdist == -1 || distance < closestdist) {
618 if (distsq(&Person::players[0]->coords, &Hotspot::hotspots[i].position) < Hotspot::hotspots[i].size && ((Hotspot::hotspots[i].type <= 10 && Hotspot::hotspots[i].type >= 0) || (Hotspot::hotspots[i].type <= 40 && Hotspot::hotspots[i].type >= 20))) {
619 closestdist = distance;
625 Hotspot::current = closest;
626 if (Hotspot::hotspots[closest].type <= 10) {
627 if (distsq(&Person::players[0]->coords, &Hotspot::hotspots[closest].position) < Hotspot::hotspots[closest].size) {
628 Tutorial::stagetime = 0;
630 Tutorial::maxtime = 1;
631 tutorialopac = Tutorial::maxtime - Tutorial::stagetime;
632 if (tutorialopac > 1) {
635 if (tutorialopac < 0) {
639 string = Hotspot::hotspots[closest].text;
646 if (string[i] == '\n' || string[i] > 'z' || string[i] < ' ' || string[i] == '\0') {
647 text->glPrintOutlined(1, 1, 1, tutorialopac, 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);
650 if (string[i] == '\0') {
659 } else if ((Hotspot::hotspots[closest].type >= 20) && (Dialog::dialogs[Hotspot::hotspots[closest].type - 20].gonethrough == 0)) {
660 Dialog::whichdialogue = Hotspot::hotspots[closest].type - 20;
661 Dialog::currentDialog().play();
662 Dialog::currentDialog().gonethrough++;
667 /* Drawing dialogs */
668 if (Dialog::inDialog() && !mainmenu) {
669 glDisable(GL_DEPTH_TEST);
670 glDisable(GL_CULL_FACE);
671 glDisable(GL_LIGHTING);
672 glDisable(GL_TEXTURE_2D);
674 glMatrixMode(GL_PROJECTION);
677 glOrtho(0, screenwidth, 0, screenheight, -100, 100);
678 glMatrixMode(GL_MODELVIEW);
681 if (Dialog::currentScene().location == 1) {
682 glTranslatef(0, screenheight * 3 / 4, 0);
684 glScalef(screenwidth, screenheight / 4, 1);
685 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
688 glColor4f(Dialog::currentScene().color[0], Dialog::currentScene().color[1], Dialog::currentScene().color[2], 0.7);
690 glVertex3f(0, 0, 0.0f);
691 glVertex3f(1, 0, 0.0f);
692 glVertex3f(1, 1, 0.0f);
693 glVertex3f(0, 1, 0.0f);
695 glMatrixMode(GL_PROJECTION);
697 glMatrixMode(GL_MODELVIEW);
699 glEnable(GL_DEPTH_TEST);
700 glEnable(GL_CULL_FACE);
703 glEnable(GL_TEXTURE_2D);
710 startx = screenwidth * 1 / 5;
711 if (Dialog::currentScene().location == 1) {
712 starty = screenheight / 16 + screenheight * 4 / 5;
714 starty = screenheight * 1 / 5 - screenheight / 16;
717 /* Get speaker name, and remove potential '#' chars hardcoded in it. */
718 string = Dialog::currentScene().name + ": ";
719 string.erase(std::remove(string.begin(), string.end(), '#'), string.end());
721 /* Print speaker name in dialog box. */
722 if (Dialog::currentScene().color[0] + Dialog::currentScene().color[1] + Dialog::currentScene().color[2] < 1.5) {
723 text->glPrintOutlined(0.7, 0.7, 0.7, tutorialopac, startx - 2 * 7.6 * string.size() * screenwidth / 1024, starty, string, 1, 1.4 * screenwidth / 1024, screenwidth, screenheight);
725 glColor4f(0, 0, 0, tutorialopac);
726 text->glPrintOutline(startx - 2 * 7.6 * string.size() * screenwidth / 1024 - 4, starty - 4, string, 1, 1.4 * 1.25 * screenwidth / 1024, screenwidth, screenheight);
729 /* Get dialog text, and remove potential '#' chars hardcoded in it.' */
730 string = Dialog::currentScene().text;
731 string.erase(std::remove(string.begin(), string.end(), '#'), string.end());
733 /* Print dialog text in dialog box. */
739 if (string[i] == '\n' || string[i] > 'z' || string[i] < ' ' || string[i] == '\0') {
740 if (Dialog::currentScene().color[0] + Dialog::currentScene().color[1] + Dialog::currentScene().color[2] < 1.5) {
741 text->glPrintOutlined(1, 1, 1, tutorialopac, startx, starty - 20 * screenwidth / 1024 * line, string, 1, 1.4 * screenwidth / 1024, screenwidth, screenheight, lastline, i);
743 glColor4f(0, 0, 0, tutorialopac);
744 text->glPrint(startx, starty - 20 * screenwidth / 1024 * line, string, 1, 1.4 * screenwidth / 1024, screenwidth, screenheight, lastline, i);
748 if (string[i] == '\0') {
759 if (!Tutorial::active && !winfreeze && !Dialog::inDialog() && !mainmenu) {
762 string = "Score: " + to_string(int(Account::active().getCampaignScore()));
764 string = "Score: " + to_string(int(Account::active().getCampaignScore() + bonustotal));
767 string = "Score: " + to_string(int(bonustotal));
769 text->glPrintOutlined(1, 0, 0, 1, 1024 / 40, 768 / 16 + 768 * 14 / 16, string, 1, 1.5, 1024, 768);
771 glDisable(GL_DEPTH_TEST);
772 glDisable(GL_CULL_FACE);
773 glDisable(GL_LIGHTING);
774 glDisable(GL_TEXTURE_2D);
776 glMatrixMode(GL_PROJECTION);
779 glOrtho(0, screenwidth, 0, screenheight, -100, 100);
780 glMatrixMode(GL_MODELVIEW);
783 glTranslatef(15, screenheight * 17.5 / 20, 0);
784 glScalef(screenwidth / 3 + 20, screenheight / 20, 1);
785 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
787 glColor4f(0.0, 0.4, 0.0, 0.7);
788 float bar = ((float)Person::players[0]->damage) / Person::players[0]->damagetolerance;
790 glVertex3f((bar < 1 ? bar : 1), 0, 0.0f);
791 glVertex3f(1, 0, 0.0f);
792 glVertex3f(1, 1, 0.0f);
793 glVertex3f((bar < 1 ? bar : 1), 1, 0.0f);
795 glColor4f(0.1, 0.0, 0.0, 1);
796 bar = ((float)Person::players[0]->bloodloss) / Person::players[0]->damagetolerance;
798 glVertex3f(0, 0, 0.0f);
799 glVertex3f((bar < 1 ? bar : 1), 0, 0.0f);
800 glVertex3f((bar < 1 ? bar : 1), 1, 0.0f);
801 glVertex3f(0, 1, 0.0f);
803 glColor4f(0.4, 0.0, 0.0, 0.7);
804 bar = ((float)Person::players[0]->damage) / Person::players[0]->damagetolerance;
806 glVertex3f(0, 0, 0.0f);
807 glVertex3f((bar < 1 ? bar : 1), 0, 0.0f);
808 glVertex3f((bar < 1 ? bar : 1), 1, 0.0f);
809 glVertex3f(0, 1, 0.0f);
811 glColor4f(0.4, 0.0, 0.0, 0.7);
812 bar = ((float)Person::players[0]->permanentdamage) / Person::players[0]->damagetolerance;
814 glVertex3f(0, 0, 0.0f);
815 glVertex3f((bar < 1 ? bar : 1), 0, 0.0f);
816 glVertex3f((bar < 1 ? bar : 1), 1, 0.0f);
817 glVertex3f(0, 1, 0.0f);
819 glColor4f(0.4, 0.0, 0.0, 0.7);
820 bar = ((float)Person::players[0]->superpermanentdamage) / Person::players[0]->damagetolerance;
822 glVertex3f(0, 0, 0.0f);
823 glVertex3f((bar < 1 ? bar : 1), 0, 0.0f);
824 glVertex3f((bar < 1 ? bar : 1), 1, 0.0f);
825 glVertex3f(0, 1, 0.0f);
827 glColor4f(0.0, 0.0, 0.0, 0.7);
829 glBegin(GL_LINE_STRIP);
830 glVertex3f(0, 0, 0.0f);
831 glVertex3f(1, 0, 0.0f);
832 glVertex3f(1, 1, 0.0f);
833 glVertex3f(0, 1, 0.0f);
834 glVertex3f(0, 0, 0.0f);
837 glMatrixMode(GL_PROJECTION);
839 glMatrixMode(GL_MODELVIEW);
841 glEnable(GL_DEPTH_TEST);
842 glEnable(GL_CULL_FACE);
845 glEnable(GL_TEXTURE_2D);
847 // writing the numbers :
848 string = "Damages : " + to_string(int(Person::players[0]->damage)) + "/" + to_string(int(Person::players[0]->damagetolerance)) + " (" + to_string(int(Person::players[0]->bloodloss)) + ")";
849 text->glPrintOutlined(1, 0, 0, 1, 1024 / 40, 768 / 16 + 768 * 14 / 16 - 40, string, 1, 1.5, 1024, 768);
853 glColor4f(.5, .5, .5, 1);
855 if ((texttoggle || editorenabled) && devtools && !mainmenu) {
856 string = "The framespersecond is " + to_string(int(fps));
857 text->glPrint(10, 30, string, 0, .8, 1024, 768);
860 string = "Map editor enabled.";
862 string = "Map editor disabled.";
864 text->glPrint(10, 60, string, 0, .8, 1024, 768);
866 string = "Object size: " + to_string(editorsize);
867 text->glPrint(10, 75, string, 0, .8, 1024, 768);
868 if (editoryaw >= 0) {
869 string = "Object yaw: " + to_string(editoryaw);
871 string = "Object yaw: Random";
873 text->glPrint(10, 90, string, 0, .8, 1024, 768);
874 if (editorpitch >= 0) {
875 string = "Object pitch: " + to_string(editorpitch);
877 string = "Object pitch: Random";
879 text->glPrint(10, 105, string, 0, .8, 1024, 768);
880 string = "Object type: " + to_string(editortype);
881 text->glPrint(10, 120, string, 0, .8, 1024, 768);
882 switch (editortype) {
908 string = "(chimney)";
911 string = "(platform)";
920 text->glPrint(130, 120, string, 0, .8, 1024, 768);
922 string = "Numplayers: " + to_string(Person::players.size());
923 text->glPrint(10, 155, string, 0, .8, 1024, 768);
924 string = "Player " + to_string(int(Person::players.size()) - 1) + ": numwaypoints: " + to_string(Person::players.back()->numwaypoints);
925 text->glPrint(10, 140, string, 0, .8, 1024, 768);
927 string = "Difficulty: " + to_string(difficulty);
928 text->glPrint(10, 240, string, 0, .8, 1024, 768);
932 if (drawmode == glowmode) {
933 glDisable(GL_DEPTH_TEST);
934 glDisable(GL_CULL_FACE);
935 glDisable(GL_LIGHTING);
936 glDisable(GL_TEXTURE_2D);
938 glMatrixMode(GL_PROJECTION);
941 glOrtho(0, screenwidth, 0, screenheight, -100, 100);
942 glMatrixMode(GL_MODELVIEW);
945 glScalef(screenwidth, screenheight, 1);
946 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
948 glColor4f(0, 0, 0, .5);
950 glVertex3f(0, 0, 0.0f);
951 glVertex3f(256, 0, 0.0f);
952 glVertex3f(256, 256, 0.0f);
953 glVertex3f(0, 256, 0.0f);
955 glMatrixMode(GL_PROJECTION);
957 glMatrixMode(GL_MODELVIEW);
959 glEnable(GL_DEPTH_TEST);
960 glEnable(GL_CULL_FACE);
965 if ((((blackout && damageeffects) || (Person::players[0]->bloodloss > 0 && damageeffects && Person::players[0]->blooddimamount > 0) || Person::players[0]->dead) && !cameramode) || console) {
966 glDisable(GL_DEPTH_TEST);
967 glDisable(GL_CULL_FACE);
968 glDisable(GL_LIGHTING);
969 glDisable(GL_TEXTURE_2D);
971 glMatrixMode(GL_PROJECTION);
974 glOrtho(0, screenwidth, 0, screenheight, -100, 100);
975 glMatrixMode(GL_MODELVIEW);
978 glScalef(screenwidth, screenheight, 1);
979 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
981 if (Person::players[0]->dead) {
982 blackout += multiplier * 3;
984 if (Person::players[0]->dead == 1) {
987 if (Person::players[0]->dead == 2 && blackout > .6) {
990 glColor4f(0, 0, 0, blackout);
991 if (!Person::players[0]->dead) {
992 if ((Person::players[0]->bloodloss / Person::players[0]->damagetolerance * (sin(woozy) / 4 + .5)) * .3 < .3) {
993 glColor4f(0, 0, 0, Person::players[0]->blooddimamount * Person::players[0]->bloodloss / Person::players[0]->damagetolerance * (sin(woozy) / 4 + .5) * .3);
994 blackout = Person::players[0]->blooddimamount * Person::players[0]->bloodloss / Person::players[0]->damagetolerance * (sin(woozy) / 4 + .5) * .3;
996 glColor4f(0, 0, 0, Person::players[0]->blooddimamount * .3);
997 blackout = Person::players[0]->blooddimamount * .3;
1001 glColor4f(.7, 0, 0, .2);
1004 glVertex3f(0, 0, 0.0f);
1005 glVertex3f(256, 0, 0.0f);
1006 glVertex3f(256, 256, 0.0f);
1007 glVertex3f(0, 256, 0.0f);
1009 glMatrixMode(GL_PROJECTION);
1011 glMatrixMode(GL_MODELVIEW);
1013 glEnable(GL_DEPTH_TEST);
1014 glEnable(GL_CULL_FACE);
1015 glDisable(GL_BLEND);
1019 if (flashamount > 0 && damageeffects) {
1020 if (flashamount > 1) {
1023 if (flashdelay <= 0) {
1024 flashamount -= multiplier;
1027 if (flashamount < 0) {
1030 glDisable(GL_DEPTH_TEST);
1031 glDisable(GL_CULL_FACE);
1032 glDisable(GL_LIGHTING);
1034 glMatrixMode(GL_PROJECTION);
1037 glOrtho(0, screenwidth, 0, screenheight, -100, 100);
1038 glMatrixMode(GL_MODELVIEW);
1041 glScalef(screenwidth, screenheight, 1);
1042 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1044 glColor4f(flashr, flashg, flashb, flashamount);
1046 glVertex3f(0, 0, 0.0f);
1047 glVertex3f(256, 0, 0.0f);
1048 glVertex3f(256, 256, 0.0f);
1049 glVertex3f(0, 256, 0.0f);
1051 glMatrixMode(GL_PROJECTION);
1053 glMatrixMode(GL_MODELVIEW);
1055 glEnable(GL_DEPTH_TEST);
1056 glEnable(GL_CULL_FACE);
1057 glDisable(GL_BLEND);
1061 if (difficulty < 2 && !Dialog::inDialog()) { // minimap
1062 float mapviewdist = 20000;
1064 glDisable(GL_DEPTH_TEST);
1065 glColor3f(1.0, 1.0, 1.0); // no coloring
1067 glEnable(GL_TEXTURE_2D);
1068 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1069 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1070 glDisable(GL_DEPTH_TEST);
1071 glDisable(GL_CULL_FACE);
1072 glDisable(GL_LIGHTING);
1074 glMatrixMode(GL_PROJECTION);
1077 glOrtho(0, screenwidth, 0, screenheight, -100, 100);
1078 glMatrixMode(GL_MODELVIEW);
1081 glScalef((float)screenwidth / 2, (float)screenwidth / 2, 1);
1082 glTranslatef(1.75, .25, 0);
1083 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1085 glColor4f(1, 1, 1, 1);
1092 center = Person::players[0]->coords;
1096 glScalef(.25 / radius * 256 * terrain.scale * .4, .25 / radius * 256 * terrain.scale * .4, 1);
1098 glScalef(1 / (1 / radius * 256 * terrain.scale * .4), 1 / (1 / radius * 256 * terrain.scale * .4), 1);
1100 glRotatef(Person::players[0]->lookyaw * -1 + 180, 0, 0, 1);
1101 glTranslatef(-(center.x / terrain.scale / 256 * -2 + 1), (center.z / terrain.scale / 256 * -2 + 1), 0);
1102 for (unsigned int i = 0; i < Object::objects.size(); i++) {
1103 if (Object::objects[i]->type == treetrunktype) {
1104 distcheck = distsq(&Person::players[0]->coords, &Object::objects[i]->position);
1105 if (distcheck < mapviewdist) {
1106 Mapcircletexture.bind();
1107 glColor4f(0, .3, 0, opac * (1 - distcheck / mapviewdist));
1109 glTranslatef(Object::objects[i]->position.x / terrain.scale / 256 * -2 + 1, Object::objects[i]->position.z / terrain.scale / 256 * 2 - 1, 0);
1110 glRotatef(Object::objects[i]->yaw, 0, 0, 1);
1111 glScalef(.003, .003, .003);
1114 glVertex3f(-1, -1, 0.0f);
1116 glVertex3f(1, -1, 0.0f);
1118 glVertex3f(1, 1, 0.0f);
1120 glVertex3f(-1, 1, 0.0f);
1125 if (Object::objects[i]->type == boxtype) {
1126 distcheck = distsq(&Person::players[0]->coords, &Object::objects[i]->position);
1127 if (distcheck < mapviewdist) {
1128 Mapboxtexture.bind();
1129 glColor4f(.4, .4, .4, opac * (1 - distcheck / mapviewdist));
1131 glTranslatef(Object::objects[i]->position.x / terrain.scale / 256 * -2 + 1, Object::objects[i]->position.z / terrain.scale / 256 * 2 - 1, 0);
1132 glRotatef(Object::objects[i]->yaw, 0, 0, 1);
1133 glScalef(.01 * Object::objects[i]->scale, .01 * Object::objects[i]->scale, .01 * Object::objects[i]->scale);
1136 glVertex3f(-1, -1, 0.0f);
1138 glVertex3f(1, -1, 0.0f);
1140 glVertex3f(1, 1, 0.0f);
1142 glVertex3f(-1, 1, 0.0f);
1148 if (editorenabled) {
1149 Mapcircletexture.bind();
1150 for (int i = 0; i < numboundaries; i++) {
1151 glColor4f(0, 0, 0, opac / 3);
1153 glTranslatef(boundary[i].x / terrain.scale / 256 * -2 + 1, boundary[i].z / terrain.scale / 256 * 2 - 1, 0);
1154 glScalef(.002, .002, .002);
1157 glVertex3f(-1, -1, 0.0f);
1159 glVertex3f(1, -1, 0.0f);
1161 glVertex3f(1, 1, 0.0f);
1163 glVertex3f(-1, 1, 0.0f);
1168 for (unsigned i = 0; i < Person::players.size(); i++) {
1169 distcheck = distsq(&Person::players[0]->coords, &Person::players[i]->coords);
1170 if (distcheck < mapviewdist) {
1172 Maparrowtexture.bind();
1174 glColor4f(1, 1, 1, opac);
1175 } else if (Person::players[i]->dead == 2 || Person::players[i]->howactive > typesleeping) {
1176 glColor4f(0, 0, 0, opac * (1 - distcheck / mapviewdist));
1177 } else if (Person::players[i]->dead) {
1178 glColor4f(.3, .3, .3, opac * (1 - distcheck / mapviewdist));
1179 } else if (Person::players[i]->aitype == attacktypecutoff) {
1180 glColor4f(1, 0, 0, opac * (1 - distcheck / mapviewdist));
1181 } else if (Person::players[i]->aitype == passivetype) {
1182 glColor4f(0, 1, 0, opac * (1 - distcheck / mapviewdist));
1184 glColor4f(1, 1, 0, 1);
1186 glTranslatef(Person::players[i]->coords.x / terrain.scale / 256 * -2 + 1, Person::players[i]->coords.z / terrain.scale / 256 * 2 - 1, 0);
1187 glRotatef(Person::players[i]->yaw + 180, 0, 0, 1);
1188 glScalef(.005, .005, .005);
1191 glVertex3f(-1, -1, 0.0f);
1193 glVertex3f(1, -1, 0.0f);
1195 glVertex3f(1, 1, 0.0f);
1197 glVertex3f(-1, 1, 0.0f);
1203 glDisable(GL_TEXTURE_2D);
1204 glMatrixMode(GL_PROJECTION);
1206 glMatrixMode(GL_MODELVIEW);
1208 glEnable(GL_DEPTH_TEST);
1209 glEnable(GL_CULL_FACE);
1210 glDisable(GL_BLEND);
1214 if (loading && !stealthloading && (!campaign || Person::players[0]->dead)) {
1215 glDisable(GL_DEPTH_TEST);
1216 glDisable(GL_CULL_FACE);
1217 glDisable(GL_LIGHTING);
1218 glDisable(GL_TEXTURE_2D);
1220 glMatrixMode(GL_PROJECTION);
1223 glOrtho(0, screenwidth, 0, screenheight, -100, 100);
1224 glMatrixMode(GL_MODELVIEW);
1227 glScalef(screenwidth, screenheight, 1);
1228 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1230 glColor4f(0, 0, 0, .7);
1232 glVertex3f(0, 0, 0.0f);
1233 glVertex3f(256, 0, 0.0f);
1234 glVertex3f(256, 256, 0.0f);
1235 glVertex3f(0, 256, 0.0f);
1237 glMatrixMode(GL_PROJECTION);
1239 glMatrixMode(GL_MODELVIEW);
1241 glEnable(GL_DEPTH_TEST);
1242 glEnable(GL_CULL_FACE);
1243 glDisable(GL_BLEND);
1247 glDisable(GL_DEPTH_TEST);
1248 glColor3f(1.0, 1.0, 1.0); // no coloring
1250 glEnable(GL_TEXTURE_2D);
1255 glEnable(GL_TEXTURE_2D);
1256 glColor4f(1, 1, 1, 1);
1257 string = "Loading...";
1258 text->glPrint(1024 / 2 - 90, 768 / 2, string, 1, 2, 1024, 768);
1261 drawmode = normalmode;
1264 if (winfreeze && !campaign) {
1265 glDisable(GL_DEPTH_TEST);
1266 glDisable(GL_CULL_FACE);
1267 glDisable(GL_LIGHTING);
1268 glDisable(GL_TEXTURE_2D);
1270 glMatrixMode(GL_PROJECTION);
1273 glOrtho(0, screenwidth, 0, screenheight, -100, 100);
1274 glMatrixMode(GL_MODELVIEW);
1277 glScalef(screenwidth, screenheight, 1);
1278 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1280 glColor4f(0, 0, 0, .4);
1282 glVertex3f(0, 0, 0.0f);
1283 glVertex3f(256, 0, 0.0f);
1284 glVertex3f(256, 256, 0.0f);
1285 glVertex3f(0, 256, 0.0f);
1287 glMatrixMode(GL_PROJECTION);
1289 glMatrixMode(GL_MODELVIEW);
1291 glEnable(GL_DEPTH_TEST);
1292 glEnable(GL_CULL_FACE);
1293 glDisable(GL_BLEND);
1297 glDisable(GL_DEPTH_TEST);
1298 glColor3f(1.0, 1.0, 1.0); // no coloring
1300 glEnable(GL_TEXTURE_2D);
1302 //Win Screen Won Victory
1304 glEnable(GL_TEXTURE_2D);
1305 glColor4f(1, 1, 1, 1);
1306 string = "Level Cleared!";
1307 text->glPrintOutlined(1024 / 2 - string.size() * 10, 768 * 7 / 8, string, 1, 2, 1024, 768);
1309 string = "Score: " + to_string(int(bonustotal - startbonustotal));
1310 text->glPrintOutlined(1024 / 30, 768 * 6 / 8, string, 1, 2, 1024, 768);
1312 string = "Press Escape to return to menu or Space to continue";
1313 text->glPrintOutlined(640 / 2 - string.size() * 5, 480 * 1 / 16, string, 1, 1, 640, 480);
1315 int wontime = (int)round(wonleveltime);
1316 string = "Time: " + to_string(int((wontime - wontime % 60) / 60));
1317 if (wontime % 60 < 10) {
1320 string += to_string(int(wontime % 60));
1321 text->glPrintOutlined(1024 / 30, 768 * 6 / 8 - 40, string, 1, 2, 1024, 768);
1324 int awards[award_count];
1325 int numawards = award_awards(awards);
1327 for (int i = 0; i < numawards && i < 6; i++) {
1328 text->glPrintOutlined(1024 / 30, 768 * 6 / 8 - 90 - 40 * i, award_names[awards[i]], 1, 2, 1024, 768);
1332 if (drawmode != normalmode) {
1333 glEnable(GL_TEXTURE_2D);
1335 if (!drawtoggle || drawmode != realmotionblurmode || (drawtoggle == 2 || change == 1)) {
1336 if (screentexture) {
1338 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
1339 GLfloat subtractColor[4] = { 0.5, 0.5, 0.5, 0.0 };
1340 glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, subtractColor);
1341 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
1342 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_CONSTANT);
1343 glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, 2.0f);
1345 glBindTexture(GL_TEXTURE_2D, screentexture);
1346 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texviewwidth, texviewheight);
1349 if ((drawtoggle || change == 1) && drawmode == realmotionblurmode) {
1350 if (screentexture2) {
1351 glBindTexture(GL_TEXTURE_2D, screentexture2);
1352 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texviewwidth, texviewheight);
1354 if (!screentexture2) {
1355 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1357 glGenTextures(1, &screentexture2);
1358 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
1360 glEnable(GL_TEXTURE_2D);
1361 glBindTexture(GL_TEXTURE_2D, screentexture2);
1362 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1363 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1365 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);
1370 glClear(GL_DEPTH_BUFFER_BIT);
1371 Game::ReSizeGLScene(90, .1f);
1372 glViewport(0, 0, screenwidth, screenheight);
1374 if (drawmode != normalmode) {
1375 glDisable(GL_DEPTH_TEST);
1376 if (drawmode == motionblurmode) {
1377 glDrawBuffer(GL_FRONT);
1378 glReadBuffer(GL_BACK);
1380 glColor3f(1.0, 1.0, 1.0); // no coloring
1382 glEnable(GL_TEXTURE_2D);
1383 glBindTexture(GL_TEXTURE_2D, screentexture);
1384 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1385 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1386 glDisable(GL_DEPTH_TEST);
1387 glDisable(GL_CULL_FACE);
1388 glDisable(GL_LIGHTING);
1390 glMatrixMode(GL_PROJECTION);
1393 glOrtho(0, screenwidth, 0, screenheight, -100, 100);
1394 glMatrixMode(GL_MODELVIEW);
1397 glScalef((float)screenwidth / 2, (float)screenheight / 2, 1);
1398 glTranslatef(1, 1, 0);
1399 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1401 if (drawmode == motionblurmode) {
1402 if (motionbluramount < .2) {
1403 motionbluramount = .2;
1405 glColor4f(1, 1, 1, motionbluramount);
1409 glVertex3f(-1, -1, 0.0f);
1410 glTexCoord2f(texcoordwidth, 0);
1411 glVertex3f(1, -1, 0.0f);
1412 glTexCoord2f(texcoordwidth, texcoordheight);
1413 glVertex3f(1, 1, 0.0f);
1414 glTexCoord2f(0, texcoordheight);
1415 glVertex3f(-1, 1, 0.0f);
1419 if (drawmode == realmotionblurmode) {
1420 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
1421 glClear(GL_COLOR_BUFFER_BIT);
1422 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
1423 glBindTexture(GL_TEXTURE_2D, screentexture);
1424 glColor4f(1, 1, 1, .5);
1428 glVertex3f(-1, -1, 0.0f);
1429 glTexCoord2f(texcoordwidth, 0);
1430 glVertex3f(1, -1, 0.0f);
1431 glTexCoord2f(texcoordwidth, texcoordheight);
1432 glVertex3f(1, 1, 0.0f);
1433 glTexCoord2f(0, texcoordheight);
1434 glVertex3f(-1, 1, 0.0f);
1437 glBindTexture(GL_TEXTURE_2D, screentexture2);
1438 glColor4f(1, 1, 1, .5);
1442 glVertex3f(-1, -1, 0.0f);
1443 glTexCoord2f(texcoordwidth, 0);
1444 glVertex3f(1, -1, 0.0f);
1445 glTexCoord2f(texcoordwidth, texcoordheight);
1446 glVertex3f(1, 1, 0.0f);
1447 glTexCoord2f(0, texcoordheight);
1448 glVertex3f(-1, 1, 0.0f);
1451 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1453 if (drawmode == doublevisionmode) {
1454 static float crosseyedness;
1455 crosseyedness = abs(Person::players[0]->damage - Person::players[0]->superpermanentdamage - (Person::players[0]->damagetolerance - Person::players[0]->superpermanentdamage) * 1 / 2) / 30;
1456 if (crosseyedness > 1) {
1459 if (crosseyedness < 0) {
1462 glColor4f(1, 1, 1, 1);
1463 glDisable(GL_BLEND);
1468 glVertex3f(-1, -1, 0.0f);
1469 glTexCoord2f(texcoordwidth, 0);
1470 glVertex3f(1, -1, 0.0f);
1471 glTexCoord2f(texcoordwidth, texcoordheight);
1472 glVertex3f(1, 1, 0.0f);
1473 glTexCoord2f(0, texcoordheight);
1474 glVertex3f(-1, 1, 0.0f);
1477 if (crosseyedness) {
1478 glColor4f(1, 1, 1, .5);
1481 glTranslatef(.015 * crosseyedness, 0, 0);
1485 glVertex3f(-1, -1, 0.0f);
1486 glTexCoord2f(texcoordwidth, 0);
1487 glVertex3f(1, -1, 0.0f);
1488 glTexCoord2f(texcoordwidth, texcoordheight);
1489 glVertex3f(1, 1, 0.0f);
1490 glTexCoord2f(0, texcoordheight);
1491 glVertex3f(-1, 1, 0.0f);
1496 if (drawmode == glowmode) {
1497 glColor4f(.5, .5, .5, .5);
1499 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
1501 glTranslatef(.01, 0, 0);
1504 glVertex3f(-1, -1, 0.0f);
1505 glTexCoord2f(texcoordwidth, 0);
1506 glVertex3f(1, -1, 0.0f);
1507 glTexCoord2f(texcoordwidth, texcoordheight);
1508 glVertex3f(1, 1, 0.0f);
1509 glTexCoord2f(0, texcoordheight);
1510 glVertex3f(-1, 1, 0.0f);
1514 glTranslatef(-.01, 0, 0);
1517 glVertex3f(-1, -1, 0.0f);
1518 glTexCoord2f(texcoordwidth, 0);
1519 glVertex3f(1, -1, 0.0f);
1520 glTexCoord2f(texcoordwidth, texcoordheight);
1521 glVertex3f(1, 1, 0.0f);
1522 glTexCoord2f(0, texcoordheight);
1523 glVertex3f(-1, 1, 0.0f);
1527 glTranslatef(.0, .01, 0);
1530 glVertex3f(-1, -1, 0.0f);
1531 glTexCoord2f(texcoordwidth, 0);
1532 glVertex3f(1, -1, 0.0f);
1533 glTexCoord2f(texcoordwidth, texcoordheight);
1534 glVertex3f(1, 1, 0.0f);
1535 glTexCoord2f(0, texcoordheight);
1536 glVertex3f(-1, 1, 0.0f);
1540 glTranslatef(0, -.01, 0);
1543 glVertex3f(-1, -1, 0.0f);
1544 glTexCoord2f(texcoordwidth, 0);
1545 glVertex3f(1, -1, 0.0f);
1546 glTexCoord2f(texcoordwidth, texcoordheight);
1547 glVertex3f(1, 1, 0.0f);
1548 glTexCoord2f(0, texcoordheight);
1549 glVertex3f(-1, 1, 0.0f);
1553 if (drawmode == radialzoommode) {
1554 for (int i = 0; i < 3; i++) {
1555 glColor4f(1, 1, 1, 1 / ((float)i + 1));
1557 glScalef(1 + (float)i * .01, 1 + (float)i * .01, 1);
1560 glVertex3f(-1, -1, 0.0f);
1561 glTexCoord2f(texcoordwidth, 0);
1562 glVertex3f(1, -1, 0.0f);
1563 glTexCoord2f(texcoordwidth, texcoordheight);
1564 glVertex3f(1, 1, 0.0f);
1565 glTexCoord2f(0, texcoordheight);
1566 glVertex3f(-1, 1, 0.0f);
1571 glDisable(GL_TEXTURE_2D);
1572 glMatrixMode(GL_PROJECTION);
1574 glMatrixMode(GL_MODELVIEW);
1576 glEnable(GL_DEPTH_TEST);
1577 glEnable(GL_CULL_FACE);
1578 glDisable(GL_BLEND);
1583 glEnable(GL_TEXTURE_2D);
1584 glColor4f(1, 1, 1, 1);
1586 if (consoleselected >= 60) {
1587 offset = consoleselected - 60;
1589 textmono->glPrint(10, 30, " ]", 0, 1, 1024, 768);
1591 textmono->glPrint(30 + (float)consoleselected * 10 - offset * 10, 30, "_", 0, 1, 1024, 768);
1593 for (unsigned i = 0; i < 15; i++) {
1594 textmono->glPrint(30 - offset * 10, 30 + i * 20, consoletext[i], 0, 1, 1024, 768);
1599 if (freeze || winfreeze || (mainmenu && gameon) || (!gameon && gamestarted)) {
1600 multiplier = tempmult;
1607 if (freeze || winfreeze || (mainmenu && gameon) || (!gameon && gamestarted)) {
1608 tempmult = multiplier;
1612 if (side == stereoRight || side == stereoCenter) {
1613 if (drawmode != motionblurmode || mainmenu) {
1618 glDrawBuffer(GL_BACK);
1619 glReadBuffer(GL_BACK);
1623 if (drawtoggle == 2) {
1627 if (freeze || winfreeze || (mainmenu && gameon) || (!gameon && gamestarted)) {
1628 multiplier = tempmult;
1630 //Jordan fixed your warning!
1636 // !!! FIXME: hack: clamp framerate in menu so text input works correctly on fast systems.
1639 glDrawBuffer(GL_BACK);
1640 glReadBuffer(GL_BACK);
1641 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
1642 Game::ReSizeGLScene(90, .1f);
1644 //draw menu background
1645 glClear(GL_DEPTH_BUFFER_BIT);
1646 glEnable(GL_ALPHA_TEST);
1647 glAlphaFunc(GL_GREATER, 0.001f);
1648 glEnable(GL_TEXTURE_2D);
1649 glDisable(GL_DEPTH_TEST);
1650 glDisable(GL_CULL_FACE);
1651 glDisable(GL_LIGHTING);
1653 glMatrixMode(GL_PROJECTION);
1656 glOrtho(0, screenwidth, 0, screenheight, -100, 100);
1657 glMatrixMode(GL_MODELVIEW);
1660 glTranslatef(screenwidth / 2, screenheight / 2, 0);
1662 glScalef((float)screenwidth / 2, (float)screenheight / 2, 1);
1663 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1664 glDisable(GL_BLEND);
1665 glColor4f(0, 0, 0, 1.0);
1666 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
1667 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
1668 glDisable(GL_TEXTURE_2D);
1670 glVertex3f(-1, -1, 0);
1671 glVertex3f(+1, -1, 0);
1672 glVertex3f(+1, +1, 0);
1673 glVertex3f(-1, +1, 0);
1676 glColor4f(0.4, 0.4, 0.4, 1.0);
1677 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
1678 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
1679 glEnable(GL_TEXTURE_2D);
1680 Game::Mainmenuitems[4].bind();
1683 glVertex3f(-1, -1, 0);
1685 glVertex3f(+1, -1, 0);
1687 glVertex3f(+1, +1, 0);
1689 glVertex3f(-1, +1, 0);
1693 glMatrixMode(GL_PROJECTION);
1695 glMatrixMode(GL_MODELVIEW);
1697 glMatrixMode(GL_PROJECTION);
1700 glOrtho(0, 640, 0, 480, -100, 100);
1701 glMatrixMode(GL_MODELVIEW);
1704 glEnable(GL_TEXTURE_2D);
1709 glMatrixMode(GL_PROJECTION);
1711 glMatrixMode(GL_MODELVIEW);
1714 glMatrixMode(GL_PROJECTION);
1717 glOrtho(0, screenwidth, 0, screenheight, -100, 100);
1718 glMatrixMode(GL_MODELVIEW);
1721 glTranslatef(screenwidth / 2, screenheight / 2, 0);
1723 glScalef((float)screenwidth / 2, (float)screenheight / 2, 1);
1724 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1726 glEnable(GL_TEXTURE_2D);
1727 glColor4f(1, 1, 1, 1);
1728 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
1729 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
1731 if (!Game::waiting) { // hide the cursor while waiting for a key
1733 glTranslatef(Game::mousecoordh - screenwidth / 2, Game::mousecoordv * -1 + screenheight / 2, 0);
1734 glScalef((float)screenwidth / 64, (float)screenwidth / 64, 1);
1735 glTranslatef(1, -1, 0);
1736 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1737 glColor4f(1, 1, 1, 1);
1738 Game::cursortexture.bind();
1742 glVertex3f(-1, -1, 0.0f);
1744 glVertex3f(1, -1, 0.0f);
1746 glVertex3f(1, 1, 0.0f);
1748 glVertex3f(-1, 1, 0.0f);
1754 glMatrixMode(GL_PROJECTION);
1758 if (flashamount > 0) {
1759 if (flashamount > 1) {
1762 if (flashdelay <= 0) {
1763 flashamount -= multiplier;
1766 if (flashamount < 0) {
1769 glDisable(GL_DEPTH_TEST);
1770 glDisable(GL_CULL_FACE);
1771 glDisable(GL_LIGHTING);
1772 glDisable(GL_TEXTURE_2D);
1774 glMatrixMode(GL_PROJECTION);
1777 glOrtho(0, screenwidth, 0, screenheight, -100, 100);
1778 glMatrixMode(GL_MODELVIEW);
1781 glScalef(screenwidth, screenheight, 1);
1782 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1784 glColor4f(flashr, flashg, flashb, flashamount);
1786 glVertex3f(0, 0, 0.0f);
1787 glVertex3f(256, 0, 0.0f);
1788 glVertex3f(256, 256, 0.0f);
1789 glVertex3f(0, 256, 0.0f);
1791 glMatrixMode(GL_PROJECTION);
1793 glMatrixMode(GL_MODELVIEW);
1795 glEnable(GL_DEPTH_TEST);
1796 glEnable(GL_CULL_FACE);
1797 glDisable(GL_BLEND);