2010-03-13 22:10:45 +01:00
// This file is part of Glest (www.glest.org)
//
2011-12-14 08:40:48 +01:00
// Copyright (C) 2001-2008 Martiño Figueroa
2010-03-13 22:10:45 +01:00
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
2012-04-20 03:04:05 +02:00
# define NOMINMAX
2010-03-13 22:10:45 +01:00
# include "renderer.h"
# include "texture_gl.h"
# include "main_menu.h"
# include "config.h"
# include "components.h"
# include "time_flow.h"
# include "graphics_interface.h"
# include "object.h"
# include "core_data.h"
# include "game.h"
# include "metrics.h"
# include "opengl.h"
# include "faction.h"
# include "factory_repository.h"
2010-05-28 07:31:17 +02:00
# include <cstdlib>
2010-10-22 09:28:55 +02:00
# include "cache_manager.h"
2010-10-22 23:54:47 +02:00
# include "network_manager.h"
2012-04-20 03:04:05 +02:00
# include <algorithm>
2013-01-16 18:51:31 +01:00
# include <iterator>
2010-03-13 22:10:45 +01:00
# include "leak_dumper.h"
using namespace Shared : : Graphics ;
using namespace Shared : : Graphics : : Gl ;
using namespace Shared : : Util ;
2010-11-01 17:44:05 +01:00
using namespace Shared : : Graphics ;
2010-03-13 22:10:45 +01:00
namespace Glest { namespace Game {
2011-02-05 06:07:05 +01:00
uint32 Renderer : : SurfaceData : : nextUniqueId = 1 ;
2011-06-10 05:09:19 +02:00
bool Renderer : : renderText3DEnabled = true ;
2015-11-30 01:00:03 +01:00
//const float SKIP_INTERPOLATION_DISTANCE = 20.0f;
2012-10-06 04:10:23 +02:00
const string DEFAULT_CHAR_FOR_WIDTH_CALC = " V " ;
2012-10-06 09:06:40 +02:00
enum PROJECTION_TO_INFINITY {
pti_D_IS_ZERO ,
pti_N_OVER_D_IS_OUTSIDE
} ;
2010-03-13 22:10:45 +01:00
// =====================================================
// class MeshCallbackTeamColor
// =====================================================
2010-05-21 18:36:08 +02:00
bool MeshCallbackTeamColor : : noTeamColors = false ;
2011-01-15 09:45:17 +01:00
void MeshCallbackTeamColor : : execute ( const Mesh * mesh ) {
2010-03-13 22:10:45 +01:00
//team color
2010-05-21 18:36:08 +02:00
if ( mesh - > getCustomTexture ( ) & & teamTexture ! = NULL & &
MeshCallbackTeamColor : : noTeamColors = = false ) {
2010-03-13 22:10:45 +01:00
//texture 0
glTexEnvi ( GL_TEXTURE_ENV , GL_TEXTURE_ENV_MODE , GL_COMBINE ) ;
//set color to interpolation
glTexEnvi ( GL_TEXTURE_ENV , GL_COMBINE_RGB , GL_INTERPOLATE ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_SOURCE0_RGB , GL_TEXTURE ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_OPERAND0_RGB , GL_SRC_COLOR ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_SOURCE1_RGB , GL_TEXTURE1 ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_OPERAND1_RGB , GL_SRC_COLOR ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_SOURCE2_RGB , GL_TEXTURE ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_OPERAND2_RGB , GL_SRC_ALPHA ) ;
//set alpha to 1
glTexEnvi ( GL_TEXTURE_ENV , GL_COMBINE_ALPHA , GL_REPLACE ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_SOURCE0_ALPHA , GL_TEXTURE ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_OPERAND0_ALPHA , GL_SRC_ALPHA ) ;
//texture 1
glActiveTexture ( GL_TEXTURE1 ) ;
glMultiTexCoord2f ( GL_TEXTURE1 , 0.f , 0.f ) ;
glEnable ( GL_TEXTURE_2D ) ;
glBindTexture ( GL_TEXTURE_2D , static_cast < const Texture2DGl * > ( teamTexture ) - > getHandle ( ) ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_TEXTURE_ENV_MODE , GL_COMBINE ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_COMBINE_RGB , GL_MODULATE ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_SOURCE0_RGB , GL_PRIMARY_COLOR ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_OPERAND0_RGB , GL_SRC_COLOR ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_SOURCE1_RGB , GL_PREVIOUS ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_OPERAND1_RGB , GL_SRC_COLOR ) ;
//set alpha to 1
glTexEnvi ( GL_TEXTURE_ENV , GL_COMBINE_ALPHA , GL_REPLACE ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_SOURCE0_ALPHA , GL_PRIMARY_COLOR ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_OPERAND0_ALPHA , GL_SRC_ALPHA ) ;
glActiveTexture ( GL_TEXTURE0 ) ;
}
2011-01-15 09:45:17 +01:00
else {
2010-03-13 22:10:45 +01:00
glActiveTexture ( GL_TEXTURE1 ) ;
glDisable ( GL_TEXTURE_2D ) ;
glActiveTexture ( GL_TEXTURE0 ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_TEXTURE_ENV_MODE , GL_MODULATE ) ;
}
}
// ===========================================================
// class Renderer
// ===========================================================
// ===================== PUBLIC ========================
const int Renderer : : maxProgressBar = 100 ;
const Vec4f Renderer : : progressBarBack1 = Vec4f ( 0.7f , 0.7f , 0.7f , 0.7f ) ;
const Vec4f Renderer : : progressBarBack2 = Vec4f ( 0.7f , 0.7f , 0.7f , 1.f ) ;
const Vec4f Renderer : : progressBarFront1 = Vec4f ( 0.f , 0.5f , 0.f , 1.f ) ;
const Vec4f Renderer : : progressBarFront2 = Vec4f ( 0.f , 0.1f , 0.f , 1.f ) ;
const float Renderer : : sunDist = 10e6 ;
const float Renderer : : moonDist = 10e6 ;
const float Renderer : : lightAmbFactor = 0.4f ;
const int Renderer : : maxMouse2dAnim = 100 ;
const GLenum Renderer : : baseTexUnit = GL_TEXTURE0 ;
const GLenum Renderer : : fowTexUnit = GL_TEXTURE1 ;
const GLenum Renderer : : shadowTexUnit = GL_TEXTURE2 ;
const float Renderer : : selectionCircleRadius = 0.7f ;
const float Renderer : : magicCircleRadius = 1.f ;
//perspective values
const float Renderer : : perspFov = 60.f ;
2011-02-13 04:06:12 +01:00
const float Renderer : : perspNearPlane = 1.f ;
2010-07-15 16:54:19 +02:00
//const float Renderer::perspFarPlane= 50.f;
2011-05-02 00:48:44 +02:00
float Renderer : : perspFarPlane = 1000000.f ;
2010-03-13 22:10:45 +01:00
const float Renderer : : ambFactor = 0.7f ;
const Vec4f Renderer : : fowColor = Vec4f ( 0.0f , 0.0f , 0.0f , 1.0f ) ;
const Vec4f Renderer : : defSpecularColor = Vec4f ( 0.8f , 0.8f , 0.8f , 1.f ) ;
const Vec4f Renderer : : defDiffuseColor = Vec4f ( 1.f , 1.f , 1.f , 1.f ) ;
const Vec4f Renderer : : defAmbientColor = Vec4f ( 1.f * ambFactor , 1.f * ambFactor , 1.f * ambFactor , 1.f ) ;
const Vec4f Renderer : : defColor = Vec4f ( 1.f , 1.f , 1.f , 1.f ) ;
2010-07-15 09:33:49 +02:00
//const float Renderer::maxLightDist= 100.f;
2011-04-19 20:30:44 +02:00
const float Renderer : : maxLightDist = 100.f ;
2010-03-13 22:10:45 +01:00
2011-03-28 23:04:47 +02:00
bool Renderer : : rendererEnded = true ;
2010-10-04 18:43:00 +02:00
const int MIN_FPS_NORMAL_RENDERING = 15 ;
const int MIN_FPS_NORMAL_RENDERING_TOP_THRESHOLD = 25 ;
2010-07-17 14:41:05 +02:00
2011-02-13 15:35:17 +01:00
const int OBJECT_SELECT_OFFSET = 100000000 ;
2011-11-30 22:27:03 +01:00
bool VisibleQuadContainerCache : : enableFrustumCalcs = true ;
2011-11-30 06:57:14 +01:00
2010-03-13 22:10:45 +01:00
// ==================== constructor and destructor ====================
2013-12-25 07:27:44 +01:00
Renderer : : Renderer ( ) : BaseRenderer ( ) , saveScreenShotThreadAccessor ( new Mutex ( CODE_AT_LINE ) ) {
2011-12-02 23:04:02 +01:00
//this->masterserverMode = masterserverMode;
2011-09-27 07:29:57 +02:00
//printf("this->masterserverMode = %d\n",this->masterserverMode);
2011-10-27 21:02:15 +02:00
//assert(0==1);
2011-09-27 07:29:57 +02:00
2011-03-28 23:04:47 +02:00
Renderer : : rendererEnded = false ;
2013-09-22 02:51:47 +02:00
shadowIntensity = 0 ;
2012-09-22 22:13:57 +02:00
shadowFrameSkip = 0 ;
triangleCount = 0 ;
smoothedRenderFps = 0 ;
shadowTextureSize = 0 ;
shadows = sDisabled ;
shadowMapFrame = 0 ;
textures3D = false ;
photoMode = false ;
focusArrows = false ;
pointCount = 0 ;
maxLights = 0 ;
waterAnim = 0 ;
2010-07-30 09:51:39 +02:00
this - > allowRenderUnitTitles = false ;
this - > menu = NULL ;
this - > game = NULL ;
2011-12-02 17:07:59 +01:00
this - > gameCamera = NULL ;
2010-07-30 09:51:39 +02:00
showDebugUI = false ;
2011-02-06 08:01:54 +01:00
showDebugUILevel = debugui_fps ;
2010-07-30 09:51:39 +02:00
modelRenderer = NULL ;
textRenderer = NULL ;
2011-06-08 09:18:06 +02:00
textRenderer3D = NULL ;
2010-07-30 09:51:39 +02:00
particleRenderer = NULL ;
2010-10-30 04:21:47 +02:00
saveScreenShotThread = NULL ;
2011-02-05 06:50:42 +01:00
mapSurfaceData . clear ( ) ;
2011-04-18 18:51:30 +02:00
visibleFrameUnitList . clear ( ) ;
visibleFrameUnitListCameraKey = " " ;
2010-07-30 09:51:39 +02:00
2011-12-02 17:07:59 +01:00
quadCache = VisibleQuadContainerCache ( ) ;
2013-02-11 23:51:36 +01:00
quadCache . clearFrustumData ( ) ;
2011-12-02 17:07:59 +01:00
2010-09-03 03:50:16 +02:00
lastRenderFps = MIN_FPS_NORMAL_RENDERING ;
shadowsOffDueToMinRender = false ;
2011-10-22 21:45:05 +02:00
shadowMapHandle = 0 ;
shadowMapHandleValid = false ;
2012-05-24 08:16:54 +02:00
//list3d=0;
//list3dValid=false;
//list2d=0;
//list2dValid=false;
//list3dMenu=0;
//list3dMenuValid=false;
//customlist3dMenu=NULL;
2012-05-28 18:51:56 +02:00
//this->mm3d = NULL;
2012-05-28 04:36:12 +02:00
this - > custom_mm3d = NULL ;
2010-09-03 03:50:16 +02:00
2012-03-13 02:34:14 +01:00
this - > program = NULL ;
2010-07-30 09:51:39 +02:00
//resources
2010-09-10 10:51:32 +02:00
for ( int i = 0 ; i < rsCount ; + + i ) {
2010-07-30 09:51:39 +02:00
modelManager [ i ] = NULL ;
textureManager [ i ] = NULL ;
particleManager [ i ] = NULL ;
fontManager [ i ] = NULL ;
}
2010-03-13 22:10:45 +01:00
Config & config = Config : : getInstance ( ) ;
2011-05-02 00:48:44 +02:00
Renderer : : perspFarPlane = config . getFloat ( " PerspectiveFarPlane " , floatToStr ( Renderer : : perspFarPlane ) . c_str ( ) ) ;
2010-09-10 10:51:32 +02:00
this - > no2DMouseRendering = config . getBool ( " No2DMouseRendering " , " false " ) ;
this - > maxConsoleLines = config . getInt ( " ConsoleMaxLines " ) ;
2010-06-24 03:23:18 +02:00
2012-03-29 20:14:25 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] Renderer::perspFarPlane [%f] this->no2DMouseRendering [%d] this->maxConsoleLines [%d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , Renderer : : perspFarPlane , this - > no2DMouseRendering , this - > maxConsoleLines ) ;
2011-05-02 00:48:44 +02:00
2011-09-27 07:29:57 +02:00
GraphicsInterface & gi = GraphicsInterface : : getInstance ( ) ;
FactoryRepository & fr = FactoryRepository : : getInstance ( ) ;
2010-03-13 22:10:45 +01:00
gi . setFactory ( fr . getGraphicsFactory ( config . getString ( " FactoryGraphics " ) ) ) ;
GraphicsFactory * graphicsFactory = GraphicsInterface : : getInstance ( ) . getFactory ( ) ;
2011-12-02 23:04:02 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = false ) {
2011-09-27 07:29:57 +02:00
modelRenderer = graphicsFactory - > newModelRenderer ( ) ;
textRenderer = graphicsFactory - > newTextRenderer2D ( ) ;
textRenderer3D = graphicsFactory - > newTextRenderer3D ( ) ;
particleRenderer = graphicsFactory - > newParticleRenderer ( ) ;
}
2010-03-13 22:10:45 +01:00
//resources
2010-09-10 10:51:32 +02:00
for ( int i = 0 ; i < rsCount ; + + i ) {
2011-12-02 23:04:02 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = false ) {
2011-09-27 07:29:57 +02:00
modelManager [ i ] = graphicsFactory - > newModelManager ( ) ;
textureManager [ i ] = graphicsFactory - > newTextureManager ( ) ;
modelManager [ i ] - > setTextureManager ( textureManager [ i ] ) ;
fontManager [ i ] = graphicsFactory - > newFontManager ( ) ;
}
2010-03-13 22:10:45 +01:00
particleManager [ i ] = graphicsFactory - > newParticleManager ( ) ;
}
2010-12-24 03:10:31 +01:00
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = false ) {
2013-01-23 15:51:28 +01:00
static string mutexOwnerId = string ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) ) + string ( " _ " ) + intToStr ( __LINE__ ) ;
2011-12-03 01:39:03 +01:00
saveScreenShotThread = new SimpleTaskThread ( this , 0 , 25 ) ;
2013-01-23 15:51:28 +01:00
saveScreenShotThread - > setUniqueID ( mutexOwnerId ) ;
2011-12-03 01:39:03 +01:00
saveScreenShotThread - > start ( ) ;
}
2010-03-13 22:10:45 +01:00
}
2011-02-12 08:34:32 +01:00
void Renderer : : cleanupScreenshotThread ( ) {
if ( saveScreenShotThread ) {
saveScreenShotThread - > signalQuit ( ) ;
2013-01-23 15:51:28 +01:00
// for(time_t elapsed = time(NULL);
// getSaveScreenQueueSize() > 0 && difftime((long int)time(NULL),elapsed) <= 7;) {
// sleep(0);
// }
// if(saveScreenShotThread->canShutdown(true) == true &&
// saveScreenShotThread->shutdownAndWait() == true) {
// //printf("IN MenuStateCustomGame cleanup - C\n");
// delete saveScreenShotThread;
// }
// saveScreenShotThread = NULL;
if ( saveScreenShotThread - > shutdownAndWait ( ) = = true ) {
2011-02-12 08:34:32 +01:00
delete saveScreenShotThread ;
}
saveScreenShotThread = NULL ;
2013-01-23 15:51:28 +01:00
2011-02-12 08:34:32 +01:00
if ( getSaveScreenQueueSize ( ) > 0 ) {
2012-03-29 20:14:25 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] FORCING MEMORY CLEANUP and NOT SAVING screenshots, saveScreenQueue.size() = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , saveScreenQueue . size ( ) ) ;
2011-02-12 08:34:32 +01:00
2013-01-23 15:51:28 +01:00
static string mutexOwnerId = string ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) ) + string ( " _ " ) + intToStr ( __LINE__ ) ;
2013-12-25 07:27:44 +01:00
MutexSafeWrapper safeMutex ( saveScreenShotThreadAccessor , mutexOwnerId ) ;
2011-02-12 08:34:32 +01:00
for ( std : : list < std : : pair < string , Pixmap2D * > > : : iterator iter = saveScreenQueue . begin ( ) ;
iter ! = saveScreenQueue . end ( ) ; + + iter ) {
delete iter - > second ;
}
saveScreenQueue . clear ( ) ;
}
}
}
2010-10-30 04:21:47 +02:00
Renderer : : ~ Renderer ( ) {
2013-01-23 15:51:28 +01:00
try {
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
delete modelRenderer ;
modelRenderer = NULL ;
delete textRenderer ;
textRenderer = NULL ;
delete textRenderer3D ;
textRenderer3D = NULL ;
delete particleRenderer ;
particleRenderer = NULL ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
//resources
for ( int i = 0 ; i < rsCount ; + + i ) {
delete modelManager [ i ] ;
modelManager [ i ] = NULL ;
delete textureManager [ i ] ;
textureManager [ i ] = NULL ;
delete particleManager [ i ] ;
particleManager [ i ] = NULL ;
delete fontManager [ i ] ;
fontManager [ i ] = NULL ;
}
2010-03-13 22:10:45 +01:00
2013-01-23 15:51:28 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-04-15 07:06:15 +02:00
2013-01-23 15:51:28 +01:00
// Wait for the queue to become empty or timeout the thread at 7 seconds
cleanupScreenshotThread ( ) ;
2010-09-17 06:59:32 +02:00
2013-01-23 15:51:28 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-12-02 17:07:59 +01:00
2013-01-23 15:51:28 +01:00
mapSurfaceData . clear ( ) ;
quadCache = VisibleQuadContainerCache ( ) ;
2013-02-11 23:51:36 +01:00
quadCache . clearFrustumData ( ) ;
2013-01-23 15:51:28 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
this - > menu = NULL ;
this - > game = NULL ;
this - > gameCamera = NULL ;
2013-12-25 07:27:44 +01:00
delete saveScreenShotThreadAccessor ;
saveScreenShotThreadAccessor = NULL ;
2013-01-23 15:51:28 +01:00
}
catch ( const exception & e ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s Line: %d] \n Error [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , e . what ( ) ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , szBuf ) ;
throw megaglest_runtime_error ( szBuf ) ;
}
2010-03-13 22:10:45 +01:00
}
2013-11-07 19:39:08 +01:00
void Renderer : : simpleTask ( BaseThread * callingThread , void * userdata ) {
2010-10-30 04:21:47 +02:00
// This code reads pixmaps from a queue and saves them to disk
Pixmap2D * savePixMapBuffer = NULL ;
string path = " " ;
2012-03-29 20:14:25 +02:00
static string mutexOwnerId = string ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) ) + string ( " _ " ) + intToStr ( __LINE__ ) ;
2013-12-25 07:27:44 +01:00
MutexSafeWrapper safeMutex ( saveScreenShotThreadAccessor , mutexOwnerId ) ;
2011-09-01 01:10:43 +02:00
if ( saveScreenQueue . empty ( ) = = false ) {
2012-03-29 20:14:25 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] saveScreenQueue.size() = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , saveScreenQueue . size ( ) ) ;
2010-10-30 04:21:47 +02:00
savePixMapBuffer = saveScreenQueue . front ( ) . second ;
path = saveScreenQueue . front ( ) . first ;
saveScreenQueue . pop_front ( ) ;
}
safeMutex . ReleaseLock ( ) ;
if ( savePixMapBuffer ! = NULL ) {
2012-03-29 20:14:25 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] about to save [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , path . c_str ( ) ) ;
2010-10-30 04:21:47 +02:00
savePixMapBuffer - > save ( path ) ;
delete savePixMapBuffer ;
}
}
2011-03-28 23:04:47 +02:00
bool Renderer : : isEnded ( ) {
return Renderer : : rendererEnded ;
}
2011-12-02 23:04:02 +01:00
Renderer & Renderer : : getInstance ( ) {
static Renderer renderer ;
2010-03-13 22:10:45 +01:00
return renderer ;
}
2010-04-04 06:14:27 +02:00
void Renderer : : reinitAll ( ) {
2010-04-05 22:42:05 +02:00
//resources
2011-12-02 23:04:02 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
2011-09-27 07:29:57 +02:00
return ;
}
2010-04-05 22:42:05 +02:00
for ( int i = 0 ; i < rsCount ; + + i ) {
2010-04-06 22:10:38 +02:00
//modelManager[i]->init();
2010-04-05 22:42:05 +02:00
textureManager [ i ] - > init ( true ) ;
//particleManager[i]->init();
2010-04-06 22:10:38 +02:00
//fontManager[i]->init();
2010-04-04 06:14:27 +02:00
}
}
2010-03-13 22:10:45 +01:00
// ==================== init ====================
2011-01-15 09:45:17 +01:00
void Renderer : : init ( ) {
2012-08-10 08:19:35 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
Config & config = Config : : getInstance ( ) ;
2012-08-10 08:19:35 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
loadConfig ( ) ;
2012-08-10 08:19:35 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-12-02 23:04:02 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
2011-09-27 09:01:08 +02:00
return ;
}
2012-08-10 08:19:35 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
if ( config . getBool ( " CheckGlCaps " ) ) {
2012-08-10 08:19:35 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
checkGlCaps ( ) ;
}
2012-08-10 08:19:35 +02:00
if ( glActiveTexture = = NULL ) {
char szBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " Error: glActiveTexture == NULL \n glActiveTexture is only supported if the GL version is 1.3 or greater, \n or if the ARB_multitexture extension is supported! " ) ;
2012-08-10 08:19:35 +02:00
throw megaglest_runtime_error ( szBuf ) ;
}
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
if ( config . getBool ( " FirstTime " ) ) {
2012-08-10 08:19:35 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
config . setBool ( " FirstTime " , false ) ;
autoConfig ( ) ;
2012-08-10 08:19:35 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
config . save ( ) ;
}
2012-08-10 08:19:35 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
modelManager [ rsGlobal ] - > init ( ) ;
2012-08-10 08:19:35 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
textureManager [ rsGlobal ] - > init ( ) ;
2012-08-10 08:19:35 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
fontManager [ rsGlobal ] - > init ( ) ;
2012-08-10 08:19:35 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
init2dList ( ) ;
2010-07-16 02:42:13 +02:00
2012-08-10 08:19:35 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-07-16 02:42:13 +02:00
glHint ( GL_FOG_HINT , GL_FASTEST ) ;
2012-08-10 08:19:35 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-07-16 02:42:13 +02:00
//glHint(GL_GENERATE_MIPMAP_HINT, GL_FASTEST);
glHint ( GL_LINE_SMOOTH_HINT , GL_FASTEST ) ;
2012-08-10 08:19:35 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-07-16 02:42:13 +02:00
//glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
//glHint(GL_POINT_SMOOTH_HINT, GL_FASTEST);
//glHint(GL_POLYGON_SMOOTH_HINT, GL_FASTEST);
glHint ( GL_TEXTURE_COMPRESSION_HINT , GL_FASTEST ) ;
2012-08-10 08:19:35 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-07-16 02:42:13 +02:00
2010-03-13 22:10:45 +01:00
}
2011-12-02 17:07:59 +01:00
void Renderer : : initGame ( const Game * game , GameCamera * gameCamera ) {
2012-08-10 08:19:35 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2012-03-29 20:14:25 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-04-04 06:14:27 +02:00
2012-08-10 08:19:35 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-12-02 17:07:59 +01:00
this - > gameCamera = gameCamera ;
2011-11-30 22:27:03 +01:00
VisibleQuadContainerCache : : enableFrustumCalcs = Config : : getInstance ( ) . getBool ( " EnableFrustrumCalcs " , " true " ) ;
2011-11-30 07:58:26 +01:00
quadCache = VisibleQuadContainerCache ( ) ;
2013-02-11 23:51:36 +01:00
quadCache . clearFrustumData ( ) ;
2011-11-30 07:58:26 +01:00
2011-02-05 06:07:05 +01:00
SurfaceData : : nextUniqueId = 1 ;
2011-02-05 06:50:42 +01:00
mapSurfaceData . clear ( ) ;
2010-03-13 22:10:45 +01:00
this - > game = game ;
2012-06-22 15:30:15 +02:00
worldToScreenPosCache . clear ( ) ;
2010-03-13 22:10:45 +01:00
//vars
shadowMapFrame = 0 ;
waterAnim = 0 ;
2012-08-10 08:19:35 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2012-03-29 20:14:25 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-04-04 06:14:27 +02:00
2011-12-02 23:04:02 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
2011-09-27 07:29:57 +02:00
return ;
}
2011-09-27 09:01:08 +02:00
//check gl caps
2012-08-10 08:19:35 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-09-27 09:01:08 +02:00
checkGlOptionalCaps ( ) ;
2010-03-13 22:10:45 +01:00
//shadows
2011-01-15 09:45:17 +01:00
if ( shadows = = sProjected | | shadows = = sShadowMapping ) {
2010-03-13 22:10:45 +01:00
static_cast < ModelRendererGl * > ( modelRenderer ) - > setSecondaryTexCoordUnit ( 2 ) ;
2013-09-22 15:55:20 +02:00
Config & config = Config : : getInstance ( ) ;
2010-03-13 22:10:45 +01:00
glGenTextures ( 1 , & shadowMapHandle ) ;
2011-10-22 21:45:05 +02:00
shadowMapHandleValid = true ;
2013-09-22 15:55:20 +02:00
shadowIntensity = config . getFloat ( " ShadowIntensity " , " 1.0 " ) ;
if ( game ! = NULL ) {
shadowIntensity = shadowIntensity * game - > getWorld ( ) - > getTileset ( ) - > getShadowIntense ( ) ;
if ( shadowIntensity > 1.0f ) {
shadowIntensity = 1.0f ;
}
}
2010-03-13 22:10:45 +01:00
glBindTexture ( GL_TEXTURE_2D , shadowMapHandle ) ;
glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_WRAP_S , GL_CLAMP_TO_EDGE ) ;
glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_WRAP_T , GL_CLAMP_TO_EDGE ) ;
glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_LINEAR ) ;
glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_LINEAR ) ;
2011-01-15 09:45:17 +01:00
if ( shadows = = sShadowMapping ) {
2012-03-29 20:14:25 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-04-04 06:14:27 +02:00
2010-03-13 22:10:45 +01:00
//shadow mapping
glTexParameteri ( GL_TEXTURE_2D , GL_DEPTH_TEXTURE_MODE , GL_LUMINANCE ) ;
2010-10-27 17:04:47 +02:00
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB);
glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_COMPARE_MODE_ARB , GL_NONE ) ;
2010-03-13 22:10:45 +01:00
glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_COMPARE_FUNC_ARB , GL_LEQUAL ) ;
2010-10-27 17:04:47 +02:00
//glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FAIL_VALUE_ARB, 1.0f-shadowAlpha);
2010-03-13 22:10:45 +01:00
glTexImage2D ( GL_TEXTURE_2D , 0 , GL_DEPTH_COMPONENT32 ,
shadowTextureSize , shadowTextureSize ,
0 , GL_DEPTH_COMPONENT , GL_UNSIGNED_BYTE , NULL ) ;
}
2011-01-15 09:45:17 +01:00
else {
2012-03-29 20:14:25 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-04-04 06:14:27 +02:00
2010-03-13 22:10:45 +01:00
//projected
glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGB8 ,
shadowTextureSize , shadowTextureSize ,
0 , GL_LUMINANCE , GL_UNSIGNED_BYTE , NULL ) ;
}
shadowMapFrame = - 1 ;
}
2012-03-29 20:14:25 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-04-04 06:14:27 +02:00
2010-07-13 07:33:43 +02:00
IF_DEBUG_EDITION ( getDebugRenderer ( ) . init ( ) ; )
2010-03-13 22:10:45 +01:00
//texture init
modelManager [ rsGame ] - > init ( ) ;
textureManager [ rsGame ] - > init ( ) ;
fontManager [ rsGame ] - > init ( ) ;
2012-03-29 20:14:25 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-04-04 06:14:27 +02:00
2010-03-13 22:10:45 +01:00
init3dList ( ) ;
}
2012-03-14 08:23:41 +01:00
void Renderer : : manageDeferredParticleSystems ( ) {
2013-12-23 01:10:00 +01:00
// if(deferredParticleSystems.empty() == false) {
// printf("deferredParticleSystems.size() = %d\n",(int)deferredParticleSystems.size());
// }
2012-03-14 08:23:41 +01:00
for ( unsigned int i = 0 ; i < deferredParticleSystems . size ( ) ; + + i ) {
std : : pair < ParticleSystem * , ResourceScope > & deferredParticleSystem = deferredParticleSystems [ i ] ;
ParticleSystem * ps = deferredParticleSystem . first ;
ResourceScope rs = deferredParticleSystem . second ;
if ( ps - > getTextureFileLoadDeferred ( ) ! = " " & & ps - > getTexture ( ) = = NULL ) {
2012-03-19 22:35:54 +01:00
CoreData : : TextureSystemType textureSystemId =
static_cast < CoreData : : TextureSystemType > (
ps - > getTextureFileLoadDeferredSystemId ( ) ) ;
2014-11-28 00:28:49 +01:00
//printf("Load DEFERRED particle i = %d textureSystemId = %d\n",i,textureSystemId);
2012-03-19 22:35:54 +01:00
if ( textureSystemId ! = CoreData : : tsyst_NONE ) {
Texture2D * texture = CoreData : : getInstance ( ) . getTextureBySystemId ( textureSystemId ) ;
//printf("Loading texture from system [%d] [%p]\n",textureSystemId,texture);
2012-03-14 08:23:41 +01:00
ps - > setTexture ( texture ) ;
2014-11-28 00:28:49 +01:00
//printf("#2 Load DEFERRED particle i = %d textureSystemId = %d, texture = %p\n",i,textureSystemId,texture);
2012-03-14 08:23:41 +01:00
}
2012-03-19 22:35:54 +01:00
else {
Texture2D * texture = newTexture2D ( rs ) ;
if ( texture ) {
texture - > setFormat ( ps - > getTextureFileLoadDeferredFormat ( ) ) ;
texture - > getPixmap ( ) - > init ( ps - > getTextureFileLoadDeferredComponents ( ) ) ;
}
if ( texture ) {
2012-03-29 20:14:25 +02:00
string textureFile = ps - > getTextureFileLoadDeferred ( ) ;
if ( fileExists ( textureFile ) = = false ) {
textureFile = Config : : findValidLocalFileFromPath ( textureFile ) ;
}
texture - > load ( textureFile ) ;
2012-03-19 22:35:54 +01:00
ps - > setTexture ( texture ) ;
}
2014-11-28 00:28:49 +01:00
//printf("#3 Load DEFERRED particle i = %d textureSystemId = %d, texture = %p\n",i,textureSystemId,texture);
2012-03-19 22:35:54 +01:00
}
2012-03-14 08:23:41 +01:00
}
if ( dynamic_cast < GameParticleSystem * > ( ps ) ! = NULL ) {
GameParticleSystem * gps = dynamic_cast < GameParticleSystem * > ( ps ) ;
2013-12-14 08:04:12 +01:00
if ( gps ! = NULL & & gps - > getModelFileLoadDeferred ( ) ! = " " & & gps - > getModel ( ) = = NULL ) {
2013-12-05 16:17:41 +01:00
std : : map < string , vector < pair < string , string > > > loadedFileList ;
Model * model = newModel ( rsGame , gps - > getModelFileLoadDeferred ( ) , false , & loadedFileList , NULL ) ;
if ( model )
gps - > setModel ( model ) ;
2012-03-14 08:23:41 +01:00
}
}
2012-03-19 22:35:54 +01:00
manageParticleSystem ( ps , rs ) ;
2013-12-23 01:10:00 +01:00
//printf("Managing ps [%p]\n",ps);
2012-03-14 08:23:41 +01:00
}
deferredParticleSystems . clear ( ) ;
//printf("After deferredParticleSystems.size() = %d\n",deferredParticleSystems.size());
}
2011-01-15 09:45:17 +01:00
void Renderer : : initMenu ( const MainMenu * mm ) {
2012-03-29 20:14:25 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-04-04 06:14:27 +02:00
this - > menu = mm ;
2012-03-29 20:14:25 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-04-04 06:14:27 +02:00
2011-12-02 23:04:02 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
2011-09-27 07:29:57 +02:00
return ;
}
2010-03-13 22:10:45 +01:00
modelManager [ rsMenu ] - > init ( ) ;
textureManager [ rsMenu ] - > init ( ) ;
fontManager [ rsMenu ] - > init ( ) ;
//modelRenderer->setCustomTexture(CoreData::getInstance().getCustomTexture());
2012-03-29 20:14:25 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-04-04 06:14:27 +02:00
2012-05-28 18:51:56 +02:00
//init3dListMenu(mm);
2010-04-04 06:14:27 +02:00
2012-03-29 20:14:25 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
}
2011-01-15 09:45:17 +01:00
void Renderer : : reset3d ( ) {
2010-03-13 22:10:45 +01:00
assertGl ( ) ;
glLightModeli ( GL_LIGHT_MODEL_COLOR_CONTROL , GL_SEPARATE_SPECULAR_COLOR ) ;
2012-05-24 08:16:54 +02:00
//glCallList(list3d);
render3dSetup ( ) ;
2010-03-13 22:10:45 +01:00
pointCount = 0 ;
triangleCount = 0 ;
assertGl ( ) ;
}
2011-01-15 09:45:17 +01:00
void Renderer : : reset2d ( ) {
2010-03-13 22:10:45 +01:00
assertGl ( ) ;
glLightModeli ( GL_LIGHT_MODEL_COLOR_CONTROL , GL_SINGLE_COLOR ) ;
2012-05-24 08:16:54 +02:00
//glCallList(list2d);
render2dMenuSetup ( ) ;
2010-03-13 22:10:45 +01:00
assertGl ( ) ;
}
2011-01-15 09:45:17 +01:00
void Renderer : : reset3dMenu ( ) {
2010-03-13 22:10:45 +01:00
assertGl ( ) ;
glLightModeli ( GL_LIGHT_MODEL_COLOR_CONTROL , GL_SINGLE_COLOR ) ;
2012-05-28 04:36:12 +02:00
//printf("In [%s::%s Line: %d] this->custom_mm3d [%p] this->mm3d [%p]\n",__FILE__,__FUNCTION__,__LINE__,this->custom_mm3d,this->mm3d);
2012-05-24 08:16:54 +02:00
if ( this - > custom_mm3d ! = NULL ) {
render3dMenuSetup ( this - > custom_mm3d ) ;
//glCallList(*this->customlist3dMenu);
2011-10-05 05:42:29 +02:00
}
else {
2012-05-28 18:51:56 +02:00
render3dMenuSetup ( this - > menu ) ;
//render3dMenuSetup(this->mm3d);
2012-05-24 08:16:54 +02:00
//glCallList(list3dMenu);
2011-10-05 05:42:29 +02:00
}
2010-03-13 22:10:45 +01:00
assertGl ( ) ;
}
// ==================== end ====================
2011-01-15 09:45:17 +01:00
void Renderer : : end ( ) {
2011-12-02 17:07:59 +01:00
quadCache = VisibleQuadContainerCache ( ) ;
2013-02-11 23:51:36 +01:00
quadCache . clearFrustumData ( ) ;
2011-12-02 17:07:59 +01:00
2011-03-28 23:04:47 +02:00
if ( Renderer : : rendererEnded = = true ) {
return ;
}
2011-01-26 10:09:59 +01:00
std : : map < string , Texture2D * > & crcFactionPreviewTextureCache = CacheManager : : getCachedItem < std : : map < string , Texture2D * > > ( GameConstants : : factionPreviewTextureCacheLookupKey ) ;
crcFactionPreviewTextureCache . clear ( ) ;
2011-02-12 08:34:32 +01:00
// Wait for the queue to become empty or timeout the thread at 7 seconds
cleanupScreenshotThread ( ) ;
mapSurfaceData . clear ( ) ;
2010-03-13 22:10:45 +01:00
//delete resources
2011-02-12 09:05:18 +01:00
if ( modelManager [ rsGlobal ] ) {
modelManager [ rsGlobal ] - > end ( ) ;
}
if ( textureManager [ rsGlobal ] ) {
textureManager [ rsGlobal ] - > end ( ) ;
}
if ( fontManager [ rsGlobal ] ) {
fontManager [ rsGlobal ] - > end ( ) ;
}
if ( particleManager [ rsGlobal ] ) {
particleManager [ rsGlobal ] - > end ( ) ;
}
2010-03-13 22:10:45 +01:00
//delete 2d list
2012-05-24 08:16:54 +02:00
//if(list2dValid == true) {
// glDeleteLists(list2d, 1);
// list2dValid=false;
//}
2011-03-28 23:04:47 +02:00
Renderer : : rendererEnded = true ;
2010-03-13 22:10:45 +01:00
}
2011-10-06 20:04:59 +02:00
void Renderer : : endScenario ( ) {
2011-12-02 17:07:59 +01:00
this - > game = NULL ;
this - > gameCamera = NULL ;
quadCache = VisibleQuadContainerCache ( ) ;
2013-02-11 23:51:36 +01:00
quadCache . clearFrustumData ( ) ;
2011-10-06 20:04:59 +02:00
2011-12-02 23:04:02 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
2011-10-06 20:04:59 +02:00
return ;
}
//delete resources
//modelManager[rsGame]->end();
//textureManager[rsGame]->end();
//fontManager[rsGame]->end();
//particleManager[rsGame]->end();
2011-10-22 21:45:05 +02:00
if ( shadowMapHandleValid = = true & &
( shadows = = sProjected | | shadows = = sShadowMapping ) ) {
2011-10-06 20:04:59 +02:00
glDeleteTextures ( 1 , & shadowMapHandle ) ;
2011-10-22 21:45:05 +02:00
shadowMapHandleValid = false ;
2011-10-06 20:04:59 +02:00
}
2012-05-24 08:16:54 +02:00
//if(list3dValid == true) {
// glDeleteLists(list3d, 1);
// list3dValid=false;
//}
2011-10-06 20:04:59 +02:00
2012-06-22 15:30:15 +02:00
worldToScreenPosCache . clear ( ) ;
2011-10-06 20:04:59 +02:00
ReleaseSurfaceVBOs ( ) ;
mapSurfaceData . clear ( ) ;
}
2011-10-22 21:45:05 +02:00
void Renderer : : endGame ( bool isFinalEnd ) {
2011-12-02 17:07:59 +01:00
this - > game = NULL ;
this - > gameCamera = NULL ;
2013-09-22 15:55:20 +02:00
Config & config = Config : : getInstance ( ) ;
2010-03-13 22:10:45 +01:00
2013-05-28 09:10:13 +02:00
try {
quadCache = VisibleQuadContainerCache ( ) ;
quadCache . clearFrustumData ( ) ;
}
catch ( const exception & e ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s Line: %d] \n Error [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , e . what ( ) ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , szBuf ) ;
abort ( ) ;
}
2011-11-30 07:58:26 +01:00
2011-10-22 21:45:05 +02:00
if ( isFinalEnd ) {
//delete resources
2011-12-02 23:04:02 +01:00
if ( modelManager [ rsGame ] ! = NULL ) {
modelManager [ rsGame ] - > end ( ) ;
}
if ( textureManager [ rsGame ] ! = NULL ) {
textureManager [ rsGame ] - > end ( ) ;
}
if ( fontManager [ rsGame ] ! = NULL ) {
fontManager [ rsGame ] - > end ( ) ;
}
if ( particleManager [ rsGame ] ! = NULL ) {
particleManager [ rsGame ] - > end ( ) ;
}
}
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
2011-10-22 21:45:05 +02:00
}
2010-03-13 22:10:45 +01:00
2011-10-22 21:45:05 +02:00
if ( shadowMapHandleValid = = true & &
( shadows = = sProjected | | shadows = = sShadowMapping ) ) {
2010-03-13 22:10:45 +01:00
glDeleteTextures ( 1 , & shadowMapHandle ) ;
2011-10-22 21:45:05 +02:00
shadowMapHandleValid = false ;
2010-03-13 22:10:45 +01:00
}
2013-09-22 15:55:20 +02:00
shadowIntensity = config . getFloat ( " ShadowIntensity " , " 1.0 " ) ;
2010-03-13 22:10:45 +01:00
2012-05-24 08:16:54 +02:00
//if(list3dValid == true) {
// glDeleteLists(list3d, 1);
// list3dValid=false;
//}
2010-11-02 20:52:20 +01:00
2012-06-22 15:30:15 +02:00
worldToScreenPosCache . clear ( ) ;
2011-02-05 06:07:05 +01:00
ReleaseSurfaceVBOs ( ) ;
2011-02-05 06:50:42 +01:00
mapSurfaceData . clear ( ) ;
2010-03-13 22:10:45 +01:00
}
2011-01-15 09:45:17 +01:00
void Renderer : : endMenu ( ) {
2010-04-04 06:14:27 +02:00
this - > menu = NULL ;
2011-09-27 07:29:57 +02:00
2010-03-13 22:10:45 +01:00
//delete resources
2011-10-12 07:24:30 +02:00
if ( modelManager [ rsMenu ] ) {
modelManager [ rsMenu ] - > end ( ) ;
}
if ( textureManager [ rsMenu ] ) {
textureManager [ rsMenu ] - > end ( ) ;
}
if ( fontManager [ rsMenu ] ) {
fontManager [ rsMenu ] - > end ( ) ;
}
if ( particleManager [ rsMenu ] ) {
particleManager [ rsMenu ] - > end ( ) ;
}
2010-03-13 22:10:45 +01:00
2011-12-02 23:04:02 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2012-05-24 08:16:54 +02:00
//if(this->customlist3dMenu != NULL) {
// glDeleteLists(*this->customlist3dMenu,1);
//}
//else {
// glDeleteLists(list3dMenu, 1);
//}
2010-03-13 22:10:45 +01:00
}
2017-10-10 05:21:14 +02:00
//void Renderer::reloadResources() {
// if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
// return;
// }
//
// for(int i=0; i<rsCount; ++i) {
// modelManager[i]->end();
// textureManager[i]->end();
// fontManager[i]->end();
// }
//
// for(int i=0; i<rsCount; ++i) {
// modelManager[i]->init();
// textureManager[i]->init();
// fontManager[i]->init();
// }
//}
2010-03-13 22:10:45 +01:00
// ==================== engine interface ====================
2010-04-05 21:38:50 +02:00
void Renderer : : initTexture ( ResourceScope rs , Texture * texture ) {
2011-12-02 23:04:02 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
2011-09-27 07:29:57 +02:00
return ;
}
2010-04-05 21:38:50 +02:00
textureManager [ rs ] - > initTexture ( texture ) ;
}
2010-06-24 12:52:58 +02:00
void Renderer : : endTexture ( ResourceScope rs , Texture * texture , bool mustExistInList ) {
2011-03-31 03:34:01 +02:00
string textureFilename = texture - > getPath ( ) ;
2012-03-29 20:14:25 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] free texture from manager [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , textureFilename . c_str ( ) ) ;
2011-03-31 03:34:01 +02:00
2011-12-02 23:04:02 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
2011-09-27 07:29:57 +02:00
return ;
}
2010-06-24 12:52:58 +02:00
textureManager [ rs ] - > endTexture ( texture , mustExistInList ) ;
2011-03-31 03:34:01 +02:00
if ( rs = = rsGlobal ) {
std : : map < string , Texture2D * > & crcFactionPreviewTextureCache = CacheManager : : getCachedItem < std : : map < string , Texture2D * > > ( GameConstants : : factionPreviewTextureCacheLookupKey ) ;
if ( crcFactionPreviewTextureCache . find ( textureFilename ) ! = crcFactionPreviewTextureCache . end ( ) ) {
2012-03-29 20:14:25 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] textureFilename [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , textureFilename . c_str ( ) ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] free texture from cache [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , textureFilename . c_str ( ) ) ;
2011-03-31 03:34:01 +02:00
crcFactionPreviewTextureCache . erase ( textureFilename ) ;
}
}
2010-06-24 12:52:58 +02:00
}
void Renderer : : endLastTexture ( ResourceScope rs , bool mustExistInList ) {
2011-12-02 23:04:02 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
2011-09-27 07:29:57 +02:00
return ;
}
2010-06-24 12:52:58 +02:00
textureManager [ rs ] - > endLastTexture ( mustExistInList ) ;
2010-04-05 21:38:50 +02:00
}
2013-12-05 16:17:41 +01:00
Model * Renderer : : newModel ( ResourceScope rs , const string & path , bool deletePixMapAfterLoad , std : : map < string , vector < pair < string , string > > > * loadedFileList , string * sourceLoader ) {
2011-12-02 23:04:02 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
2011-09-27 07:29:57 +02:00
return NULL ;
}
2013-12-05 16:17:41 +01:00
return modelManager [ rs ] - > newModel ( path , deletePixMapAfterLoad , loadedFileList , sourceLoader ) ;
2010-03-13 22:10:45 +01:00
}
2010-06-24 12:52:58 +02:00
void Renderer : : endModel ( ResourceScope rs , Model * model , bool mustExistInList ) {
2011-12-02 23:04:02 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
2011-09-27 07:29:57 +02:00
return ;
}
2010-06-24 12:52:58 +02:00
modelManager [ rs ] - > endModel ( model , mustExistInList ) ;
}
void Renderer : : endLastModel ( ResourceScope rs , bool mustExistInList ) {
2011-12-02 23:04:02 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
2011-09-27 07:29:57 +02:00
return ;
}
2010-06-24 12:52:58 +02:00
modelManager [ rs ] - > endLastModel ( mustExistInList ) ;
}
2010-03-13 22:10:45 +01:00
Texture2D * Renderer : : newTexture2D ( ResourceScope rs ) {
2011-12-02 23:04:02 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
2011-09-27 07:29:57 +02:00
return NULL ;
}
2010-03-13 22:10:45 +01:00
return textureManager [ rs ] - > newTexture2D ( ) ;
}
Texture3D * Renderer : : newTexture3D ( ResourceScope rs ) {
2011-12-02 23:04:02 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
2011-09-27 07:29:57 +02:00
return NULL ;
}
2010-03-13 22:10:45 +01:00
return textureManager [ rs ] - > newTexture3D ( ) ;
}
Font2D * Renderer : : newFont ( ResourceScope rs ) {
2011-12-02 23:04:02 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
2011-09-27 07:29:57 +02:00
return NULL ;
}
2010-03-13 22:10:45 +01:00
return fontManager [ rs ] - > newFont2D ( ) ;
}
2011-06-08 09:18:06 +02:00
Font3D * Renderer : : newFont3D ( ResourceScope rs ) {
2011-12-02 23:04:02 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
2011-09-27 07:29:57 +02:00
return NULL ;
}
2011-06-08 09:18:06 +02:00
return fontManager [ rs ] - > newFont3D ( ) ;
}
2013-11-19 22:57:28 +01:00
void Renderer : : endFont ( : : Shared : : Graphics : : Font * font , ResourceScope rs , bool mustExistInList ) {
2011-12-02 23:04:02 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
2011-10-25 20:39:11 +02:00
return ;
}
fontManager [ rs ] - > endFont ( font , mustExistInList ) ;
}
2017-10-10 05:21:14 +02:00
//void Renderer::resetFontManager(ResourceScope rs) {
// if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
// return;
// }
// fontManager[rs]->end();
// fontManager[rsGlobal]->init();
//}
2011-10-25 20:39:11 +02:00
2012-03-14 08:23:41 +01:00
void Renderer : : addToDeferredParticleSystemList ( std : : pair < ParticleSystem * , ResourceScope > deferredParticleSystem ) {
deferredParticleSystems . push_back ( deferredParticleSystem ) ;
}
2010-03-13 22:10:45 +01:00
void Renderer : : manageParticleSystem ( ParticleSystem * particleSystem , ResourceScope rs ) {
particleManager [ rs ] - > manage ( particleSystem ) ;
}
2010-09-07 19:30:13 +02:00
bool Renderer : : validateParticleSystemStillExists ( ParticleSystem * particleSystem , ResourceScope rs ) const {
2010-09-09 00:54:02 +02:00
return particleManager [ rs ] - > validateParticleSystemStillExists ( particleSystem ) ;
2010-09-07 19:30:13 +02:00
}
2013-09-24 05:44:15 +02:00
void Renderer : : removeParticleSystemsForParticleOwner ( ParticleOwner * particleOwner , ResourceScope rs ) {
2015-01-10 00:51:19 +01:00
particleManager [ rs ] - > removeParticleSystemsForParticleOwner ( particleOwner ) ;
2013-09-24 05:44:15 +02:00
}
2010-09-06 19:52:33 +02:00
void Renderer : : cleanupParticleSystems ( vector < ParticleSystem * > & particleSystems , ResourceScope rs ) {
particleManager [ rs ] - > cleanupParticleSystems ( particleSystems ) ;
}
void Renderer : : cleanupUnitParticleSystems ( vector < UnitParticleSystem * > & particleSystems , ResourceScope rs ) {
particleManager [ rs ] - > cleanupUnitParticleSystems ( particleSystems ) ;
}
2010-08-24 03:21:34 +02:00
void Renderer : : updateParticleManager ( ResourceScope rs , int renderFps ) {
2010-08-26 03:25:27 +02:00
particleManager [ rs ] - > update ( renderFps ) ;
2010-03-13 22:10:45 +01:00
}
void Renderer : : renderParticleManager ( ResourceScope rs ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2010-03-13 22:10:45 +01:00
glPushAttrib ( GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ) ;
glDepthFunc ( GL_LESS ) ;
particleRenderer - > renderManager ( particleManager [ rs ] , modelRenderer ) ;
glPopAttrib ( ) ;
}
2011-01-15 09:45:17 +01:00
void Renderer : : swapBuffers ( ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2010-06-25 07:41:50 +02:00
//glFlush(); // should not be required - http://www.opengl.org/wiki/Common_Mistakes
2013-06-12 02:53:52 +02:00
//glFlush();
2010-06-28 02:25:12 +02:00
2010-03-13 22:10:45 +01:00
GraphicsInterface : : getInstance ( ) . getCurrentContext ( ) - > swapBuffers ( ) ;
}
// ==================== lighting ====================
//places all the opengl lights
2011-01-15 09:45:17 +01:00
void Renderer : : setupLighting ( ) {
2011-12-02 23:04:02 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
2011-09-27 07:29:57 +02:00
return ;
}
2010-03-13 22:10:45 +01:00
int lightCount = 0 ;
const World * world = game - > getWorld ( ) ;
const GameCamera * gameCamera = game - > getGameCamera ( ) ;
const TimeFlow * timeFlow = world - > getTimeFlow ( ) ;
float time = timeFlow - > getTime ( ) ;
assertGl ( ) ;
//sun/moon light
2012-01-07 21:24:54 +01:00
Vec3f lightColor = timeFlow - > computeLightColor ( ) ;
2010-03-13 22:10:45 +01:00
Vec3f fogColor = world - > getTileset ( ) - > getFogColor ( ) ;
Vec4f lightPos = timeFlow - > isDay ( ) ? computeSunPos ( time ) : computeMoonPos ( time ) ;
nearestLightPos = lightPos ;
glLightfv ( GL_LIGHT0 , GL_POSITION , lightPos . ptr ( ) ) ;
glLightfv ( GL_LIGHT0 , GL_AMBIENT , Vec4f ( lightColor * lightAmbFactor , 1.f ) . ptr ( ) ) ;
glLightfv ( GL_LIGHT0 , GL_DIFFUSE , Vec4f ( lightColor , 1.f ) . ptr ( ) ) ;
glLightfv ( GL_LIGHT0 , GL_SPECULAR , Vec4f ( 0.0f , 0.0f , 0.f , 1.f ) . ptr ( ) ) ;
glFogfv ( GL_FOG_COLOR , Vec4f ( fogColor * lightColor , 1.f ) . ptr ( ) ) ;
lightCount + + ;
//disable all secondary lights
2011-01-15 09:45:17 +01:00
for ( int i = 1 ; i < maxLights ; + + i ) {
2010-03-13 22:10:45 +01:00
glDisable ( GL_LIGHT0 + i ) ;
}
//unit lights (not projectiles)
2013-02-26 21:48:20 +01:00
if ( timeFlow - > isTotalNight ( ) ) {
VisibleQuadContainerCache & qCache = getQuadCache ( ) ;
if ( qCache . visibleQuadUnitList . empty ( ) = = false ) {
2013-05-17 05:59:34 +02:00
//bool modelRenderStarted = false;
2013-02-26 21:48:20 +01:00
for ( int visibleUnitIndex = 0 ;
2013-11-19 07:14:06 +01:00
visibleUnitIndex < ( int ) qCache . visibleQuadUnitList . size ( ) & & lightCount < maxLights ;
2013-02-26 21:48:20 +01:00
+ + visibleUnitIndex ) {
Unit * unit = qCache . visibleQuadUnitList [ visibleUnitIndex ] ;
if ( world - > toRenderUnit ( unit ) & &
2014-11-25 23:40:47 +01:00
unit - > getCurrMidHeightVector ( ) . dist ( gameCamera - > getPos ( ) ) < maxLightDist & &
2013-02-26 21:48:20 +01:00
unit - > getType ( ) - > getLight ( ) & & unit - > isOperative ( ) ) {
//printf("$$$ Show light for faction: %s # %d / %d for Unit [%d - %s]\n",world->getFaction(i)->getType()->getName().c_str(),lightCount,maxLights,unit->getId(),unit->getFullName().c_str());
2014-11-25 23:40:47 +01:00
Vec4f pos = Vec4f ( unit - > getCurrMidHeightVector ( ) ) ;
2013-02-26 21:48:20 +01:00
pos . y + = 4.f ;
GLenum lightEnum = GL_LIGHT0 + lightCount ;
glEnable ( lightEnum ) ;
glLightfv ( lightEnum , GL_POSITION , pos . ptr ( ) ) ;
glLightfv ( lightEnum , GL_AMBIENT , Vec4f ( unit - > getType ( ) - > getLightColor ( ) ) . ptr ( ) ) ;
glLightfv ( lightEnum , GL_DIFFUSE , Vec4f ( unit - > getType ( ) - > getLightColor ( ) ) . ptr ( ) ) ;
glLightfv ( lightEnum , GL_SPECULAR , Vec4f ( unit - > getType ( ) - > getLightColor ( ) * 0.3f ) . ptr ( ) ) ;
glLightf ( lightEnum , GL_QUADRATIC_ATTENUATION , 0.05f ) ;
+ + lightCount ;
const GameCamera * gameCamera = game - > getGameCamera ( ) ;
if ( Vec3f ( pos ) . dist ( gameCamera - > getPos ( ) ) < Vec3f ( nearestLightPos ) . dist ( gameCamera - > getPos ( ) ) ) {
nearestLightPos = pos ;
}
}
}
}
}
2010-03-13 22:10:45 +01:00
assertGl ( ) ;
}
2017-10-10 05:21:14 +02:00
//void Renderer::setupLightingForRotatedModel() {
// if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
// return;
// }
//
// const World *world= game->getWorld();
// //const GameCamera *gameCamera= game->getGameCamera();
// const TimeFlow *timeFlow= world->getTimeFlow();
// float time= timeFlow->getTime();
//
// assertGl();
//
// //sun/moon light
// Vec3f lightColor= timeFlow->computeLightColor();
// Vec3f fogColor= world->getTileset()->getFogColor();
// Vec4f lightPos= timeFlow->isDay()? computeSunPos(time): computeMoonPos(time);
// //nearestLightPos= lightPos;
//
// glLightfv(GL_LIGHT0, GL_POSITION, lightPos.ptr());
// glLightfv(GL_LIGHT0, GL_AMBIENT, Vec4f(lightColor*lightAmbFactor, 1.f).ptr());
// glLightfv(GL_LIGHT0, GL_DIFFUSE, Vec4f(lightColor, 1.f).ptr());
// glLightfv(GL_LIGHT0, GL_SPECULAR, Vec4f(0.0f, 0.0f, 0.f, 1.f).ptr());
//
// glFogfv(GL_FOG_COLOR, Vec4f(fogColor*lightColor, 1.f).ptr());
//
// assertGl();
//}
2012-08-13 23:46:27 +02:00
2011-01-15 09:45:17 +01:00
void Renderer : : loadGameCameraMatrix ( ) {
2010-03-13 22:10:45 +01:00
const GameCamera * gameCamera = game - > getGameCamera ( ) ;
glMatrixMode ( GL_MODELVIEW ) ;
glLoadIdentity ( ) ;
2011-06-08 09:18:06 +02:00
if ( gameCamera ! = NULL ) {
glRotatef ( gameCamera - > getVAng ( ) , - 1 , 0 , 0 ) ;
glRotatef ( gameCamera - > getHAng ( ) , 0 , 1 , 0 ) ;
2014-02-04 21:14:52 +01:00
glTranslatef ( - ( gameCamera - > getPos ( ) . x + gameCamera - > getShakeOffset ( ) . x ) ,
- gameCamera - > getPos ( ) . y ,
- ( gameCamera - > getPos ( ) . z + gameCamera - > getShakeOffset ( ) . y ) ) ;
2011-06-08 09:18:06 +02:00
}
2010-03-13 22:10:45 +01:00
}
2011-01-15 09:45:17 +01:00
void Renderer : : loadCameraMatrix ( const Camera * camera ) {
2010-06-23 16:49:20 +02:00
const Vec3f & position = camera - > getConstPosition ( ) ;
2010-03-13 22:10:45 +01:00
Quaternion orientation = camera - > getOrientation ( ) . conjugate ( ) ;
glMatrixMode ( GL_MODELVIEW ) ;
glLoadIdentity ( ) ;
glMultMatrixf ( orientation . toMatrix4 ( ) . ptr ( ) ) ;
glTranslatef ( - position . x , - position . y , - position . z ) ;
}
2011-08-30 20:28:30 +02:00
static Vec2i _unprojectMap ( const Vec2i & pt , const GLdouble * model , const GLdouble * projection , const GLint * viewport , const char * label = NULL ) {
Vec3d a , b ;
2011-11-23 09:00:09 +01:00
/* note viewport[3] is height of window in pixels */
GLint realy = viewport [ 3 ] - ( GLint ) pt . y ;
gluUnProject ( pt . x , realy , 0 , model , projection , viewport , & a . x , & a . y , & a . z ) ;
gluUnProject ( pt . x , realy , 1 , model , projection , viewport , & b . x , & b . y , & b . z ) ;
2011-07-24 01:22:30 +02:00
// junk values if you were looking parallel to the XZ plane; this shouldn't happen as the camera can't do this?
2011-08-30 20:28:30 +02:00
const Vec3f
start ( a . x , a . y , a . z ) ,
stop ( b . x , b . y , b . z ) ,
plane ( 0 , 0 , 0 ) ,
norm ( 0 , 1 , 0 ) ,
u = stop - start ,
w = start - plane ;
const float d = norm . x * u . x + norm . y * u . y + norm . z * u . z ;
2013-06-12 03:07:53 +02:00
if ( std : : fabs ( d ) < 0.00001 )
2012-10-06 09:06:40 +02:00
throw pti_D_IS_ZERO ;
2011-08-30 20:28:30 +02:00
const float nd = - ( norm . x * w . x + norm . y * w . y + norm . z * w . z ) / d ;
if ( nd < 0.0 | | nd > = 1.0 )
2012-10-06 09:06:40 +02:00
throw pti_N_OVER_D_IS_OUTSIDE ;
2011-08-30 20:28:30 +02:00
const Vec3f i = start + u * nd ;
//const Vec2i pos(i.x,i.z);
Vec2i pos ;
if ( strcmp ( label , " tl " ) = = 0 ) {
2013-06-12 03:07:53 +02:00
pos = Vec2i ( std : : floor ( i . x ) , std : : floor ( i . z ) ) ;
2011-08-30 20:28:30 +02:00
}
else if ( strcmp ( label , " tr " ) = = 0 ) {
2013-06-12 03:07:53 +02:00
pos = Vec2i ( std : : ceil ( i . x ) , std : : floor ( i . z ) ) ;
2011-08-30 20:28:30 +02:00
}
else if ( strcmp ( label , " bl " ) = = 0 ) {
2013-06-12 03:07:53 +02:00
pos = Vec2i ( std : : floor ( i . x ) , std : : ceil ( i . z ) ) ;
2011-08-30 20:28:30 +02:00
}
else if ( strcmp ( label , " br " ) = = 0 ) {
2013-06-12 03:07:53 +02:00
pos = Vec2i ( std : : ceil ( i . x ) , std : : ceil ( i . z ) ) ;
2011-08-30 20:28:30 +02:00
}
2011-07-24 01:22:30 +02:00
if ( false ) { // print debug info
if ( label ) printf ( " %s " , label ) ;
printf ( " %d,%d -> %f,%f,%f -> %f,%f,%f -> %f,%f,%f -> %d,%d \n " ,
2011-08-30 20:28:30 +02:00
pt . x , pt . y ,
start . x , start . y , start . z ,
stop . x , stop . y , stop . z ,
i . x , i . y , i . z ,
pos . x , pos . y ) ;
2011-07-24 01:22:30 +02:00
}
return pos ;
2011-11-23 09:00:09 +01:00
2011-07-24 01:22:30 +02:00
}
2011-11-30 17:51:51 +01:00
bool Renderer : : ExtractFrustum ( VisibleQuadContainerCache & quadCacheItem ) {
2013-02-11 23:51:36 +01:00
bool frustumChanged = false ;
2011-11-30 17:51:51 +01:00
vector < float > proj ( 16 , 0 ) ;
vector < float > modl ( 16 , 0 ) ;
2011-11-30 06:57:14 +01:00
/* Get the current PROJECTION matrix from OpenGL */
glGetFloatv ( GL_PROJECTION_MATRIX , & proj [ 0 ] ) ;
/* Get the current MODELVIEW matrix from OpenGL */
glGetFloatv ( GL_MODELVIEW_MATRIX , & modl [ 0 ] ) ;
2011-11-30 18:47:07 +01:00
// for(unsigned int i = 0; i < proj.size(); ++i) {
// //printf("\ni = %d proj [%f][%f] modl [%f][%f]\n",i,proj[i],quadCacheItem.proj[i],modl[i],quadCacheItem.modl[i]);
// if(proj[i] != quadCacheItem.proj[i]) {
2013-02-11 23:51:36 +01:00
// frustumChanged = true;
2011-11-30 18:47:07 +01:00
// break;
// }
// if(modl[i] != quadCacheItem.modl[i]) {
2013-02-11 23:51:36 +01:00
// frustumChanged = true;
2011-11-30 18:47:07 +01:00
// break;
// }
// }
2011-11-30 22:27:03 +01:00
// Check the frustum cache
const bool useFrustumCache = Config : : getInstance ( ) . getBool ( " EnableFrustrumCache " , " false " ) ;
pair < vector < float > , vector < float > > lookupKey ;
if ( useFrustumCache = = true ) {
lookupKey = make_pair ( proj , modl ) ;
map < pair < vector < float > , vector < float > > , vector < vector < float > > > : : iterator iterFind = quadCacheItem . frustumDataCache . find ( lookupKey ) ;
if ( iterFind ! = quadCacheItem . frustumDataCache . end ( ) ) {
2013-02-11 23:51:36 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " \n Calc Frustum found in cache \n " ) ;
2011-11-30 22:27:03 +01:00
quadCacheItem . frustumData = iterFind - > second ;
2013-02-11 23:51:36 +01:00
frustumChanged = ( quadCacheItem . proj ! = proj | | quadCacheItem . modl ! = modl ) ;
if ( frustumChanged = = true ) {
2011-11-30 22:27:03 +01:00
quadCacheItem . proj = proj ;
quadCacheItem . modl = modl ;
}
2013-02-11 23:51:36 +01:00
return frustumChanged ;
2011-11-30 22:27:03 +01:00
}
}
2011-11-30 18:47:07 +01:00
if ( quadCacheItem . proj ! = proj | | quadCacheItem . modl ! = modl ) {
2013-02-11 23:51:36 +01:00
//if(frustumChanged == true) {
frustumChanged = true ;
2011-11-30 18:47:07 +01:00
vector < vector < float > > & frustum = quadCacheItem . frustumData ;
2011-11-30 22:27:03 +01:00
//assert(frustum.size() == 6);
//assert(frustum[0].size() == 4);
2011-11-30 17:51:51 +01:00
quadCacheItem . proj = proj ;
quadCacheItem . modl = modl ;
float clip [ 16 ] ;
float t = 0 ;
/* Combine the two matrices (multiply projection by modelview) */
clip [ 0 ] = modl [ 0 ] * proj [ 0 ] + modl [ 1 ] * proj [ 4 ] + modl [ 2 ] * proj [ 8 ] + modl [ 3 ] * proj [ 12 ] ;
clip [ 1 ] = modl [ 0 ] * proj [ 1 ] + modl [ 1 ] * proj [ 5 ] + modl [ 2 ] * proj [ 9 ] + modl [ 3 ] * proj [ 13 ] ;
clip [ 2 ] = modl [ 0 ] * proj [ 2 ] + modl [ 1 ] * proj [ 6 ] + modl [ 2 ] * proj [ 10 ] + modl [ 3 ] * proj [ 14 ] ;
clip [ 3 ] = modl [ 0 ] * proj [ 3 ] + modl [ 1 ] * proj [ 7 ] + modl [ 2 ] * proj [ 11 ] + modl [ 3 ] * proj [ 15 ] ;
clip [ 4 ] = modl [ 4 ] * proj [ 0 ] + modl [ 5 ] * proj [ 4 ] + modl [ 6 ] * proj [ 8 ] + modl [ 7 ] * proj [ 12 ] ;
clip [ 5 ] = modl [ 4 ] * proj [ 1 ] + modl [ 5 ] * proj [ 5 ] + modl [ 6 ] * proj [ 9 ] + modl [ 7 ] * proj [ 13 ] ;
clip [ 6 ] = modl [ 4 ] * proj [ 2 ] + modl [ 5 ] * proj [ 6 ] + modl [ 6 ] * proj [ 10 ] + modl [ 7 ] * proj [ 14 ] ;
clip [ 7 ] = modl [ 4 ] * proj [ 3 ] + modl [ 5 ] * proj [ 7 ] + modl [ 6 ] * proj [ 11 ] + modl [ 7 ] * proj [ 15 ] ;
clip [ 8 ] = modl [ 8 ] * proj [ 0 ] + modl [ 9 ] * proj [ 4 ] + modl [ 10 ] * proj [ 8 ] + modl [ 11 ] * proj [ 12 ] ;
clip [ 9 ] = modl [ 8 ] * proj [ 1 ] + modl [ 9 ] * proj [ 5 ] + modl [ 10 ] * proj [ 9 ] + modl [ 11 ] * proj [ 13 ] ;
clip [ 10 ] = modl [ 8 ] * proj [ 2 ] + modl [ 9 ] * proj [ 6 ] + modl [ 10 ] * proj [ 10 ] + modl [ 11 ] * proj [ 14 ] ;
clip [ 11 ] = modl [ 8 ] * proj [ 3 ] + modl [ 9 ] * proj [ 7 ] + modl [ 10 ] * proj [ 11 ] + modl [ 11 ] * proj [ 15 ] ;
clip [ 12 ] = modl [ 12 ] * proj [ 0 ] + modl [ 13 ] * proj [ 4 ] + modl [ 14 ] * proj [ 8 ] + modl [ 15 ] * proj [ 12 ] ;
clip [ 13 ] = modl [ 12 ] * proj [ 1 ] + modl [ 13 ] * proj [ 5 ] + modl [ 14 ] * proj [ 9 ] + modl [ 15 ] * proj [ 13 ] ;
clip [ 14 ] = modl [ 12 ] * proj [ 2 ] + modl [ 13 ] * proj [ 6 ] + modl [ 14 ] * proj [ 10 ] + modl [ 15 ] * proj [ 14 ] ;
clip [ 15 ] = modl [ 12 ] * proj [ 3 ] + modl [ 13 ] * proj [ 7 ] + modl [ 14 ] * proj [ 11 ] + modl [ 15 ] * proj [ 15 ] ;
/* Extract the numbers for the RIGHT plane */
frustum [ 0 ] [ 0 ] = clip [ 3 ] - clip [ 0 ] ;
frustum [ 0 ] [ 1 ] = clip [ 7 ] - clip [ 4 ] ;
frustum [ 0 ] [ 2 ] = clip [ 11 ] - clip [ 8 ] ;
frustum [ 0 ] [ 3 ] = clip [ 15 ] - clip [ 12 ] ;
2013-02-11 23:51:36 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " \n Calc Frustum #%da: [%f][%f][%f][%f] \n " , 0 , frustum [ 0 ] [ 0 ] , frustum [ 0 ] [ 1 ] , frustum [ 0 ] [ 2 ] , frustum [ 0 ] [ 3 ] ) ;
2011-11-30 18:47:07 +01:00
2011-11-30 17:51:51 +01:00
/* Normalize the result */
2013-06-11 08:44:26 +02:00
t = std : : sqrt ( frustum [ 0 ] [ 0 ] * frustum [ 0 ] [ 0 ] + frustum [ 0 ] [ 1 ] * frustum [ 0 ] [ 1 ] + frustum [ 0 ] [ 2 ] * frustum [ 0 ] [ 2 ] ) ;
2011-11-30 18:56:58 +01:00
if ( t ! = 0.0 ) {
frustum [ 0 ] [ 0 ] / = t ;
frustum [ 0 ] [ 1 ] / = t ;
frustum [ 0 ] [ 2 ] / = t ;
frustum [ 0 ] [ 3 ] / = t ;
2011-11-30 17:51:51 +01:00
2013-02-11 23:51:36 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " \n Calc Frustum #%db: [%f][%f][%f][%f] t = %f \n " , 0 , frustum [ 0 ] [ 0 ] , frustum [ 0 ] [ 1 ] , frustum [ 0 ] [ 2 ] , frustum [ 0 ] [ 3 ] , t ) ;
2011-11-30 18:56:58 +01:00
}
2011-11-30 18:47:07 +01:00
2011-11-30 17:51:51 +01:00
/* Extract the numbers for the LEFT plane */
frustum [ 1 ] [ 0 ] = clip [ 3 ] + clip [ 0 ] ;
frustum [ 1 ] [ 1 ] = clip [ 7 ] + clip [ 4 ] ;
frustum [ 1 ] [ 2 ] = clip [ 11 ] + clip [ 8 ] ;
frustum [ 1 ] [ 3 ] = clip [ 15 ] + clip [ 12 ] ;
2013-02-11 23:51:36 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " \n Calc Frustum #%da: [%f][%f][%f][%f] \n " , 1 , frustum [ 1 ] [ 0 ] , frustum [ 1 ] [ 1 ] , frustum [ 1 ] [ 2 ] , frustum [ 1 ] [ 3 ] ) ;
2011-11-30 18:47:07 +01:00
2011-11-30 17:51:51 +01:00
/* Normalize the result */
2013-06-11 08:44:26 +02:00
t = std : : sqrt ( frustum [ 1 ] [ 0 ] * frustum [ 1 ] [ 0 ] + frustum [ 1 ] [ 1 ] * frustum [ 1 ] [ 1 ] + frustum [ 1 ] [ 2 ] * frustum [ 1 ] [ 2 ] ) ;
2011-11-30 18:56:58 +01:00
if ( t ! = 0.0 ) {
frustum [ 1 ] [ 0 ] / = t ;
frustum [ 1 ] [ 1 ] / = t ;
frustum [ 1 ] [ 2 ] / = t ;
frustum [ 1 ] [ 3 ] / = t ;
2011-11-30 17:51:51 +01:00
2013-02-11 23:51:36 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " \n Calc Frustum #%db: [%f][%f][%f][%f] t = %f \n " , 1 , frustum [ 1 ] [ 0 ] , frustum [ 1 ] [ 1 ] , frustum [ 1 ] [ 2 ] , frustum [ 1 ] [ 3 ] , t ) ;
2011-11-30 18:56:58 +01:00
}
2011-11-30 18:47:07 +01:00
2011-11-30 17:51:51 +01:00
/* Extract the BOTTOM plane */
frustum [ 2 ] [ 0 ] = clip [ 3 ] + clip [ 1 ] ;
frustum [ 2 ] [ 1 ] = clip [ 7 ] + clip [ 5 ] ;
frustum [ 2 ] [ 2 ] = clip [ 11 ] + clip [ 9 ] ;
frustum [ 2 ] [ 3 ] = clip [ 15 ] + clip [ 13 ] ;
2013-02-11 23:51:36 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " \n Calc Frustum #%da: [%f][%f][%f][%f] \n " , 2 , frustum [ 2 ] [ 0 ] , frustum [ 2 ] [ 1 ] , frustum [ 2 ] [ 2 ] , frustum [ 2 ] [ 3 ] ) ;
2011-11-30 18:47:07 +01:00
2011-11-30 17:51:51 +01:00
/* Normalize the result */
2013-06-11 08:44:26 +02:00
t = std : : sqrt ( frustum [ 2 ] [ 0 ] * frustum [ 2 ] [ 0 ] + frustum [ 2 ] [ 1 ] * frustum [ 2 ] [ 1 ] + frustum [ 2 ] [ 2 ] * frustum [ 2 ] [ 2 ] ) ;
2011-11-30 18:56:58 +01:00
if ( t ! = 0.0 ) {
frustum [ 2 ] [ 0 ] / = t ;
frustum [ 2 ] [ 1 ] / = t ;
frustum [ 2 ] [ 2 ] / = t ;
frustum [ 2 ] [ 3 ] / = t ;
2011-11-30 17:51:51 +01:00
2013-02-11 23:51:36 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " \n Calc Frustum #%db: [%f][%f][%f][%f] t = %f \n " , 2 , frustum [ 2 ] [ 0 ] , frustum [ 2 ] [ 1 ] , frustum [ 2 ] [ 2 ] , frustum [ 2 ] [ 3 ] , t ) ;
2011-11-30 18:56:58 +01:00
}
2011-11-30 18:47:07 +01:00
2011-11-30 17:51:51 +01:00
/* Extract the TOP plane */
frustum [ 3 ] [ 0 ] = clip [ 3 ] - clip [ 1 ] ;
frustum [ 3 ] [ 1 ] = clip [ 7 ] - clip [ 5 ] ;
frustum [ 3 ] [ 2 ] = clip [ 11 ] - clip [ 9 ] ;
frustum [ 3 ] [ 3 ] = clip [ 15 ] - clip [ 13 ] ;
2013-02-11 23:51:36 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " \n Calc Frustum #%da: [%f][%f][%f][%f] \n " , 3 , frustum [ 3 ] [ 0 ] , frustum [ 3 ] [ 1 ] , frustum [ 3 ] [ 2 ] , frustum [ 3 ] [ 3 ] ) ;
2011-11-30 18:47:07 +01:00
2011-11-30 17:51:51 +01:00
/* Normalize the result */
2013-06-11 08:44:26 +02:00
t = std : : sqrt ( frustum [ 3 ] [ 0 ] * frustum [ 3 ] [ 0 ] + frustum [ 3 ] [ 1 ] * frustum [ 3 ] [ 1 ] + frustum [ 3 ] [ 2 ] * frustum [ 3 ] [ 2 ] ) ;
2011-11-30 18:56:58 +01:00
if ( t ! = 0.0 ) {
frustum [ 3 ] [ 0 ] / = t ;
frustum [ 3 ] [ 1 ] / = t ;
frustum [ 3 ] [ 2 ] / = t ;
frustum [ 3 ] [ 3 ] / = t ;
2013-02-11 23:51:36 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " \n Calc Frustum #%db: [%f][%f][%f][%f] t = %f \n " , 3 , frustum [ 3 ] [ 0 ] , frustum [ 3 ] [ 1 ] , frustum [ 3 ] [ 2 ] , frustum [ 3 ] [ 3 ] , t ) ;
2011-11-30 18:56:58 +01:00
}
2011-11-30 18:47:07 +01:00
2011-11-30 17:51:51 +01:00
/* Extract the FAR plane */
frustum [ 4 ] [ 0 ] = clip [ 3 ] - clip [ 2 ] ;
frustum [ 4 ] [ 1 ] = clip [ 7 ] - clip [ 6 ] ;
frustum [ 4 ] [ 2 ] = clip [ 11 ] - clip [ 10 ] ;
frustum [ 4 ] [ 3 ] = clip [ 15 ] - clip [ 14 ] ;
2013-02-11 23:51:36 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " \n Calc Frustum #%da: [%f][%f][%f][%f] \n " , 4 , frustum [ 4 ] [ 0 ] , frustum [ 4 ] [ 1 ] , frustum [ 4 ] [ 2 ] , frustum [ 4 ] [ 3 ] ) ;
2011-11-30 18:47:07 +01:00
2011-11-30 17:51:51 +01:00
/* Normalize the result */
2013-06-11 08:44:26 +02:00
t = std : : sqrt ( frustum [ 4 ] [ 0 ] * frustum [ 4 ] [ 0 ] + frustum [ 4 ] [ 1 ] * frustum [ 4 ] [ 1 ] + frustum [ 4 ] [ 2 ] * frustum [ 4 ] [ 2 ] ) ;
2011-11-30 17:51:51 +01:00
2011-11-30 18:56:58 +01:00
if ( t ! = 0.0 ) {
frustum [ 4 ] [ 0 ] / = t ;
frustum [ 4 ] [ 1 ] / = t ;
frustum [ 4 ] [ 2 ] / = t ;
frustum [ 4 ] [ 3 ] / = t ;
2013-02-11 23:51:36 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " \n Calc Frustum #%db: [%f][%f][%f][%f] t = %f \n " , 4 , frustum [ 4 ] [ 0 ] , frustum [ 4 ] [ 1 ] , frustum [ 4 ] [ 2 ] , frustum [ 4 ] [ 3 ] , t ) ;
2011-11-30 18:56:58 +01:00
}
2011-11-30 18:47:07 +01:00
2011-11-30 17:51:51 +01:00
/* Extract the NEAR plane */
frustum [ 5 ] [ 0 ] = clip [ 3 ] + clip [ 2 ] ;
frustum [ 5 ] [ 1 ] = clip [ 7 ] + clip [ 6 ] ;
frustum [ 5 ] [ 2 ] = clip [ 11 ] + clip [ 10 ] ;
frustum [ 5 ] [ 3 ] = clip [ 15 ] + clip [ 14 ] ;
2013-02-11 23:51:36 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " \n Calc Frustum #%da: [%f][%f][%f][%f] \n " , 5 , frustum [ 5 ] [ 0 ] , frustum [ 5 ] [ 1 ] , frustum [ 5 ] [ 2 ] , frustum [ 5 ] [ 3 ] ) ;
2011-11-30 18:47:07 +01:00
2011-11-30 17:51:51 +01:00
/* Normalize the result */
2013-06-11 08:44:26 +02:00
t = std : : sqrt ( frustum [ 5 ] [ 0 ] * frustum [ 5 ] [ 0 ] + frustum [ 5 ] [ 1 ] * frustum [ 5 ] [ 1 ] + frustum [ 5 ] [ 2 ] * frustum [ 5 ] [ 2 ] ) ;
2011-11-30 18:47:07 +01:00
2011-11-30 18:56:58 +01:00
if ( t ! = 0.0 ) {
frustum [ 5 ] [ 0 ] / = t ;
frustum [ 5 ] [ 1 ] / = t ;
frustum [ 5 ] [ 2 ] / = t ;
frustum [ 5 ] [ 3 ] / = t ;
2011-11-30 18:47:07 +01:00
2013-02-11 23:51:36 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " \n Calc Frustum #%db: [%f][%f][%f][%f] t = %f \n " , 5 , frustum [ 5 ] [ 0 ] , frustum [ 5 ] [ 1 ] , frustum [ 5 ] [ 2 ] , frustum [ 5 ] [ 3 ] , t ) ;
2011-11-30 18:56:58 +01:00
}
2011-11-30 22:27:03 +01:00
if ( useFrustumCache = = true ) {
quadCacheItem . frustumDataCache [ lookupKey ] = frustum ;
}
2011-11-30 17:51:51 +01:00
}
2013-02-11 23:51:36 +01:00
return frustumChanged ;
2011-11-30 06:57:14 +01:00
}
2017-10-10 05:21:14 +02:00
//bool Renderer::PointInFrustum(vector<vector<float> > &frustum, float x, float y, float z ) {
// unsigned int p=0;
//
// for( p = 0; p < frustum.size(); p++ ) {
// if( frustum[p][0] * x + frustum[p][1] * y + frustum[p][2] * z + frustum[p][3] <= 0 ) {
// return false;
// }
// }
// return true;
//}
//
//bool Renderer::SphereInFrustum(vector<vector<float> > &frustum, float x, float y, float z, float radius) {
// // Go through all the sides of the frustum
// for(int i = 0; i < (int)frustum.size(); i++ ) {
// // If the center of the sphere is farther away from the plane than the radius
// if(frustum[i][0] * x + frustum[i][1] * y + frustum[i][2] * z + frustum[i][3] <= -radius ) {
// // The distance was greater than the radius so the sphere is outside of the frustum
// return false;
// }
// }
//
// // The sphere was inside of the frustum!
// return true;
//}
2011-12-13 02:30:52 +01:00
2011-11-30 06:57:14 +01:00
bool Renderer : : CubeInFrustum ( vector < vector < float > > & frustum , float x , float y , float z , float size ) {
2011-11-30 08:39:24 +01:00
unsigned int p = 0 ;
2011-11-30 06:57:14 +01:00
2011-11-30 08:39:24 +01:00
for ( p = 0 ; p < frustum . size ( ) ; p + + ) {
2011-11-30 06:57:14 +01:00
if ( frustum [ p ] [ 0 ] * ( x - size ) + frustum [ p ] [ 1 ] * ( y - size ) + frustum [ p ] [ 2 ] * ( z - size ) + frustum [ p ] [ 3 ] > 0 )
continue ;
if ( frustum [ p ] [ 0 ] * ( x + size ) + frustum [ p ] [ 1 ] * ( y - size ) + frustum [ p ] [ 2 ] * ( z - size ) + frustum [ p ] [ 3 ] > 0 )
continue ;
if ( frustum [ p ] [ 0 ] * ( x - size ) + frustum [ p ] [ 1 ] * ( y + size ) + frustum [ p ] [ 2 ] * ( z - size ) + frustum [ p ] [ 3 ] > 0 )
continue ;
if ( frustum [ p ] [ 0 ] * ( x + size ) + frustum [ p ] [ 1 ] * ( y + size ) + frustum [ p ] [ 2 ] * ( z - size ) + frustum [ p ] [ 3 ] > 0 )
continue ;
if ( frustum [ p ] [ 0 ] * ( x - size ) + frustum [ p ] [ 1 ] * ( y - size ) + frustum [ p ] [ 2 ] * ( z + size ) + frustum [ p ] [ 3 ] > 0 )
continue ;
if ( frustum [ p ] [ 0 ] * ( x + size ) + frustum [ p ] [ 1 ] * ( y - size ) + frustum [ p ] [ 2 ] * ( z + size ) + frustum [ p ] [ 3 ] > 0 )
continue ;
if ( frustum [ p ] [ 0 ] * ( x - size ) + frustum [ p ] [ 1 ] * ( y + size ) + frustum [ p ] [ 2 ] * ( z + size ) + frustum [ p ] [ 3 ] > 0 )
continue ;
if ( frustum [ p ] [ 0 ] * ( x + size ) + frustum [ p ] [ 1 ] * ( y + size ) + frustum [ p ] [ 2 ] * ( z + size ) + frustum [ p ] [ 3 ] > 0 )
continue ;
return false ;
}
return true ;
}
2011-01-15 09:45:17 +01:00
void Renderer : : computeVisibleQuad ( ) {
2011-12-02 17:07:59 +01:00
visibleQuad = this - > gameCamera - > computeVisibleQuad ( ) ;
2011-07-24 01:22:30 +02:00
2013-02-11 23:51:36 +01:00
bool frustumChanged = false ;
2011-11-30 07:58:26 +01:00
if ( VisibleQuadContainerCache : : enableFrustumCalcs = = true ) {
2013-02-11 23:51:36 +01:00
frustumChanged = ExtractFrustum ( quadCache ) ;
2011-11-30 06:57:14 +01:00
}
2013-02-11 23:51:36 +01:00
if ( frustumChanged & & SystemFlags : : VERBOSE_MODE_ENABLED ) {
2011-11-30 17:51:51 +01:00
printf ( " \n Camera: %d,%d %d,%d %d,%d %d,%d \n " ,
visibleQuad . p [ 0 ] . x , visibleQuad . p [ 0 ] . y ,
visibleQuad . p [ 1 ] . x , visibleQuad . p [ 1 ] . y ,
visibleQuad . p [ 2 ] . x , visibleQuad . p [ 2 ] . y ,
visibleQuad . p [ 3 ] . x , visibleQuad . p [ 3 ] . y ) ;
2011-11-30 18:47:07 +01:00
for ( unsigned int i = 0 ; i < quadCache . frustumData . size ( ) ; + + i ) {
2013-02-11 23:51:36 +01:00
printf ( " \n Frustum #%u [ " MG_SIZE_T_SPECIFIER " ]: " , i , quadCache . frustumData . size ( ) ) ;
2011-11-30 18:47:07 +01:00
vector < float > & frustumDataInner = quadCache . frustumData [ i ] ;
for ( unsigned int j = 0 ; j < frustumDataInner . size ( ) ; + + j ) {
2011-11-30 17:51:51 +01:00
printf ( " [%f] " , quadCache . frustumData [ i ] [ j ] ) ;
}
}
2011-11-30 18:47:07 +01:00
printf ( " \n END \n " ) ;
2011-11-30 17:51:51 +01:00
}
2011-11-30 06:57:14 +01:00
2011-08-30 20:28:30 +02:00
const bool newVisibleQuadCalc = false ;
if ( newVisibleQuadCalc ) {
const bool debug = false ;
try {
if ( debug ) {
visibleQuad = gameCamera - > computeVisibleQuad ( ) ;
printf ( " Camera: %d,%d %d,%d %d,%d %d,%d \n " ,
visibleQuad . p [ 0 ] . x , visibleQuad . p [ 0 ] . y ,
visibleQuad . p [ 1 ] . x , visibleQuad . p [ 1 ] . y ,
visibleQuad . p [ 2 ] . x , visibleQuad . p [ 2 ] . y ,
visibleQuad . p [ 3 ] . x , visibleQuad . p [ 3 ] . y ) ;
}
2011-11-23 09:00:09 +01:00
2011-08-30 20:28:30 +02:00
// compute the four corners using OpenGL
GLdouble model [ 16 ] , projection [ 16 ] ;
GLint viewport [ 4 ] ;
glGetDoublev ( GL_MODELVIEW_MATRIX , model ) ;
glGetDoublev ( GL_PROJECTION_MATRIX , projection ) ;
glGetIntegerv ( GL_VIEWPORT , viewport ) ;
Vec2i
tl = _unprojectMap ( Vec2i ( 0 , 0 ) , model , projection , viewport , " tl " ) ,
tr = _unprojectMap ( Vec2i ( viewport [ 2 ] , 0 ) , model , projection , viewport , " tr " ) ,
br = _unprojectMap ( Vec2i ( viewport [ 2 ] , viewport [ 3 ] ) , model , projection , viewport , " br " ) ,
bl = _unprojectMap ( Vec2i ( 0 , viewport [ 3 ] ) , model , projection , viewport , " bl " ) ;
2011-11-23 09:00:09 +01:00
2011-08-30 20:28:30 +02:00
// orientate it for map iterator
2011-09-01 01:10:43 +02:00
//bool swapRequiredX = false;
2011-08-30 20:28:30 +02:00
bool swapRequiredY = false ;
int const cellBuffer = 4 ;
if ( ( tl . x > tr . x ) | | ( bl . x > br . x ) ) {
if ( debug ) printf ( " Swap X??? \n " ) ;
//std::swap(tl,bl);
//std::swap(tr,br);
if ( tl . x > tr . x ) {
if ( debug ) printf ( " Swap X1??? \n " ) ;
tr . x + = cellBuffer ;
tl . x - = cellBuffer ;
std : : swap ( tl . x , tr . x ) ;
2011-09-01 01:10:43 +02:00
//swapRequiredX = true;
2011-08-30 20:28:30 +02:00
}
else {
tl . x + = cellBuffer ;
tr . x - = cellBuffer ;
}
if ( bl . x > br . x ) {
if ( debug ) printf ( " Swap X2??? \n " ) ;
bl . x + = cellBuffer ;
br . x - = cellBuffer ;
std : : swap ( bl . x , br . x ) ;
2011-09-01 01:10:43 +02:00
//swapRequiredX = true;
2011-08-30 20:28:30 +02:00
}
else {
br . x + = cellBuffer ;
bl . x - = cellBuffer ;
}
}
if ( ( tl . y > bl . y ) | | ( tr . y > br . y ) ) {
2011-12-02 17:07:59 +01:00
visibleQuad = this - > gameCamera - > computeVisibleQuad ( ) ;
2011-08-30 20:28:30 +02:00
if ( debug ) printf ( " Swap Y??? \n " ) ;
if ( tl . y > bl . y ) {
if ( debug ) printf ( " Swap Y1??? \n " ) ;
tl . y + = cellBuffer ;
bl . y - = cellBuffer ;
std : : swap ( tl . y , bl . y ) ;
swapRequiredY = true ;
}
else {
bl . y + = cellBuffer ;
tl . y - = cellBuffer ;
}
if ( tr . y > br . y ) {
if ( debug ) printf ( " Swap Y2??? \n " ) ;
tr . y + = cellBuffer ;
br . y - = cellBuffer ;
std : : swap ( tr . y , br . y ) ;
swapRequiredY = true ;
}
else {
br . y + = cellBuffer ;
tr . y - = cellBuffer ;
}
//std::swap(tl,tr);
//std::swap(bl,br);
}
if ( swapRequiredY = = false ) {
tl . y - = cellBuffer ;
tr . y - = cellBuffer ;
bl . y + = cellBuffer ;
br . y + = cellBuffer ;
}
// set it as the frustum
visibleQuad = Quad2i ( tl , bl , tr , br ) ; // strange order
if ( debug ) {
printf ( " Will: %d,%d %d,%d %d,%d %d,%d \n " ,
visibleQuad . p [ 0 ] . x , visibleQuad . p [ 0 ] . y ,
visibleQuad . p [ 1 ] . x , visibleQuad . p [ 1 ] . y ,
visibleQuad . p [ 2 ] . x , visibleQuad . p [ 2 ] . y ,
visibleQuad . p [ 3 ] . x , visibleQuad . p [ 3 ] . y ) ;
}
}
2012-09-22 22:13:57 +02:00
catch ( PROJECTION_TO_INFINITY & e ) {
2011-08-30 20:28:30 +02:00
if ( debug ) printf ( " hmm staring at the horizon %d \n " , ( int ) e ) ;
// use historic code solution
2011-12-02 17:07:59 +01:00
visibleQuad = this - > gameCamera - > computeVisibleQuad ( ) ;
2011-08-30 20:28:30 +02:00
}
}
2010-03-13 22:10:45 +01:00
}
// =======================================
// basic rendering
// =======================================
2011-01-15 09:45:17 +01:00
void Renderer : : renderMouse2d ( int x , int y , int anim , float fade ) {
2011-04-28 01:37:57 +02:00
if ( no2DMouseRendering = = true ) {
return ;
2011-12-03 01:39:03 +01:00
}
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2012-04-03 01:37:03 +02:00
// float blue=0.0f;
// float green=0.4f;
2012-06-12 22:37:00 +02:00
if ( game ! = NULL & & game - > getGui ( ) ! = NULL ) {
2012-04-03 00:17:10 +02:00
const Gui * gui = game - > getGui ( ) ;
const Display * display = gui - > getDisplay ( ) ;
int downPos = display - > getDownSelectedPos ( ) ;
2012-06-12 22:37:00 +02:00
if ( downPos ! = Display : : invalidPos ) {
2012-04-03 00:17:10 +02:00
// in state of doing something
const Texture2D * texture = display - > getDownImage ( downPos ) ;
renderTextureQuad ( x + 18 , y - 50 , 32 , 32 , texture , 0.8f ) ;
}
2012-04-03 01:37:03 +02:00
// else {
// // Display current commandtype
// const Unit *unit=NULL;
// if(gui->getSelection()->isEmpty()){
// blue=0.0f;
// green=0.1f;
// }
// else{
// unit=gui->getSelection()->getFrontUnit();
// if(unit->getCurrCommand()!=NULL && unit->getCurrCommand()->getCommandType()->getImage()!=NULL){
// const Texture2D *texture = unit->getCurrCommand()->getCommandType()->getImage();
// renderTextureQuad(x+18,y-50,32,32,texture,0.2f);
// }
// }
// }
2012-06-12 22:37:00 +02:00
if ( game - > isMarkCellMode ( ) = = true ) {
const Texture2D * texture = game - > getMarkCellTexture ( ) ;
2015-01-04 14:38:32 +01:00
renderTextureQuad ( x , y , texture - > getTextureWidth ( ) , texture - > getTextureHeight ( ) , texture , 0.8f ) ;
2012-06-12 22:37:00 +02:00
}
2012-06-13 18:19:44 +02:00
if ( game - > isUnMarkCellMode ( ) = = true ) {
const Texture2D * texture = game - > getUnMarkCellTexture ( ) ;
2015-01-04 14:38:32 +01:00
renderTextureQuad ( x , y , texture - > getTextureWidth ( ) , texture - > getTextureHeight ( ) , texture , 0.8f ) ;
2012-06-13 18:19:44 +02:00
}
2012-04-03 00:17:10 +02:00
}
2011-12-03 01:39:03 +01:00
2011-04-28 01:37:57 +02:00
float fadeFactor = fade + 1.f ;
anim = anim * 2 - maxMouse2dAnim ;
2012-10-06 09:06:40 +02:00
float color2 = ( abs ( anim * ( int ) fadeFactor ) / static_cast < float > ( maxMouse2dAnim ) ) / 2.f + 0.4f ;
float color1 = ( abs ( anim * ( int ) fadeFactor ) / static_cast < float > ( maxMouse2dAnim ) ) / 2.f + 0.8f ;
2011-04-28 01:37:57 +02:00
glPushAttrib ( GL_CURRENT_BIT | GL_COLOR_BUFFER_BIT | GL_LINE_BIT ) ;
glEnable ( GL_BLEND ) ;
//inside
glColor4f ( 0.4f * fadeFactor , 0.2f * fadeFactor , 0.2f * fadeFactor , 0.5f * fadeFactor ) ;
glBegin ( GL_TRIANGLES ) ;
glVertex2i ( x , y ) ;
glVertex2i ( x + 20 , y - 10 ) ;
glVertex2i ( x + 10 , y - 20 ) ;
glEnd ( ) ;
//border
glLineWidth ( 2 ) ;
glBegin ( GL_LINE_LOOP ) ;
2012-04-03 01:37:03 +02:00
glColor4f ( 1.f , 0.2f , 0 , color1 ) ;
2011-04-28 01:37:57 +02:00
glVertex2i ( x , y ) ;
2012-04-03 01:37:03 +02:00
glColor4f ( 1.f , 0.4f , 0 , color2 ) ;
2011-04-28 01:37:57 +02:00
glVertex2i ( x + 20 , y - 10 ) ;
2012-04-03 01:37:03 +02:00
glColor4f ( 1.f , 0.4f , 0 , color2 ) ;
2011-04-28 01:37:57 +02:00
glVertex2i ( x + 10 , y - 20 ) ;
glEnd ( ) ;
glPopAttrib ( ) ;
2012-04-03 00:17:10 +02:00
2011-04-28 01:37:57 +02:00
/*
2010-06-24 03:23:18 +02:00
if ( no2DMouseRendering = = true ) {
return ;
}
2011-01-15 09:45:17 +01:00
float color1 = 0.0 , color2 = 0.0 ;
2010-03-13 22:10:45 +01:00
2011-01-15 09:45:17 +01:00
float fadeFactor = fade + 1.f ;
2010-03-13 22:10:45 +01:00
2011-01-15 09:45:17 +01:00
anim = anim * 2 - maxMouse2dAnim ;
2010-03-13 22:10:45 +01:00
2010-05-28 07:31:17 +02:00
color2 = ( abs ( anim * ( int ) fadeFactor ) / static_cast < float > ( maxMouse2dAnim ) ) / 2.f + 0.4f ;
color1 = ( abs ( anim * ( int ) fadeFactor ) / static_cast < float > ( maxMouse2dAnim ) ) / 2.f + 0.8f ;
2010-03-13 22:10:45 +01:00
glPushAttrib ( GL_CURRENT_BIT | GL_COLOR_BUFFER_BIT | GL_LINE_BIT ) ;
2011-02-09 02:27:41 +01:00
glEnable ( GL_BLEND ) ;
2010-03-13 22:10:45 +01:00
2011-02-09 09:04:21 +01:00
//inside
Vec2i vertices [ 3 ] ;
vertices [ 0 ] = Vec2i ( x , y ) ;
vertices [ 1 ] = Vec2i ( x + 20 , y - 10 ) ;
vertices [ 2 ] = Vec2i ( x + 10 , y - 20 ) ;
glColor4f ( 0.4f * fadeFactor , 0.2f * fadeFactor , 0.2f * fadeFactor , 0.5f * fadeFactor ) ;
glEnableClientState ( GL_VERTEX_ARRAY ) ;
glVertexPointer ( 2 , GL_INT , 0 , & vertices [ 0 ] ) ;
glDrawArrays ( GL_TRIANGLES , 0 , 3 ) ;
glDisableClientState ( GL_VERTEX_ARRAY ) ;
//border
vertices [ 0 ] = Vec2i ( x , y ) ;
vertices [ 1 ] = Vec2i ( x + 20 , y - 10 ) ;
vertices [ 2 ] = Vec2i ( x + 10 , y - 20 ) ;
Vec4f colors [ 4 ] ;
colors [ 0 ] = Vec4f ( 1.f , 0.2f , 0 , color1 ) ;
colors [ 1 ] = Vec4f ( 1.f , 0.4f , 0 , color2 ) ;
colors [ 2 ] = Vec4f ( 1.f , 0.4f , 0 , color2 ) ;
glLineWidth ( 2 ) ;
glEnableClientState ( GL_VERTEX_ARRAY ) ;
glVertexPointer ( 2 , GL_INT , 0 , & vertices [ 0 ] ) ;
glEnableClientState ( GL_COLOR_ARRAY ) ;
glColorPointer ( 4 , GL_FLOAT , 0 , & colors [ 0 ] ) ;
glDrawArrays ( GL_LINE_LOOP , 0 , 3 ) ;
glDisableClientState ( GL_COLOR_ARRAY ) ;
glDisableClientState ( GL_VERTEX_ARRAY ) ;
2010-03-13 22:10:45 +01:00
glPopAttrib ( ) ;
2011-04-28 01:37:57 +02:00
*/
2010-03-13 22:10:45 +01:00
}
2010-04-15 07:06:15 +02:00
void Renderer : : renderMouse3d ( ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2012-02-03 07:16:50 +01:00
Config & config = Config : : getInstance ( ) ;
if ( config . getBool ( " RecordMode " , " false " ) = = true ) {
return ;
}
2010-04-15 07:06:15 +02:00
if ( game = = NULL ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s] Line: %d game == NULL " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( szBuf ) ;
2010-04-15 07:06:15 +02:00
}
else if ( game - > getGui ( ) = = NULL ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s] Line: %d game->getGui() == NULL " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( szBuf ) ;
2010-04-15 07:06:15 +02:00
}
else if ( game - > getGui ( ) - > getMouse3d ( ) = = NULL ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s] Line: %d game->getGui()->getMouse3d() == NULL " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( szBuf ) ;
2010-04-15 07:06:15 +02:00
}
2010-03-13 22:10:45 +01:00
const Gui * gui = game - > getGui ( ) ;
const Mouse3d * mouse3d = gui - > getMouse3d ( ) ;
const Map * map = game - > getWorld ( ) - > getMap ( ) ;
2011-01-15 09:45:17 +01:00
if ( map = = NULL ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s] Line: %d map == NULL " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( szBuf ) ;
2011-01-15 09:45:17 +01:00
}
2010-03-13 22:10:45 +01:00
assertGl ( ) ;
2011-01-15 09:45:17 +01:00
if ( ( mouse3d - > isEnabled ( ) | | gui - > isPlacingBuilding ( ) ) & & gui - > isValidPosObjWorld ( ) ) {
2012-06-22 06:58:44 +02:00
const Vec2i & pos = gui - > getPosObjWorld ( ) ;
2010-03-13 22:10:45 +01:00
glMatrixMode ( GL_MODELVIEW ) ;
2012-06-22 06:58:44 +02:00
2010-03-13 22:10:45 +01:00
glPushAttrib ( GL_CURRENT_BIT | GL_LIGHTING_BIT | GL_ENABLE_BIT | GL_DEPTH_BUFFER_BIT ) ;
glEnable ( GL_BLEND ) ;
glDisable ( GL_STENCIL_TEST ) ;
glDepthFunc ( GL_LESS ) ;
glEnable ( GL_COLOR_MATERIAL ) ;
glDepthMask ( GL_FALSE ) ;
2011-01-15 09:45:17 +01:00
if ( gui - > isPlacingBuilding ( ) ) {
2010-03-13 22:10:45 +01:00
2013-01-15 04:18:26 +01:00
modelRenderer - > begin ( true , true , false , false ) ;
2010-03-13 22:10:45 +01:00
2012-06-22 06:58:44 +02:00
const UnitType * building = gui - > getBuilding ( ) ;
2012-06-22 15:30:15 +02:00
const Gui * gui = game - > getGui ( ) ;
renderGhostModel ( building , pos , gui - > getSelectedFacing ( ) ) ;
2010-06-17 02:08:27 +02:00
2010-03-13 22:10:45 +01:00
modelRenderer - > end ( ) ;
2012-06-22 06:58:44 +02:00
glDisable ( GL_COLOR_MATERIAL ) ;
glPopAttrib ( ) ;
2010-03-13 22:10:45 +01:00
}
2011-01-15 09:45:17 +01:00
else {
2012-06-22 06:58:44 +02:00
glPushMatrix ( ) ;
Vec3f pos3f = Vec3f ( pos . x , map - > getCell ( pos ) - > getHeight ( ) , pos . y ) ;
Vec4f color ;
GLUquadricObj * cilQuadric ;
2010-03-13 22:10:45 +01:00
//standard mouse
glDisable ( GL_TEXTURE_2D ) ;
glDisable ( GL_CULL_FACE ) ;
color = Vec4f ( 1.f , 0.f , 0.f , 1.f - mouse3d - > getFade ( ) ) ;
glColor4fv ( color . ptr ( ) ) ;
glMaterialfv ( GL_FRONT_AND_BACK , GL_AMBIENT , color . ptr ( ) ) ;
glTranslatef ( pos3f . x , pos3f . y + 2.f , pos3f . z ) ;
glRotatef ( 90.f , 1.f , 0.f , 0.f ) ;
glRotatef ( static_cast < float > ( mouse3d - > getRot ( ) ) , 0.f , 0.f , 1.f ) ;
cilQuadric = gluNewQuadric ( ) ;
gluQuadricDrawStyle ( cilQuadric , GLU_FILL ) ;
gluCylinder ( cilQuadric , 0.5f , 0.f , 2.f , 4 , 1 ) ;
gluCylinder ( cilQuadric , 0.5f , 0.f , 0.f , 4 , 1 ) ;
glTranslatef ( 0.f , 0.f , 1.f ) ;
gluCylinder ( cilQuadric , 0.7f , 0.f , 1.f , 4 , 1 ) ;
gluCylinder ( cilQuadric , 0.7f , 0.f , 0.f , 4 , 1 ) ;
gluDeleteQuadric ( cilQuadric ) ;
2012-06-22 06:58:44 +02:00
glPopAttrib ( ) ;
glPopMatrix ( ) ;
2012-04-03 00:17:10 +02:00
}
2010-03-13 22:10:45 +01:00
}
}
2010-08-31 08:38:27 +02:00
void Renderer : : renderBackground ( const Texture2D * texture ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2010-03-13 22:10:45 +01:00
const Metrics & metrics = Metrics : : getInstance ( ) ;
assertGl ( ) ;
glPushAttrib ( GL_ENABLE_BIT ) ;
glDisable ( GL_LIGHTING ) ;
glEnable ( GL_TEXTURE_2D ) ;
renderQuad ( 0 , 0 , metrics . getVirtualW ( ) , metrics . getVirtualH ( ) , texture ) ;
glPopAttrib ( ) ;
assertGl ( ) ;
}
2011-01-15 09:45:17 +01:00
void Renderer : : renderTextureQuad ( int x , int y , int w , int h , const Texture2D * texture , float alpha , const Vec3f * color ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2010-03-13 22:10:45 +01:00
assertGl ( ) ;
glPushAttrib ( GL_ENABLE_BIT ) ;
glDisable ( GL_LIGHTING ) ;
glEnable ( GL_TEXTURE_2D ) ;
glEnable ( GL_BLEND ) ;
2010-10-22 09:28:55 +02:00
if ( color ! = NULL ) {
Vec4f newColor ( * color ) ;
newColor . w = alpha ;
glColor4fv ( newColor . ptr ( ) ) ;
}
else {
glColor4f ( 1.f , 1.f , 1.f , alpha ) ;
}
2010-03-13 22:10:45 +01:00
renderQuad ( x , y , w , h , texture ) ;
glPopAttrib ( ) ;
assertGl ( ) ;
}
2011-06-10 05:09:19 +02:00
void Renderer : : renderConsoleLine3D ( int lineIndex , int xPosition , int yPosition , int lineHeight ,
Font3D * font , string stringToHightlight , const ConsoleLineInfo * lineInfo ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2011-06-10 05:09:19 +02:00
Vec4f fontColor ;
2011-10-03 02:36:28 +02:00
Lang & lang = Lang : : getInstance ( ) ;
2011-09-01 01:10:43 +02:00
//const Metrics &metrics= Metrics::getInstance();
2011-06-10 05:09:19 +02:00
FontMetrics * fontMetrics = font - > getMetrics ( ) ;
if ( game ! = NULL ) {
fontColor = game - > getGui ( ) - > getDisplay ( ) - > getColor ( ) ;
}
else {
// white shadowed is default ( in the menu for example )
//fontColor=Vec4f(1.f, 1.f, 1.f, 0.0f);
fontColor = Vec4f ( lineInfo - > color . x , lineInfo - > color . y , lineInfo - > color . z , 0.0f ) ;
}
Vec4f defaultFontColor = fontColor ;
if ( lineInfo - > PlayerIndex > = 0 ) {
std : : map < int , Texture2D * > & crcPlayerTextureCache = CacheManager : : getCachedItem < std : : map < int , Texture2D * > > ( GameConstants : : playerTextureCacheLookupKey ) ;
Vec3f playerColor = crcPlayerTextureCache [ lineInfo - > PlayerIndex ] - > getPixmap ( ) - > getPixel3f ( 0 , 0 ) ;
fontColor . x = playerColor . x ;
fontColor . y = playerColor . y ;
fontColor . z = playerColor . z ;
GameNetworkInterface * gameNetInterface = NetworkManager : : getInstance ( ) . getGameNetworkInterface ( ) ;
if ( gameNetInterface ! = NULL & & gameNetInterface - > getGameSettings ( ) ! = NULL ) {
const GameSettings * gameSettings = gameNetInterface - > getGameSettings ( ) ;
string playerName = gameSettings - > getNetworkPlayerNameByPlayerIndex ( lineInfo - > PlayerIndex ) ;
if ( playerName ! = lineInfo - > originalPlayerName & & lineInfo - > originalPlayerName ! = " " ) {
playerName = lineInfo - > originalPlayerName ;
}
2012-10-06 19:50:27 +02:00
if ( playerName = = GameConstants : : NETWORK_SLOT_UNCONNECTED_SLOTNAME ) {
2013-10-29 07:13:38 +01:00
playerName = lang . getString ( " SystemUser " ) ;
2012-10-06 19:50:27 +02:00
}
2011-06-10 05:09:19 +02:00
//printf("playerName [%s], line [%s]\n",playerName.c_str(),line.c_str());
//string headerLine = "*" + playerName + ":";
2011-10-03 02:36:28 +02:00
//string headerLine = playerName + ": ";
string headerLine = playerName ;
if ( lineInfo - > teamMode = = true ) {
2013-10-29 07:13:38 +01:00
headerLine + = " ( " + lang . getString ( " Team " ) + " ) " ;
2011-10-03 02:36:28 +02:00
}
headerLine + = " : " ;
2011-06-10 05:09:19 +02:00
if ( fontMetrics = = NULL ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " fontMetrics == NULL " ) ;
2011-06-10 05:09:19 +02:00
}
renderTextShadow3D (
headerLine ,
font ,
fontColor ,
xPosition , lineIndex * lineHeight + yPosition ) ;
fontColor = defaultFontColor ;
//xPosition += (8 * (playerName.length() + 2));
// Proper font spacing after username portion of chat text rendering
2011-06-28 02:51:13 +02:00
//xPosition += (metrics.toVirtualX(fontMetrics->getTextWidth(headerLine)));
xPosition + = fontMetrics - > getTextWidth ( headerLine ) ;
2011-06-10 05:09:19 +02:00
}
}
else if ( lineInfo - > originalPlayerName ! = " " ) {
string playerName = lineInfo - > originalPlayerName ;
2011-10-03 02:36:28 +02:00
//string headerLine = playerName + ": ";
string headerLine = playerName ;
if ( lineInfo - > teamMode = = true ) {
2013-10-29 07:13:38 +01:00
headerLine + = " ( " + lang . getString ( " Team " ) + " ) " ;
2011-10-03 02:36:28 +02:00
}
headerLine + = " : " ;
2011-06-10 05:09:19 +02:00
if ( fontMetrics = = NULL ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " fontMetrics == NULL " ) ;
2011-06-10 05:09:19 +02:00
}
renderTextShadow3D (
headerLine ,
font ,
fontColor ,
xPosition , lineIndex * lineHeight + yPosition ) ;
fontColor = defaultFontColor ;
//xPosition += (8 * (playerName.length() + 2));
// Proper font spacing after username portion of chat text rendering
2011-06-28 02:51:13 +02:00
//xPosition += (metrics.toVirtualX(fontMetrics->getTextWidth(headerLine)));
xPosition + = fontMetrics - > getTextWidth ( headerLine ) ;
2011-06-10 05:09:19 +02:00
}
else {
fontColor = defaultFontColor ;
}
if ( stringToHightlight ! = " " & & lineInfo - > text . find ( stringToHightlight ) ! = string : : npos ) {
fontColor = Vec4f ( 1.f , 0.5f , 0.5f , 0.0f ) ;
}
renderTextShadow3D (
lineInfo - > text ,
font ,
fontColor ,
xPosition , ( lineIndex * lineHeight ) + yPosition ) ;
}
2010-12-27 01:59:57 +01:00
void Renderer : : renderConsoleLine ( int lineIndex , int xPosition , int yPosition , int lineHeight ,
2011-06-06 23:38:25 +02:00
Font2D * font , string stringToHightlight , const ConsoleLineInfo * lineInfo ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2010-04-11 02:45:09 +02:00
Vec4f fontColor ;
2011-10-03 02:36:28 +02:00
Lang & lang = Lang : : getInstance ( ) ;
2010-12-27 01:59:57 +01:00
const Metrics & metrics = Metrics : : getInstance ( ) ;
2011-06-06 23:38:25 +02:00
FontMetrics * fontMetrics = font - > getMetrics ( ) ;
2011-01-02 07:46:48 +01:00
2010-10-22 09:28:55 +02:00
if ( game ! = NULL ) {
fontColor = game - > getGui ( ) - > getDisplay ( ) - > getColor ( ) ;
2010-04-11 02:45:09 +02:00
}
else {
// white shadowed is default ( in the menu for example )
2011-03-26 18:17:34 +01:00
//fontColor=Vec4f(1.f, 1.f, 1.f, 0.0f);
fontColor = Vec4f ( lineInfo - > color . x , lineInfo - > color . y , lineInfo - > color . z , 0.0f ) ;
2010-04-11 02:45:09 +02:00
}
2010-10-22 09:28:55 +02:00
Vec4f defaultFontColor = fontColor ;
2010-10-23 06:00:39 +02:00
if ( lineInfo - > PlayerIndex > = 0 ) {
2010-10-22 09:28:55 +02:00
std : : map < int , Texture2D * > & crcPlayerTextureCache = CacheManager : : getCachedItem < std : : map < int , Texture2D * > > ( GameConstants : : playerTextureCacheLookupKey ) ;
2010-10-23 06:00:39 +02:00
Vec3f playerColor = crcPlayerTextureCache [ lineInfo - > PlayerIndex ] - > getPixmap ( ) - > getPixel3f ( 0 , 0 ) ;
2010-10-22 23:54:47 +02:00
fontColor . x = playerColor . x ;
fontColor . y = playerColor . y ;
fontColor . z = playerColor . z ;
GameNetworkInterface * gameNetInterface = NetworkManager : : getInstance ( ) . getGameNetworkInterface ( ) ;
if ( gameNetInterface ! = NULL & & gameNetInterface - > getGameSettings ( ) ! = NULL ) {
const GameSettings * gameSettings = gameNetInterface - > getGameSettings ( ) ;
2010-10-23 06:00:39 +02:00
string playerName = gameSettings - > getNetworkPlayerNameByPlayerIndex ( lineInfo - > PlayerIndex ) ;
if ( playerName ! = lineInfo - > originalPlayerName & & lineInfo - > originalPlayerName ! = " " ) {
playerName = lineInfo - > originalPlayerName ;
}
//printf("playerName [%s], line [%s]\n",playerName.c_str(),line.c_str());
2010-11-02 21:19:56 +01:00
//string headerLine = "*" + playerName + ":";
2011-10-03 02:36:28 +02:00
//string headerLine = playerName + ": ";
string headerLine = playerName ;
if ( lineInfo - > teamMode = = true ) {
2013-10-29 07:13:38 +01:00
headerLine + = " ( " + lang . getString ( " Team " ) + " ) " ;
2011-10-03 02:36:28 +02:00
}
headerLine + = " : " ;
2010-11-04 07:27:25 +01:00
if ( fontMetrics = = NULL ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " fontMetrics == NULL " ) ;
2010-11-04 07:27:25 +01:00
}
2010-10-22 23:54:47 +02:00
2010-10-23 06:00:39 +02:00
renderTextShadow (
2010-12-27 01:59:57 +01:00
headerLine ,
font ,
2010-10-22 23:54:47 +02:00
fontColor ,
2010-12-27 01:59:57 +01:00
xPosition , lineIndex * lineHeight + yPosition ) ;
2010-10-22 09:28:55 +02:00
2010-10-23 06:00:39 +02:00
fontColor = defaultFontColor ;
2010-11-04 07:27:25 +01:00
//xPosition += (8 * (playerName.length() + 2));
// Proper font spacing after username portion of chat text rendering
xPosition + = ( metrics . toVirtualX ( fontMetrics - > getTextWidth ( headerLine ) ) ) ;
2010-10-22 23:54:47 +02:00
}
}
2010-12-24 03:10:31 +01:00
else if ( lineInfo - > originalPlayerName ! = " " ) {
string playerName = lineInfo - > originalPlayerName ;
2011-10-03 02:36:28 +02:00
//string headerLine = playerName + ": ";
string headerLine = playerName ;
if ( lineInfo - > teamMode = = true ) {
2013-10-29 07:13:38 +01:00
headerLine + = " ( " + lang . getString ( " Team " ) + " ) " ;
2011-10-03 02:36:28 +02:00
}
headerLine + = " : " ;
2010-12-24 03:10:31 +01:00
if ( fontMetrics = = NULL ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " fontMetrics == NULL " ) ;
2010-12-24 03:10:31 +01:00
}
renderTextShadow (
2010-12-27 01:59:57 +01:00
headerLine ,
font ,
2010-12-24 03:10:31 +01:00
fontColor ,
2010-12-27 01:59:57 +01:00
xPosition , lineIndex * lineHeight + yPosition ) ;
2010-12-24 03:10:31 +01:00
fontColor = defaultFontColor ;
//xPosition += (8 * (playerName.length() + 2));
// Proper font spacing after username portion of chat text rendering
xPosition + = ( metrics . toVirtualX ( fontMetrics - > getTextWidth ( headerLine ) ) ) ;
}
2010-10-22 23:54:47 +02:00
else {
fontColor = defaultFontColor ;
}
2011-01-01 23:08:34 +01:00
if ( stringToHightlight ! = " " & & lineInfo - > text . find ( stringToHightlight ) ! = string : : npos ) {
2011-01-01 21:31:25 +01:00
fontColor = Vec4f ( 1.f , 0.5f , 0.5f , 0.0f ) ;
}
2010-10-22 23:54:47 +02:00
renderTextShadow (
2010-10-23 06:00:39 +02:00
lineInfo - > text ,
2010-12-27 01:59:57 +01:00
font ,
2010-10-22 23:54:47 +02:00
fontColor ,
2010-12-27 01:59:57 +01:00
xPosition , ( lineIndex * lineHeight ) + yPosition ) ;
2010-10-22 23:54:47 +02:00
}
2014-10-31 01:08:12 +01:00
void Renderer : : renderConsole ( const Console * console , ConsoleMode mode , int overrideMaxConsoleLines ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2010-10-22 23:54:47 +02:00
if ( console = = NULL ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " console == NULL " ) ;
2010-10-22 23:54:47 +02:00
}
glPushAttrib ( GL_ENABLE_BIT ) ;
glEnable ( GL_BLEND ) ;
2014-10-31 01:08:12 +01:00
if ( mode = = consoleFull ) {
2013-10-23 22:23:21 +02:00
int x = console - > getXPos ( ) - 5 ;
int y = console - > getYPos ( ) - 5 ;
int h = console - > getLineHeight ( ) * console - > getStoredLineCount ( ) ;
2013-10-25 07:45:54 +02:00
if ( h > 0 ) {
int w = 1000 ;
2013-10-23 22:33:00 +02:00
//background
glPushAttrib ( GL_ENABLE_BIT | GL_CURRENT_BIT ) ;
glEnable ( GL_BLEND ) ;
glColor4f ( 0.0f , 0.0f , 0.0f , 0.8f ) ;
glBegin ( GL_TRIANGLE_STRIP ) ;
glVertex2i ( x , y ) ;
glVertex2i ( x , y + h ) ;
glVertex2i ( x + w , y ) ;
glVertex2i ( x + w , y + h ) ;
glEnd ( ) ;
2013-10-24 01:11:18 +02:00
glPopAttrib ( ) ;
2013-10-23 22:33:00 +02:00
}
2010-10-22 23:54:47 +02:00
for ( int i = 0 ; i < console - > getStoredLineCount ( ) ; + + i ) {
2010-10-23 06:00:39 +02:00
const ConsoleLineInfo & lineInfo = console - > getStoredLineItem ( i ) ;
2011-06-10 05:09:19 +02:00
if ( renderText3DEnabled = = true ) {
renderConsoleLine3D ( i , console - > getXPos ( ) , console - > getYPos ( ) ,
console - > getLineHeight ( ) , console - > getFont3D ( ) ,
console - > getStringToHighlight ( ) , & lineInfo ) ;
}
else {
renderConsoleLine ( i , console - > getXPos ( ) , console - > getYPos ( ) ,
console - > getLineHeight ( ) , console - > getFont ( ) ,
console - > getStringToHighlight ( ) , & lineInfo ) ;
}
2010-06-09 00:50:37 +02:00
}
}
2014-10-31 01:08:12 +01:00
else if ( mode = = consoleStoredOnly ) {
2011-04-15 01:13:44 +02:00
int allowedMaxLines = ( overrideMaxConsoleLines > = 0 ? overrideMaxConsoleLines : maxConsoleLines ) ;
for ( int i = 0 ; i < console - > getStoredLineCount ( ) & & i < allowedMaxLines ; + + i ) {
2010-10-23 06:00:39 +02:00
const ConsoleLineInfo & lineInfo = console - > getStoredLineItem ( i ) ;
2011-06-10 05:09:19 +02:00
if ( renderText3DEnabled = = true ) {
renderConsoleLine3D ( i , console - > getXPos ( ) , console - > getYPos ( ) ,
console - > getLineHeight ( ) , console - > getFont3D ( ) , console - > getStringToHighlight ( ) , & lineInfo ) ;
}
else {
renderConsoleLine ( i , console - > getXPos ( ) , console - > getYPos ( ) ,
console - > getLineHeight ( ) , console - > getFont ( ) , console - > getStringToHighlight ( ) , & lineInfo ) ;
}
2010-04-14 22:49:14 +02:00
}
}
2014-10-31 01:08:12 +01:00
else if ( mode = = consoleStoredAndNormal ) {
int allowedMaxLines = ( overrideMaxConsoleLines > = 0 ? overrideMaxConsoleLines : maxConsoleLines ) ;
2014-11-24 01:10:10 +01:00
float starttimestamp = - 1 ;
2014-10-31 01:08:12 +01:00
int consoleIndex = 0 ;
for ( int i = 0 ; i < console - > getLineCount ( ) & & i < allowedMaxLines ; + + i ) {
const ConsoleLineInfo & lineInfo = console - > getLineItem ( i ) ;
2014-11-24 01:10:10 +01:00
if ( starttimestamp > lineInfo . timeStamp | | starttimestamp = = - 1 ) starttimestamp = lineInfo . timeStamp ;
2014-10-31 01:08:12 +01:00
if ( renderText3DEnabled = = true ) {
renderConsoleLine3D ( i , console - > getXPos ( ) , console - > getYPos ( ) ,
console - > getLineHeight ( ) , console - > getFont3D ( ) , console - > getStringToHighlight ( ) , & lineInfo ) ;
}
else {
renderConsoleLine ( i , console - > getXPos ( ) , console - > getYPos ( ) ,
console - > getLineHeight ( ) , console - > getFont ( ) , console - > getStringToHighlight ( ) , & lineInfo ) ;
}
2014-11-24 01:10:10 +01:00
consoleIndex + + ;
2014-10-31 01:08:12 +01:00
}
for ( int i = 0 ; i < console - > getStoredLineCount ( ) & & consoleIndex < allowedMaxLines ; + + i ) {
const ConsoleLineInfo & lineInfo = console - > getStoredLineItem ( i ) ;
2014-11-24 01:10:10 +01:00
if ( lineInfo . timeStamp < starttimestamp | | starttimestamp = = - 1 ) {
2014-10-31 01:08:12 +01:00
if ( renderText3DEnabled = = true ) {
renderConsoleLine3D ( consoleIndex , console - > getXPos ( ) , console - > getYPos ( ) ,
console - > getLineHeight ( ) , console - > getFont3D ( ) , console - > getStringToHighlight ( ) , & lineInfo ) ;
}
else {
renderConsoleLine ( consoleIndex , console - > getXPos ( ) , console - > getYPos ( ) ,
console - > getLineHeight ( ) , console - > getFont ( ) , console - > getStringToHighlight ( ) , & lineInfo ) ;
}
2014-11-24 01:10:10 +01:00
consoleIndex + + ;
2014-10-31 01:08:12 +01:00
}
}
}
else if ( mode = = consoleNormal ) {
2010-10-22 09:28:55 +02:00
for ( int i = 0 ; i < console - > getLineCount ( ) ; + + i ) {
2010-10-23 06:00:39 +02:00
const ConsoleLineInfo & lineInfo = console - > getLineItem ( i ) ;
2011-06-10 05:09:19 +02:00
if ( renderText3DEnabled = = true ) {
renderConsoleLine3D ( i , console - > getXPos ( ) , console - > getYPos ( ) ,
console - > getLineHeight ( ) , console - > getFont3D ( ) , console - > getStringToHighlight ( ) , & lineInfo ) ;
}
else {
renderConsoleLine ( i , console - > getXPos ( ) , console - > getYPos ( ) ,
console - > getLineHeight ( ) , console - > getFont ( ) , console - > getStringToHighlight ( ) , & lineInfo ) ;
}
2010-04-14 22:49:14 +02:00
}
}
2010-03-13 22:10:45 +01:00
glPopAttrib ( ) ;
}
2010-10-22 09:28:55 +02:00
void Renderer : : renderChatManager ( const ChatManager * chatManager ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2010-06-22 22:53:54 +02:00
Vec4f fontColor ;
2010-03-13 22:10:45 +01:00
Lang & lang = Lang : : getInstance ( ) ;
2010-10-22 09:28:55 +02:00
if ( chatManager - > getEditEnabled ( ) ) {
2015-12-13 22:56:47 +01:00
Vec4f color = Vec4f ( 0.0f , 0.0f , 0.0f , 0.6f ) ;
2010-10-22 09:28:55 +02:00
string text = " " ;
2010-03-13 22:10:45 +01:00
2012-09-20 06:10:34 +02:00
if ( chatManager - > isInCustomInputMode ( ) = = true ) {
2013-10-29 07:13:38 +01:00
text + = lang . getString ( " CellHint " ) ;
2012-09-20 06:10:34 +02:00
}
else if ( chatManager - > getInMenu ( ) ) {
2013-10-29 07:13:38 +01:00
text + = lang . getString ( " Chat " ) ;
2011-01-01 21:31:25 +01:00
}
else if ( chatManager - > getTeamMode ( ) ) {
2013-10-29 07:13:38 +01:00
text + = lang . getString ( " Team " ) ;
2010-03-13 22:10:45 +01:00
}
2010-10-22 09:28:55 +02:00
else {
2013-10-29 07:13:38 +01:00
text + = lang . getString ( " All " ) ;
2010-03-13 22:10:45 +01:00
}
2010-10-22 09:28:55 +02:00
text + = " : " + chatManager - > getText ( ) + " _ " ;
2010-03-13 22:10:45 +01:00
2010-10-22 09:28:55 +02:00
if ( game ! = NULL ) {
fontColor = game - > getGui ( ) - > getDisplay ( ) - > getColor ( ) ;
2010-06-22 22:53:54 +02:00
}
else {
// white shadowed is default ( in the menu for example )
fontColor = Vec4f ( 1.f , 1.f , 1.f , 0.0f ) ;
}
2010-12-05 02:33:28 +01:00
2015-12-13 22:56:47 +01:00
// render Background
int x = chatManager - > getXPos ( ) ;
int y = chatManager - > getYPos ( ) - 6 ;
int h = 22 ;
int w = 830 ;
glPushAttrib ( GL_ENABLE_BIT | GL_CURRENT_BIT ) ;
glEnable ( GL_BLEND ) ;
glColor4f ( color . x , color . y , color . z , color . w ) ;
glBegin ( GL_TRIANGLE_STRIP ) ;
glVertex2i ( x , y ) ;
glVertex2i ( x , y + h ) ;
glVertex2i ( x + w , y ) ;
glVertex2i ( x + w , y + h ) ;
glEnd ( ) ;
glPopAttrib ( ) ;
2011-06-10 05:09:19 +02:00
if ( renderText3DEnabled = = true ) {
renderTextShadow3D (
text ,
chatManager - > getFont3D ( ) ,
fontColor ,
chatManager - > getXPos ( ) , chatManager - > getYPos ( ) ) ;
}
else {
renderTextShadow (
text ,
chatManager - > getFont ( ) ,
fontColor ,
chatManager - > getXPos ( ) , chatManager - > getYPos ( ) ) ;
}
2010-03-13 22:10:45 +01:00
}
2011-01-01 21:31:25 +01:00
else
{
if ( chatManager - > getInMenu ( ) ) {
2015-02-06 01:02:34 +01:00
string text = " \t \t \t \t \t >> " + lang . getString ( " PressEnterToChat " ) + " << " ;
2011-01-01 21:31:25 +01:00
fontColor = Vec4f ( 0.5f , 0.5f , 0.5f , 0.5f ) ;
2011-06-10 05:09:19 +02:00
if ( renderText3DEnabled = = true ) {
renderTextShadow3D ( text , chatManager - > getFont3D ( ) , fontColor ,
chatManager - > getXPos ( ) , chatManager - > getYPos ( ) ) ;
}
else {
renderTextShadow ( text , chatManager - > getFont ( ) , fontColor ,
chatManager - > getXPos ( ) , chatManager - > getYPos ( ) ) ;
}
2011-01-01 21:31:25 +01:00
}
}
2010-03-13 22:10:45 +01:00
}
2013-11-11 02:42:27 +01:00
void Renderer : : renderPerformanceStats ( ) {
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
const Metrics & metrics = Metrics : : getInstance ( ) ;
const Vec4f fontColor = game - > getGui ( ) - > getDisplay ( ) - > getColor ( ) ;
char szBuf [ 200 ] = " " ;
snprintf ( szBuf , 200 , " Frame: %d " , game - > getWorld ( ) - > getFrameCount ( ) / 20 ) ;
string str = string ( szBuf ) + string ( " \n " ) ;
static time_t lastGamePerfCheck = time ( NULL ) ;
static string gamePerfStats = " " ;
if ( difftime ( ( long int ) time ( NULL ) , lastGamePerfCheck ) > 3 ) {
lastGamePerfCheck = time ( NULL ) ;
2013-11-11 05:08:10 +01:00
gamePerfStats = game - > getGamePerformanceCounts ( true ) ;
2013-11-11 02:42:27 +01:00
}
if ( gamePerfStats ! = " " ) {
str + = gamePerfStats + " \n " ;
}
if ( renderText3DEnabled = = true ) {
renderTextShadow3D (
str , CoreData : : getInstance ( ) . getDisplayFontSmall3D ( ) ,
fontColor ,
10 , metrics . getVirtualH ( ) - 180 , false ) ;
}
else {
renderTextShadow (
str , CoreData : : getInstance ( ) . getDisplayFontSmall ( ) ,
fontColor ,
10 , metrics . getVirtualH ( ) - 180 , false ) ;
}
}
2012-08-15 16:37:27 +02:00
void Renderer : : renderClock ( ) {
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2012-08-16 08:31:02 +02:00
Config & config = Config : : getInstance ( ) ;
2013-11-10 05:42:24 +01:00
if ( config . getBool ( " InGameClock " , " true " ) = = false & &
config . getBool ( " InGameLocalClock " , " true " ) = = false & &
config . getBool ( " InGameFrameCounter " , " false " ) = = false ) {
2012-08-16 08:31:02 +02:00
return ;
}
2012-08-16 23:15:31 +02:00
string str = " " ;
2012-08-15 16:37:27 +02:00
const Metrics & metrics = Metrics : : getInstance ( ) ;
const World * world = game - > getWorld ( ) ;
const Vec4f fontColor = game - > getGui ( ) - > getDisplay ( ) - > getColor ( ) ;
2012-08-16 23:15:31 +02:00
if ( config . getBool ( " InGameClock " , " true " ) = = true ) {
Lang & lang = Lang : : getInstance ( ) ;
2013-12-17 22:26:58 +01:00
char szBuf [ 501 ] = " " ;
//int hours = world->getTimeFlow()->getTime();
//int minutes = (world->getTimeFlow()->getTime() - hours) * 100 * 0.6; // scale 100 to 60
//snprintf(szBuf,200,"%s %.2d:%.2d",lang.getString("GameTime","",true).c_str(),hours,minutes);
// string header2 = lang.getString("GameDurationTime","",true) + ": " + getTimeString(stats.getFramesToCalculatePlaytime());
snprintf ( szBuf , 500 , " %s %s " , lang . getString ( " GameDurationTime " , " " , true ) . c_str ( ) , getTimeDuationString ( world - > getFrameCount ( ) , GameConstants : : updateFps ) . c_str ( ) ) ;
2012-08-16 23:15:31 +02:00
if ( str ! = " " ) {
str + = " " ;
}
str + = szBuf ;
}
2012-08-16 08:31:02 +02:00
2012-08-16 23:15:31 +02:00
if ( config . getBool ( " InGameLocalClock " , " true " ) = = true ) {
2015-11-21 20:30:23 +01:00
//time_t nowTime = time(NULL);
//struct tm *loctime = localtime(&nowTime);
struct tm loctime = threadsafe_localtime ( systemtime_now ( ) ) ;
2012-08-16 23:15:31 +02:00
char szBuf2 [ 100 ] = " " ;
2015-11-21 20:30:23 +01:00
strftime ( szBuf2 , 100 , " %H:%M " , & loctime ) ;
2012-08-16 23:15:31 +02:00
Lang & lang = Lang : : getInstance ( ) ;
char szBuf [ 200 ] = " " ;
2013-10-29 07:13:38 +01:00
snprintf ( szBuf , 200 , " %s %s " , lang . getString ( " LocalTime " , " " , true ) . c_str ( ) , szBuf2 ) ;
2012-08-16 23:15:31 +02:00
if ( str ! = " " ) {
str + = " " ;
}
str + = szBuf ;
}
2012-08-16 08:31:02 +02:00
2013-11-10 05:42:24 +01:00
if ( config . getBool ( " InGameFrameCounter " , " false " ) = = true ) {
char szBuf [ 200 ] = " " ;
snprintf ( szBuf , 200 , " Frame: %d " , game - > getWorld ( ) - > getFrameCount ( ) / 20 ) ;
if ( str ! = " " ) {
str + = " " ;
}
str + = szBuf ;
}
2012-08-16 23:15:31 +02:00
//string str = szBuf;
2012-08-15 16:37:27 +02:00
if ( renderText3DEnabled = = true ) {
renderTextShadow3D (
str , CoreData : : getInstance ( ) . getDisplayFontSmall3D ( ) ,
fontColor ,
10 , metrics . getVirtualH ( ) - 160 , false ) ;
}
else {
renderTextShadow (
str , CoreData : : getInstance ( ) . getDisplayFontSmall ( ) ,
fontColor ,
10 , metrics . getVirtualH ( ) - 160 , false ) ;
}
}
2011-01-15 09:45:17 +01:00
void Renderer : : renderResourceStatus ( ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2014-01-28 03:55:08 +01:00
const World * world = game - > getWorld ( ) ;
2015-01-10 04:03:58 +01:00
Config & config = Config : : getInstance ( ) ;
2012-04-02 03:45:13 +02:00
2014-01-28 03:55:08 +01:00
if ( world - > getThisFactionIndex ( ) < 0 | |
2014-01-30 07:47:55 +01:00
world - > getThisFactionIndex ( ) > = world - > getFactionCount ( ) ) {
2012-04-02 03:45:13 +02:00
return ;
}
2014-01-30 07:47:55 +01:00
const Faction * thisFaction = world - > getFaction ( world - > getThisFactionIndex ( ) ) ;
2018-06-13 23:27:21 +02:00
if ( thisFaction - > getPersonalityType ( ) = = fpt_Observer ) {
// render resources of selected units faction
const Gui * gui = game - > getGui ( ) ;
if ( gui ! = NULL ) {
const Selection * selection = gui - > getSelection ( ) ;
if ( selection ! = NULL & & selection - > getCount ( ) > 0 & & selection - > getFrontUnit ( ) ! = NULL ) {
const Unit * selectedUnit = selection - > getFrontUnit ( ) ;
thisFaction = selectedUnit - > getFaction ( ) ;
}
}
}
2014-01-30 07:47:55 +01:00
assertGl ( ) ;
2010-03-13 22:10:45 +01:00
glPushAttrib ( GL_ENABLE_BIT ) ;
2014-01-30 07:47:55 +01:00
int rowsRendered = 0 ;
2013-05-25 22:46:36 +02:00
int resourceCountRendered = 0 ;
2014-12-18 00:32:44 +01:00
bool twoRessourceLines = false ;
2015-01-10 04:03:58 +01:00
bool sharedTeamUnits = game ! = NULL & & game - > getGui ( ) ! = NULL
& & game - > isFlagType1BitEnabled ( ft1_allow_shared_team_units )
= = true ;
bool sharedTeamResources = game ! = NULL & & game - > getGui ( ) ! = NULL
& & game - > isFlagType1BitEnabled (
ft1_allow_shared_team_resources ) = = true ;
bool renderSharedTeamResources = false ;
bool renderSharedTeamUnits = false ;
bool renderLocalFactionResources = false ;
if ( config . getBool ( " TwoLineTeamResourceRendering " , " false " ) = = true ) {
if ( sharedTeamResources = = true | | sharedTeamUnits = = true ) {
twoRessourceLines = true ;
}
if ( sharedTeamResources = = true ) {
renderSharedTeamResources = true ;
renderSharedTeamUnits = true ;
}
else if ( sharedTeamUnits = = true ) {
renderSharedTeamUnits = true ;
renderLocalFactionResources = true ;
}
else {
renderLocalFactionResources = true ;
}
}
else {
if ( sharedTeamResources = = true )
renderSharedTeamResources = true ;
else if ( sharedTeamUnits = = true )
renderSharedTeamUnits = true ;
else
renderLocalFactionResources = true ;
}
if ( renderSharedTeamResources = = true ) {
2014-12-18 00:32:44 +01:00
resourceCountRendered = 0 ;
for ( int techTreeResourceTypeIndex = 0 ;
techTreeResourceTypeIndex < world - > getTechTree ( ) - > getResourceTypeCount ( ) ;
+ + techTreeResourceTypeIndex ) {
const ResourceType * rt = world - > getTechTree ( ) - > getResourceType ( techTreeResourceTypeIndex ) ;
if ( rt - > getDisplayInHud ( ) = = false ) {
continue ;
}
2015-01-10 22:49:31 +01:00
bool showResource = world - > showResourceTypeForTeam ( rt , thisFaction - > getTeam ( ) ) ;
2014-12-18 00:32:44 +01:00
if ( showResource = = true ) {
2015-01-10 22:49:31 +01:00
rowsRendered = renderResource ( thisFaction ,
2015-01-10 04:03:58 +01:00
false , twoRessourceLines , rt , 0 ,
2014-12-18 00:32:44 +01:00
resourceCountRendered ) ;
}
}
2015-01-10 04:03:58 +01:00
if ( resourceCountRendered > 0 ) {
rowsRendered + + ;
}
2014-12-18 00:32:44 +01:00
}
2015-01-10 04:03:58 +01:00
if ( renderLocalFactionResources = = true ) {
resourceCountRendered = 0 ;
2014-12-18 00:32:44 +01:00
2015-01-10 04:03:58 +01:00
const Faction * factionForResourceView = thisFaction ;
bool localFactionResourcesOnly = true ;
2014-01-28 03:55:08 +01:00
2015-01-10 04:03:58 +01:00
for ( int techTreeResourceTypeIndex = 0 ;
techTreeResourceTypeIndex < world - > getTechTree ( ) - > getResourceTypeCount ( ) ;
+ + techTreeResourceTypeIndex ) {
const ResourceType * rt = world - > getTechTree ( ) - > getResourceType ( techTreeResourceTypeIndex ) ;
if ( rt - > getDisplayInHud ( ) = = false ) {
continue ;
}
2014-01-28 03:55:08 +01:00
2015-01-10 04:03:58 +01:00
//if any unit produces the resource
2015-01-10 22:49:31 +01:00
bool showResource ;
if ( twoRessourceLines )
showResource = world - > showResourceTypeForTeam ( rt ,
factionForResourceView - > getTeam ( ) ) ;
else
showResource = world - > showResourceTypeForFaction ( rt ,
factionForResourceView ) ;
2015-01-10 04:03:58 +01:00
if ( showResource = = true ) {
renderResource ( factionForResourceView , localFactionResourcesOnly ,
twoRessourceLines , rt , rowsRendered , resourceCountRendered ) ;
}
}
if ( resourceCountRendered > 0 ) {
rowsRendered + + ;
}
}
2014-01-28 03:55:08 +01:00
2015-01-10 04:03:58 +01:00
if ( renderSharedTeamUnits = = true ) {
resourceCountRendered = 0 ;
2014-01-28 03:55:08 +01:00
2015-01-10 04:03:58 +01:00
const Faction * factionForResourceView = thisFaction ;
bool localFactionResourcesOnly = true ;
2014-01-28 03:55:08 +01:00
2015-01-10 04:03:58 +01:00
const Gui * gui = game - > getGui ( ) ;
if ( gui ! = NULL ) {
const Selection * selection = gui - > getSelection ( ) ;
if ( selection ! = NULL & & selection - > getCount ( ) > 0 & & selection - > getFrontUnit ( ) ! = NULL ) {
const Unit * selectedUnit = selection - > getFrontUnit ( ) ;
if ( selectedUnit ! = NULL & & selectedUnit - > getFaction ( ) - > isAlly ( thisFaction ) = = true ) {
factionForResourceView = selectedUnit - > getFaction ( ) ;
2014-01-30 07:47:55 +01:00
}
2010-03-13 22:10:45 +01:00
}
}
2015-01-10 04:03:58 +01:00
for ( int techTreeResourceTypeIndex = 0 ;
techTreeResourceTypeIndex < world - > getTechTree ( ) - > getResourceTypeCount ( ) ;
+ + techTreeResourceTypeIndex ) {
const ResourceType * rt = world - > getTechTree ( ) - > getResourceType ( techTreeResourceTypeIndex ) ;
if ( rt - > getDisplayInHud ( ) = = false ) {
continue ;
}
//if any unit produces the resource
2015-01-10 22:49:31 +01:00
bool showResource ;
if ( twoRessourceLines )
showResource = world - > showResourceTypeForTeam ( rt ,
factionForResourceView - > getTeam ( ) ) ;
else
showResource = world - > showResourceTypeForFaction ( rt ,
factionForResourceView ) ;
2015-01-10 04:03:58 +01:00
if ( showResource = = true ) {
renderResource ( factionForResourceView , localFactionResourcesOnly ,
twoRessourceLines , rt , rowsRendered , resourceCountRendered ) ;
}
}
2017-10-10 04:09:36 +02:00
//if(resourceCountRendered > 0) {
// rowsRendered++;
//}
2014-01-30 07:47:55 +01:00
}
2015-01-10 04:03:58 +01:00
2014-01-30 07:47:55 +01:00
glPopAttrib ( ) ;
2011-10-18 17:41:37 +02:00
2014-01-30 07:47:55 +01:00
assertGl ( ) ;
}
2014-01-28 03:55:08 +01:00
2014-01-30 07:47:55 +01:00
int Renderer : : renderResource ( const Faction * factionForResourceView , bool localFactionResourcesOnly ,
2014-12-18 00:32:44 +01:00
bool twoResourceLines , const ResourceType * rt , int startRow , int & resourceCountRendered ) {
2014-01-28 03:55:08 +01:00
2014-01-30 07:47:55 +01:00
const Metrics & metrics = Metrics : : getInstance ( ) ;
2014-12-18 00:32:44 +01:00
const int MAX_RESOURCES_PER_ROW = 6 ;
int resourceRowHeigth = 30 ;
int resourceYStart = metrics . getVirtualH ( ) - 30 ;
if ( twoResourceLines ) {
// we need to save some space
resourceYStart = metrics . getVirtualH ( ) - 22 ;
resourceRowHeigth = 16 ;
}
2014-01-28 03:55:08 +01:00
2014-01-30 07:47:55 +01:00
//draw resource status
if ( localFactionResourcesOnly = = true ) {
Vec4f resourceFontColor = Vec4f ( factionForResourceView - > getTexture ( ) - > getPixmapConst ( ) - > getPixel3f ( 0 , 0 ) ) ;
int resourceCol = 0 ;
int resourceRow = startRow ;
2014-01-28 03:55:08 +01:00
2014-12-18 00:32:44 +01:00
int x = resourceCol * 100 + 190 ;
int y = resourceYStart - ( resourceRowHeigth * resourceRow ) ;
int h = 16 ;
int w = 8 ;
glColor3f ( resourceFontColor . x , resourceFontColor . y , resourceFontColor . z ) ;
glBegin ( GL_TRIANGLE_STRIP ) ;
glVertex2i ( x , y + h ) ;
glVertex2i ( x , y ) ;
glVertex2i ( x + w , y + h / 2 ) ;
glEnd ( ) ;
2014-01-30 07:47:55 +01:00
}
2011-10-19 00:00:59 +02:00
2014-01-30 07:47:55 +01:00
const Resource * r = factionForResourceView - > getResource ( rt , localFactionResourcesOnly ) ;
string str = intToStr ( r - > getAmount ( ) ) ;
2014-01-28 03:55:08 +01:00
2014-01-30 07:47:55 +01:00
glEnable ( GL_TEXTURE_2D ) ;
2010-03-13 22:10:45 +01:00
2014-01-30 07:47:55 +01:00
const Vec4f fontColor = game - > getGui ( ) - > getDisplay ( ) - > getColor ( ) ;
Vec4f resourceFontColor = fontColor ;
bool isNegativeConsumableDisplayCycle = false ;
if ( rt - > getClass ( ) = = rcConsumable ) {
// Show in yellow/orange/red font if negative
if ( r - > getBalance ( ) * 5 + r - > getAmount ( ) < 0 ) {
if ( time ( NULL ) % 2 = = 0 ) {
isNegativeConsumableDisplayCycle = true ;
if ( r - > getBalance ( ) * 1 + r - > getAmount ( ) < 0 ) {
glColor3f ( RED . x , RED . y , RED . z ) ;
resourceFontColor = RED ;
2010-03-13 22:10:45 +01:00
}
2014-01-30 07:47:55 +01:00
else if ( r - > getBalance ( ) * 3 + r - > getAmount ( ) < 0 ) {
glColor3f ( ORANGE . x , ORANGE . y , ORANGE . z ) ;
resourceFontColor = ORANGE ;
}
else if ( r - > getBalance ( ) * 5 + r - > getAmount ( ) < 0 ) {
glColor3f ( YELLOW . x , YELLOW . y , YELLOW . z ) ;
resourceFontColor = YELLOW ;
}
2011-06-10 05:09:19 +02:00
}
2010-03-13 22:10:45 +01:00
}
}
2014-01-30 07:47:55 +01:00
if ( isNegativeConsumableDisplayCycle = = false ) {
glColor3f ( 1.f , 1.f , 1.f ) ;
}
2014-12-18 00:32:44 +01:00
2014-01-30 07:47:55 +01:00
int resourceRow = startRow + ( resourceCountRendered > 0 ? resourceCountRendered / MAX_RESOURCES_PER_ROW : 0 ) ;
int resourceCol = resourceCountRendered % MAX_RESOURCES_PER_ROW ;
2010-03-13 22:10:45 +01:00
2014-12-18 00:32:44 +01:00
renderQuad ( resourceCol * 100 + 200 , resourceYStart - ( resourceRowHeigth * resourceRow ) , 16 , 16 , rt - > getImage ( ) ) ;
2014-01-30 07:47:55 +01:00
if ( rt - > getClass ( ) ! = rcStatic ) {
str + = " / " + intToStr ( factionForResourceView - > getStoreAmount ( rt , localFactionResourcesOnly ) ) ;
}
if ( rt - > getClass ( ) = = rcConsumable ) {
str + = " ( " ;
if ( r - > getBalance ( ) > 0 ) {
str + = " + " ;
}
str + = intToStr ( r - > getBalance ( ) ) + " ) " ;
}
glDisable ( GL_TEXTURE_2D ) ;
if ( renderText3DEnabled = = true ) {
renderTextShadow3D (
str , CoreData : : getInstance ( ) . getDisplayFontSmall3D ( ) ,
resourceFontColor ,
2014-12-18 00:32:44 +01:00
resourceCol * 100 + 220 , resourceYStart - ( resourceRowHeigth * resourceRow ) , false ) ;
2014-01-30 07:47:55 +01:00
}
else {
renderTextShadow (
str , CoreData : : getInstance ( ) . getDisplayFontSmall ( ) ,
resourceFontColor ,
2014-12-18 00:32:44 +01:00
resourceCol * 100 + 220 , resourceYStart - ( resourceRowHeigth * resourceRow ) , false ) ;
2014-01-30 07:47:55 +01:00
}
+ + resourceCountRendered ;
return resourceRow ;
2010-03-13 22:10:45 +01:00
}
2011-01-15 09:45:17 +01:00
void Renderer : : renderSelectionQuad ( ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2012-02-03 07:16:50 +01:00
Config & config = Config : : getInstance ( ) ;
if ( config . getBool ( " RecordMode " , " false " ) = = true ) {
return ;
}
2010-03-13 22:10:45 +01:00
const Gui * gui = game - > getGui ( ) ;
const SelectionQuad * sq = gui - > getSelectionQuad ( ) ;
Vec2i down = sq - > getPosDown ( ) ;
Vec2i up = sq - > getPosUp ( ) ;
2010-09-10 10:51:32 +02:00
if ( gui - > isSelecting ( ) ) {
2010-03-13 22:10:45 +01:00
glPushAttrib ( GL_CURRENT_BIT | GL_LINE_BIT ) ;
2011-02-09 09:04:21 +01:00
Vec2i vertices [ 4 ] ;
vertices [ 0 ] = Vec2i ( down . x , down . y ) ;
vertices [ 1 ] = Vec2i ( up . x , down . y ) ;
vertices [ 2 ] = Vec2i ( up . x , up . y ) ;
vertices [ 3 ] = Vec2i ( down . x , up . y ) ;
glColor3f ( 0 , 1 , 0 ) ;
glEnableClientState ( GL_VERTEX_ARRAY ) ;
glVertexPointer ( 2 , GL_INT , 0 , & vertices [ 0 ] ) ;
glDrawArrays ( GL_LINE_LOOP , 0 , 4 ) ;
glDisableClientState ( GL_VERTEX_ARRAY ) ;
/*
2010-03-13 22:10:45 +01:00
glColor3f ( 0 , 1 , 0 ) ;
glBegin ( GL_LINE_LOOP ) ;
glVertex2i ( down . x , down . y ) ;
glVertex2i ( up . x , down . y ) ;
glVertex2i ( up . x , up . y ) ;
glVertex2i ( down . x , up . y ) ;
glEnd ( ) ;
2011-02-09 09:04:21 +01:00
*/
2010-03-13 22:10:45 +01:00
glPopAttrib ( ) ;
}
}
2011-06-06 23:38:25 +02:00
Vec2i computeCenteredPos ( const string & text , Font2D * font , int x , int y ) {
2010-08-05 02:09:45 +02:00
if ( font = = NULL ) {
2012-03-03 19:40:18 +01:00
//abort();
2016-10-30 16:41:31 +01:00
throw megaglest_runtime_error ( " font == NULL (1) text = " + text) ;
2010-08-05 02:09:45 +02:00
}
2010-03-13 22:10:45 +01:00
const Metrics & metrics = Metrics : : getInstance ( ) ;
2011-06-06 23:38:25 +02:00
FontMetrics * fontMetrics = font - > getMetrics ( ) ;
2010-03-13 22:10:45 +01:00
2010-08-05 02:09:45 +02:00
if ( fontMetrics = = NULL ) {
2016-10-30 16:41:31 +01:00
throw megaglest_runtime_error ( " fontMetrics == NULL (1) text = " + text) ;
2010-08-05 02:09:45 +02:00
}
int virtualX = ( fontMetrics - > getTextWidth ( text ) > 0 ? static_cast < int > ( fontMetrics - > getTextWidth ( text ) / 2.f ) : 5 ) ;
2011-11-28 06:54:31 +01:00
int virtualY = ( fontMetrics - > getHeight ( text ) > 0 ? static_cast < int > ( fontMetrics - > getHeight ( text ) / 2.f ) : 5 ) ;
2010-08-05 02:09:45 +02:00
Vec2i textPos (
x - metrics . toVirtualX ( virtualX ) ,
y - metrics . toVirtualY ( virtualY ) ) ;
2010-03-13 22:10:45 +01:00
2011-11-02 01:17:57 +01:00
//printf("text [%s] x = %d y = %d virtualX = %d virtualY = %d fontMetrics->getHeight() = %f\n",text.c_str(),x,y,virtualX,virtualY,fontMetrics->getHeight());
2010-03-13 22:10:45 +01:00
return textPos ;
}
2011-06-08 09:18:06 +02:00
Vec2i computeCenteredPos ( const string & text , Font3D * font , int x , int y ) {
if ( font = = NULL ) {
2016-10-30 16:41:31 +01:00
throw megaglest_runtime_error ( " font == NULL (2) text = " + text) ;
2011-06-08 09:18:06 +02:00
}
const Metrics & metrics = Metrics : : getInstance ( ) ;
FontMetrics * fontMetrics = font - > getMetrics ( ) ;
if ( fontMetrics = = NULL ) {
2016-10-30 16:41:31 +01:00
throw megaglest_runtime_error ( " fontMetrics == NULL (2) text = " + text) ;
2011-06-08 09:18:06 +02:00
}
int virtualX = ( fontMetrics - > getTextWidth ( text ) > 0 ? static_cast < int > ( fontMetrics - > getTextWidth ( text ) / 2.f ) : 5 ) ;
2011-11-28 06:54:31 +01:00
int virtualY = ( fontMetrics - > getHeight ( text ) > 0 ? static_cast < int > ( fontMetrics - > getHeight ( text ) / 2.f ) : 5 ) ;
2011-06-08 09:18:06 +02:00
Vec2i textPos (
x - metrics . toVirtualX ( virtualX ) ,
y - metrics . toVirtualY ( virtualY ) ) ;
return textPos ;
}
2012-07-26 17:26:59 +02:00
void Renderer : : renderTextSurroundingBox ( int x , int y , int w , int h ,
int maxEditWidth , int maxEditRenderWidth ) {
2012-07-26 08:27:00 +02:00
//glColor4fv(color.ptr());
//glBegin(GL_QUADS); // Start drawing a quad primitive
2012-07-26 17:26:59 +02:00
//printf("A w = %d maxEditWidth = %d maxEditRenderWidth = %d\n",w,maxEditWidth,maxEditRenderWidth);
if ( maxEditWidth > = 0 | | maxEditRenderWidth > = 0 ) {
//printf("B w = %d maxEditWidth = %d maxEditRenderWidth = %d\n",w,maxEditWidth,maxEditRenderWidth);
if ( maxEditRenderWidth > = 0 ) {
w = maxEditRenderWidth ;
}
else {
w = maxEditWidth ;
}
2012-07-26 08:27:00 +02:00
}
//printf("HI!!!\n");
glPointSize ( 20.0f ) ;
int margin = 4 ;
//glBegin(GL_POINTS); // Start drawing a point primitive
glBegin ( GL_LINE_LOOP ) ; // Start drawing a line primitive
glVertex3f ( x , y + h , 0.0f ) ; // The bottom left corner
glVertex3f ( x , y - margin , 0.0f ) ; // The top left corner
glVertex3f ( x + w , y - margin , 0.0f ) ; // The top right corner
glVertex3f ( x + w , y + h , 0.0f ) ; // The bottom right corner
glEnd ( ) ;
}
2019-10-24 22:58:51 +02:00
//
// renderTextBoundingBox3D
//
void Renderer : : renderTextBoundingBox3D ( const string & text , Font3D * font , float alpha , int x , int y , int w , int h , bool centeredW , bool centeredH ,
bool editModeEnabled , int maxEditWidth , int maxEditRenderWidth ) {
renderTextBoundingBox3D ( text , font , Vec4f ( 1.f , 1.f , 1.f , alpha ) , x , y , w , h , centeredW , centeredH , editModeEnabled , maxEditRenderWidth , maxEditRenderWidth ) ;
}
void Renderer : : renderTextBoundingBox3D ( const string & text , Font3D * font , const Vec3f & color , int x , int y , int w , int h , bool centeredW , bool centeredH ,
bool editModeEnabled , int maxEditWidth , int maxEditRenderWidth ) {
renderTextBoundingBox3D ( text , font , Vec4f ( color . x , color . y , color . z , 1.f ) , x , y , w , h , centeredW , centeredH , editModeEnabled , maxEditRenderWidth ,
maxEditRenderWidth ) ;
}
void Renderer : : renderTextBoundingBox3D ( const string & text , Font3D * font , const Vec4f & color , int x , int y , int w , int h , bool centeredW , bool centeredH ,
bool editModeEnabled , int maxEditWidth , int maxEditRenderWidth ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2011-06-12 07:54:54 +02:00
glPushAttrib ( GL_ENABLE_BIT | GL_CURRENT_BIT ) ;
glEnable ( GL_BLEND ) ;
2019-10-24 22:58:51 +02:00
glColor4fv ( color . ptr ( ) ) ;
2011-06-12 07:54:54 +02:00
Vec2f pos = Vec2f ( x , y ) ;
//Vec2i pos= centered? computeCenteredPos(text, font, x, y): Vec2i(x, y);
2019-10-24 22:58:51 +02:00
2011-07-02 03:56:06 +02:00
if ( centeredW = = true | | centeredH = = true ) {
2019-10-24 22:58:51 +02:00
getCentered3DPos ( text , font , pos , w , h , centeredW , centeredH ) ;
2011-06-12 07:54:54 +02:00
}
2012-07-26 08:27:00 +02:00
if ( editModeEnabled ) {
2012-07-26 17:26:59 +02:00
if ( maxEditWidth > = 0 | | maxEditRenderWidth > = 0 ) {
int useWidth = maxEditWidth ;
2012-07-26 08:27:00 +02:00
string temp = " " ;
2012-07-26 17:26:59 +02:00
for ( int i = 0 ; i < useWidth ; + + i ) {
2012-07-26 08:27:00 +02:00
temp + = DEFAULT_CHAR_FOR_WIDTH_CALC ;
}
2013-11-19 22:57:28 +01:00
float lineWidth = ( font - > getTextHandler ( ) - > Advance ( temp . c_str ( ) ) * : : Shared : : Graphics : : Font : : scaleFontValue ) ;
2012-07-26 17:26:59 +02:00
useWidth = ( int ) lineWidth ;
maxEditWidth = useWidth ;
2012-07-26 08:27:00 +02:00
}
2012-07-26 17:26:59 +02:00
renderTextSurroundingBox ( pos . x , pos . y , w , h , maxEditWidth , maxEditRenderWidth ) ;
2012-07-26 08:27:00 +02:00
}
2019-10-24 22:58:51 +02:00
glColor4fv ( color . ptr ( ) ) ;
2011-10-02 04:14:05 +02:00
TextRendererSafeWrapper safeTextRender ( textRenderer3D , font ) ;
2011-06-12 07:54:54 +02:00
textRenderer3D - > render ( text , pos . x , pos . y ) ;
2011-10-02 04:14:05 +02:00
safeTextRender . end ( ) ;
2011-06-12 07:54:54 +02:00
glDisable ( GL_BLEND ) ;
glPopAttrib ( ) ;
}
2019-10-24 22:58:51 +02:00
//
// renderText3D
//
2011-06-08 09:18:06 +02:00
void Renderer : : renderText3D ( const string & text , Font3D * font , float alpha , int x , int y , bool centered ) {
2019-10-24 22:58:51 +02:00
renderText3D ( text , font , Vec4f ( 1.f , 1.f , 1.f , alpha ) , x , y , centered ) ;
}
void Renderer : : renderText3D ( const string & text , Font3D * font , const Vec3f & color , int x , int y , bool centered ) {
renderText3D ( text , font , Vec4f ( color . x , color . y , color . z , 1.f ) , x , y , centered ) ;
}
void Renderer : : renderText3D ( const string & text , Font3D * font , const Vec4f & color , int x , int y , bool centered ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2011-06-08 09:18:06 +02:00
glPushAttrib ( GL_ENABLE_BIT | GL_CURRENT_BIT ) ;
glEnable ( GL_BLEND ) ;
2019-10-24 22:58:51 +02:00
glColor4fv ( color . ptr ( ) ) ;
2011-06-08 09:18:06 +02:00
2011-06-11 10:52:49 +02:00
Vec2i pos = Vec2i ( x , y ) ;
//Vec2i pos= centered? computeCenteredPos(text, font, x, y): Vec2i(x, y);
2011-06-08 09:18:06 +02:00
2011-10-02 04:14:05 +02:00
TextRendererSafeWrapper safeTextRender ( textRenderer3D , font ) ;
2011-06-11 10:52:49 +02:00
textRenderer3D - > render ( text , pos . x , pos . y , centered ) ;
2011-10-02 04:14:05 +02:00
safeTextRender . end ( ) ;
2011-06-08 09:18:06 +02:00
2011-06-11 10:52:49 +02:00
glDisable ( GL_BLEND ) ;
2011-06-08 09:18:06 +02:00
glPopAttrib ( ) ;
}
2019-10-24 22:58:51 +02:00
//
// renderText
//
2011-06-08 09:18:06 +02:00
void Renderer : : renderText ( const string & text , Font2D * font , float alpha , int x , int y , bool centered ) {
2019-10-24 22:58:51 +02:00
renderText ( text , font , Vec4f ( 1.f , 1.f , 1.f , alpha ) , x , y , centered ) ;
}
void Renderer : : renderText ( const string & text , Font2D * font , const Vec3f & color , int x , int y , bool centered ) {
renderText ( text , font , Vec4f ( color . x , color . y , color . z , 1.f ) , x , y , centered ) ;
}
void Renderer : : renderText ( const string & text , Font2D * font , const Vec4f & color , int x , int y , bool centered ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2010-03-13 22:10:45 +01:00
glPushAttrib ( GL_ENABLE_BIT | GL_CURRENT_BIT ) ;
glEnable ( GL_BLEND ) ;
2019-10-24 22:58:51 +02:00
glColor4fv ( color . ptr ( ) ) ;
2010-03-13 22:10:45 +01:00
Vec2i pos = centered ? computeCenteredPos ( text , font , x , y ) : Vec2i ( x , y ) ;
2011-10-02 04:14:05 +02:00
TextRendererSafeWrapper safeTextRender ( textRenderer , font ) ;
2010-03-13 22:10:45 +01:00
textRenderer - > render ( text , pos . x , pos . y ) ;
2011-10-02 04:14:05 +02:00
safeTextRender . end ( ) ;
2010-03-13 22:10:45 +01:00
glPopAttrib ( ) ;
}
2011-07-02 03:56:06 +02:00
Vec2f Renderer : : getCentered3DPos ( const string & text , Font3D * font , Vec2f & pos , int w , int h , bool centeredW , bool centeredH ) {
if ( centeredW = = true ) {
2012-03-28 00:44:16 +02:00
if ( font = = NULL ) {
2012-04-02 03:45:13 +02:00
//abort();
2016-10-30 16:41:31 +01:00
throw megaglest_runtime_error ( " font == NULL (5) text = " + text) ;
2012-03-28 00:44:16 +02:00
}
else if ( font - > getTextHandler ( ) = = NULL ) {
2017-01-30 20:20:01 +01:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " font->getTextHandler() == NULL(5) text = [%s] FontPtr = [%p] \n " , text . c_str ( ) , font ) ;
throw megaglest_runtime_error ( szBuf ) ;
2012-03-28 00:44:16 +02:00
}
2013-11-19 22:57:28 +01:00
float lineWidth = ( font - > getTextHandler ( ) - > Advance ( text . c_str ( ) ) * : : Shared : : Graphics : : Font : : scaleFontValue ) ;
2011-07-02 03:56:06 +02:00
if ( lineWidth < w ) {
pos . x + = ( ( w / 2.f ) - ( lineWidth / 2.f ) ) ;
}
2011-06-12 03:32:02 +02:00
}
2011-06-30 01:48:48 +02:00
2011-07-02 03:56:06 +02:00
if ( centeredH ) {
2012-03-28 00:44:16 +02:00
if ( font = = NULL ) {
2016-10-30 16:41:31 +01:00
throw megaglest_runtime_error ( " font == NULL (6) text = " + text) ;
2012-03-28 00:44:16 +02:00
}
else if ( font - > getTextHandler ( ) = = NULL ) {
2016-10-30 16:41:31 +01:00
throw megaglest_runtime_error ( " font->getTextHandler() = = NULL ( 6 ) text = " + text) ;
2012-03-28 00:44:16 +02:00
}
2011-07-02 03:56:06 +02:00
//const Metrics &metrics= Metrics::getInstance();
//float lineHeight = (font->getTextHandler()->LineHeight(text.c_str()) * Font::scaleFontValue);
2013-11-19 22:57:28 +01:00
float lineHeight = ( font - > getTextHandler ( ) - > LineHeight ( text . c_str ( ) ) * : : Shared : : Graphics : : Font : : scaleFontValue ) ;
2011-07-02 03:56:06 +02:00
//lineHeight=metrics.toVirtualY(lineHeight);
//lineHeight= lineHeight / (2.f + 0.2f * FontMetrics::DEFAULT_Y_OFFSET_FACTOR);
//pos.y += (h / 2.f) - (lineHeight / 2.f);
//pos.y += (h / 2.f) - (lineHeight);
//pos.y += (lineHeight / 2.f); // y starts at the middle of the render position, so only move up 1/2 the font height
if ( lineHeight < h ) {
2011-08-30 23:48:32 +02:00
//printf("line %d, lineHeight [%f] h [%d] text [%s]\n",__LINE__,lineHeight,h,text.c_str());
2011-11-23 21:51:58 +01:00
//if(Font::forceFTGLFonts == true) {
2011-11-18 20:53:56 +01:00
// First go to top of bounding box
pos . y + = ( h - lineHeight ) ;
2013-11-19 22:57:28 +01:00
pos . y - = ( ( h - lineHeight ) / : : Shared : : Graphics : : Font : : scaleFontValueCenterHFactor ) ;
2011-11-23 21:51:58 +01:00
// }
// else {
// pos.y += (float)(((float)h) / 2.0);
// float heightGap = (float)(((float)h - lineHeight) / 2.0);
// pos.y -= heightGap;
//
// //printf("h = %d lineHeight = %f heightGap = %f\n",h,lineHeight,heightGap);
//
// // Now calculate till we get text to middle
// //pos.y -= (realHeight / 2);
// //pos.y += (lineHeight / 2);
// }
2011-07-02 03:56:06 +02:00
}
2011-08-30 23:48:32 +02:00
else if ( lineHeight > h ) {
2011-10-03 02:36:28 +02:00
//printf("line %d, lineHeight [%f] h [%d] text [%s]\n",__LINE__,lineHeight,h,text.c_str());
2011-08-30 23:48:32 +02:00
2013-06-12 03:07:53 +02:00
pos . y + = ( std : : ceil ( lineHeight - h ) ) ;
2011-08-30 23:48:32 +02:00
}
2011-07-02 03:56:06 +02:00
}
2011-06-12 03:32:02 +02:00
return pos ;
}
2011-06-08 09:18:06 +02:00
void Renderer : : renderTextShadow3D ( const string & text , Font3D * font , const Vec4f & color , int x , int y , bool centered ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2011-06-08 09:18:06 +02:00
if ( font = = NULL ) {
2016-10-30 16:41:31 +01:00
throw megaglest_runtime_error ( " font == NULL (3) text = " + text) ;
2011-06-08 09:18:06 +02:00
}
glPushAttrib ( GL_CURRENT_BIT ) ;
Vec2i pos = centered ? computeCenteredPos ( text , font , x , y ) : Vec2i ( x , y ) ;
2011-10-02 04:14:05 +02:00
TextRendererSafeWrapper safeTextRender ( textRenderer3D , font ) ;
2011-06-08 09:18:06 +02:00
if ( color . w < 0.5 ) {
glColor3f ( 0.0f , 0.0f , 0.0f ) ;
textRenderer3D - > render ( text , pos . x - 1.0f , pos . y - 1.0f ) ;
}
glColor3f ( color . x , color . y , color . z ) ;
textRenderer3D - > render ( text , pos . x , pos . y ) ;
2011-10-02 04:14:05 +02:00
//textRenderer3D->end();
safeTextRender . end ( ) ;
2011-06-08 09:18:06 +02:00
glPopAttrib ( ) ;
}
2011-06-06 23:38:25 +02:00
void Renderer : : renderTextShadow ( const string & text , Font2D * font , const Vec4f & color , int x , int y , bool centered ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2010-04-15 07:06:15 +02:00
if ( font = = NULL ) {
2016-10-30 16:41:31 +01:00
throw megaglest_runtime_error ( " font == NULL (4) text = " + text) ;
2010-04-15 07:06:15 +02:00
}
2010-03-13 22:10:45 +01:00
glPushAttrib ( GL_CURRENT_BIT ) ;
Vec2i pos = centered ? computeCenteredPos ( text , font , x , y ) : Vec2i ( x , y ) ;
2011-10-02 04:14:05 +02:00
TextRendererSafeWrapper safeTextRender ( textRenderer , font ) ;
2011-06-08 09:18:06 +02:00
if ( color . w < 0.5 ) {
2010-04-08 22:19:25 +02:00
glColor3f ( 0.0f , 0.0f , 0.0f ) ;
2011-06-08 09:18:06 +02:00
2010-05-01 22:14:25 +02:00
textRenderer - > render ( text , pos . x - 1.0f , pos . y - 1.0f ) ;
2010-04-08 22:19:25 +02:00
}
glColor3f ( color . x , color . y , color . z ) ;
2011-06-08 09:18:06 +02:00
2010-03-13 22:10:45 +01:00
textRenderer - > render ( text , pos . x , pos . y ) ;
2011-10-02 04:14:05 +02:00
//textRenderer->end();
safeTextRender . end ( ) ;
2010-03-13 22:10:45 +01:00
glPopAttrib ( ) ;
}
// ============= COMPONENTS =============================
2011-06-06 23:38:25 +02:00
void Renderer : : renderLabel ( GraphicLabel * label ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2019-10-16 23:11:18 +02:00
if ( label - > getVisible ( ) = = false ) {
return ;
}
2013-10-25 21:35:10 +02:00
if ( label - > getEditable ( ) & & label - > getMaxEditRenderWidth ( ) > 0 )
{
int x = label - > getX ( ) ;
int y = label - > getY ( ) ;
int h = label - > getH ( ) ;
int w = label - > getMaxEditRenderWidth ( ) ;
if ( h > 0 ) {
//background
glPushAttrib ( GL_ENABLE_BIT | GL_CURRENT_BIT ) ;
glEnable ( GL_BLEND ) ;
glColor4f ( 0.2f , 0.2f , 0.2f , 0.6f * label - > getFade ( ) ) ;
glBegin ( GL_TRIANGLE_STRIP ) ;
glVertex2i ( x , y ) ;
glVertex2i ( x , y + h ) ;
glVertex2i ( x + w , y ) ;
glVertex2i ( x + w , y + h ) ;
glEnd ( ) ;
glPopAttrib ( ) ;
}
}
2014-12-15 01:07:25 +01:00
if ( label - > getRenderBackground ( ) )
{
int x = label - > getX ( ) ;
int y = label - > getY ( ) ;
int h = label - > getH ( ) ;
int w = label - > getW ( ) ;
if ( label - > getMaxEditRenderWidth ( ) > 0 ) {
w = label - > getMaxEditRenderWidth ( ) ;
}
Vec4f color = label - > getBackgroundColor ( ) ;
if ( h > 0 ) {
//background
glPushAttrib ( GL_ENABLE_BIT | GL_CURRENT_BIT ) ;
glEnable ( GL_BLEND ) ;
glColor4f ( color . x , color . y , color . z , color . w * label - > getFade ( ) ) ;
glBegin ( GL_TRIANGLE_STRIP ) ;
glVertex2i ( x , y ) ;
glVertex2i ( x , y + h ) ;
glVertex2i ( x + w , y ) ;
glVertex2i ( x + w , y + h ) ;
glEnd ( ) ;
glPopAttrib ( ) ;
}
}
2013-10-27 17:13:27 +01:00
if ( label - > getTexture ( ) ! = NULL )
{
int x = label - > getX ( ) ;
int y = label - > getY ( ) ;
int h = label - > getH ( ) ;
int w = label - > getW ( ) ;
if ( h > 0 ) {
//background
glPushAttrib ( GL_ENABLE_BIT | GL_CURRENT_BIT ) ;
glEnable ( GL_BLEND ) ;
glEnable ( GL_TEXTURE_2D ) ;
glBindTexture ( GL_TEXTURE_2D , static_cast < Texture2DGl * > ( label - > getTexture ( ) ) - > getHandle ( ) ) ;
glColor4f ( 1.0f , 1.0f , 1.0f , 1.0f * label - > getFade ( ) ) ;
glBegin ( GL_TRIANGLE_STRIP ) ;
glTexCoord2f ( 0.f , 0.f ) ;
glVertex2f ( x , y ) ;
glTexCoord2f ( 0.f , 1.f ) ;
glVertex2f ( x , y + h ) ;
2013-10-25 21:35:10 +02:00
2013-10-27 17:13:27 +01:00
glTexCoord2f ( 1.f , 0.f ) ;
glVertex2f ( x + w , y ) ;
glTexCoord2f ( 1.f , 1.f ) ;
glVertex2f ( x + w , y + h ) ;
glEnd ( ) ;
glDisable ( GL_TEXTURE_2D ) ;
glPopAttrib ( ) ;
}
}
2011-03-26 14:40:22 +01:00
Vec3f labelColor = label - > getTextColor ( ) ;
Vec4f colorWithAlpha = Vec4f ( labelColor . x , labelColor . y , labelColor . z , GraphicComponent : : getFade ( ) ) ;
renderLabel ( label , & colorWithAlpha ) ;
2010-10-22 09:28:55 +02:00
}
2011-06-06 23:38:25 +02:00
void Renderer : : renderLabel ( GraphicLabel * label , const Vec3f * color ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2010-10-22 09:28:55 +02:00
if ( color ! = NULL ) {
Vec4f colorWithAlpha = Vec4f ( * color ) ;
colorWithAlpha . w = GraphicComponent : : getFade ( ) ;
renderLabel ( label , & colorWithAlpha ) ;
}
else {
Vec4f * colorWithAlpha = NULL ;
renderLabel ( label , colorWithAlpha ) ;
}
}
2011-06-06 23:38:25 +02:00
void Renderer : : renderLabel ( GraphicLabel * label , const Vec4f * color ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2010-09-11 08:08:50 +02:00
if ( label - > getVisible ( ) = = false ) {
return ;
}
2017-02-04 21:33:18 +01:00
try {
2010-03-13 22:10:45 +01:00
glPushAttrib ( GL_ENABLE_BIT ) ;
glEnable ( GL_BLEND ) ;
2011-04-16 20:53:57 +02:00
vector < string > lines ;
2013-06-13 03:37:15 +02:00
string renderTextString = ( label - > getTextNativeTranslation ( ) ! = " " ? label - > getTextNativeTranslation ( ) : label - > getText ( ) ) ;
2011-04-16 20:53:57 +02:00
if ( label - > getWordWrap ( ) = = true ) {
2013-06-13 03:37:15 +02:00
Tokenize ( renderTextString , lines , " \n " ) ;
2010-10-22 09:28:55 +02:00
}
else {
2013-06-13 03:37:15 +02:00
lines . push_back ( renderTextString ) ;
2010-10-22 09:28:55 +02:00
}
2010-03-13 22:10:45 +01:00
2011-04-16 20:53:57 +02:00
for ( unsigned int i = 0 ; i < lines . size ( ) ; + + i ) {
Vec2i textPos ;
int x = label - > getX ( ) ;
int y = label - > getY ( ) - ( i * label - > getH ( ) ) ;
int h = label - > getH ( ) ;
int w = label - > getW ( ) ;
//if(label->getInstanceName() == "modDescrLabel") printf("~~~ lines.size() [%u] i = %d lines[i] [%s] y = %d\n",lines.size(),i,lines[i].c_str(),y);
2011-06-12 07:54:54 +02:00
if ( label - > getCentered ( ) ) {
2011-04-16 20:53:57 +02:00
textPos = Vec2i ( x + w / 2 , y + h / 2 ) ;
}
2011-06-12 07:54:54 +02:00
else {
2011-04-16 20:53:57 +02:00
textPos = Vec2i ( x , y + h / 4 ) ;
}
2012-10-22 21:38:28 +02:00
string renderTextStr = lines [ i ] ;
if ( label - > getIsPassword ( ) = = true ) {
2012-10-23 00:06:30 +02:00
if ( renderTextStr ! = " " ) {
renderTextStr = " ***** " ;
}
2012-10-22 21:38:28 +02:00
}
2011-04-16 20:53:57 +02:00
if ( color ! = NULL ) {
2011-06-10 05:09:19 +02:00
if ( renderText3DEnabled = = true ) {
2011-06-12 07:54:54 +02:00
//renderText3D(lines[i], label->getFont3D(), (*color), textPos.x, textPos.y, label->getCentered());
2011-06-28 02:51:13 +02:00
//printf("Text Render3D [%s] font3d [%p]\n",lines[i].c_str(),label->getFont3D());
2011-10-02 04:14:05 +02:00
//printf("Label render C\n");
2012-10-22 21:38:28 +02:00
renderTextBoundingBox3D ( renderTextStr , label - > getFont3D ( ) , ( * color ) ,
2012-07-26 08:27:00 +02:00
x , y , w , h , label - > getCenteredW ( ) , label - > getCenteredH ( ) ,
2012-07-26 17:26:59 +02:00
label - > getEditModeEnabled ( ) , label - > getMaxEditWidth ( ) ,
label - > getMaxEditRenderWidth ( ) ) ;
2011-06-10 05:09:19 +02:00
}
else {
2011-10-02 04:14:05 +02:00
//printf("Label render D\n");
2012-10-22 21:38:28 +02:00
renderText ( renderTextStr , label - > getFont ( ) , ( * color ) , textPos . x , textPos . y , label - > getCentered ( ) ) ;
2011-06-10 05:09:19 +02:00
}
2011-04-16 20:53:57 +02:00
}
else {
2011-06-10 05:09:19 +02:00
if ( renderText3DEnabled = = true ) {
2011-06-12 07:54:54 +02:00
//renderText3D(lines[i], label->getFont3D(), GraphicComponent::getFade(), textPos.x, textPos.y, label->getCentered());
2011-06-28 02:51:13 +02:00
//printf("Text Render3D [%s] font3d [%p]\n",lines[i].c_str(),label->getFont3D());
2011-10-02 04:14:05 +02:00
//printf("Label render E\n");
2012-10-22 21:38:28 +02:00
renderTextBoundingBox3D ( renderTextStr , label - > getFont3D ( ) ,
2012-07-26 08:27:00 +02:00
GraphicComponent : : getFade ( ) , x , y , w , h ,
label - > getCenteredW ( ) , label - > getCenteredH ( ) ,
2012-07-26 17:26:59 +02:00
label - > getEditModeEnabled ( ) , label - > getMaxEditWidth ( ) ,
label - > getMaxEditRenderWidth ( ) ) ;
2011-06-10 05:09:19 +02:00
}
else {
2011-10-02 04:14:05 +02:00
//printf("Label render F\n");
2012-10-22 21:38:28 +02:00
renderText ( renderTextStr , label - > getFont ( ) , GraphicComponent : : getFade ( ) , textPos . x , textPos . y , label - > getCentered ( ) ) ;
2011-06-10 05:09:19 +02:00
}
2011-04-16 20:53:57 +02:00
}
}
2010-03-13 22:10:45 +01:00
glPopAttrib ( ) ;
2017-02-04 21:33:18 +01:00
}
catch ( const exception & e ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s Line: %d] \n Error [%s] For Control [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , e . what ( ) , label - > getInstanceName ( ) . c_str ( ) ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , szBuf ) ;
throw megaglest_runtime_error ( szBuf ) ;
}
2010-03-13 22:10:45 +01:00
}
2011-06-06 23:38:25 +02:00
void Renderer : : renderButton ( GraphicButton * button , const Vec4f * fontColorOverride , bool * lightedOverride ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2010-09-11 08:08:50 +02:00
if ( button - > getVisible ( ) = = false ) {
return ;
}
2017-02-04 21:33:18 +01:00
try {
//char szBuf[8096]="";
//snprintf(szBuf,8096,"In [%s::%s Line: %d]\n For Control container [%s] name [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,button->getContainerName().c_str(), button->getInstanceName().c_str());
//printf(szBuf);
2010-03-13 22:10:45 +01:00
int x = button - > getX ( ) ;
int y = button - > getY ( ) ;
int h = button - > getH ( ) ;
int w = button - > getW ( ) ;
2010-04-22 01:13:39 +02:00
const Vec3f disabledTextColor = Vec3f ( 0.25f , 0.25f , 0.25f ) ;
2010-03-13 22:10:45 +01:00
glPushAttrib ( GL_CURRENT_BIT | GL_ENABLE_BIT ) ;
//background
CoreData & coreData = CoreData : : getInstance ( ) ;
2011-03-25 11:11:16 +01:00
Texture2D * backTexture = NULL ;
if ( button - > getUseCustomTexture ( ) = = true ) {
backTexture = dynamic_cast < Texture2D * > ( button - > getCustomTexture ( ) ) ;
}
else {
backTexture = w > 3 * h / 2 ? coreData . getButtonBigTexture ( ) : coreData . getButtonSmallTexture ( ) ;
}
2010-03-13 22:10:45 +01:00
glEnable ( GL_TEXTURE_2D ) ;
glEnable ( GL_BLEND ) ;
2011-03-25 11:11:16 +01:00
if ( backTexture ! = NULL ) {
glBindTexture ( GL_TEXTURE_2D , static_cast < Texture2DGl * > ( backTexture ) - > getHandle ( ) ) ;
}
else {
glBindTexture ( GL_TEXTURE_2D , 0 ) ;
}
2010-03-13 22:10:45 +01:00
//button
2012-06-01 07:26:01 +02:00
Vec4f fontColor ( GraphicComponent : : getCustomTextColor ( ) ) ;
2011-03-04 23:54:04 +01:00
if ( fontColorOverride ! = NULL ) {
fontColor = * fontColorOverride ;
}
else {
2010-08-12 00:31:26 +02:00
// white shadowed is default ( in the menu for example )
2012-06-01 07:26:01 +02:00
fontColor . w = GraphicComponent : : getFade ( ) ;
2011-03-04 23:54:04 +01:00
}
2010-08-12 00:31:26 +02:00
//Vec4f color= Vec4f(1.f, 1.f, 1.f, GraphicComponent::getFade());
Vec4f color = fontColor ;
2010-03-13 22:10:45 +01:00
glColor4fv ( color . ptr ( ) ) ;
glBegin ( GL_TRIANGLE_STRIP ) ;
glTexCoord2f ( 0.f , 0.f ) ;
2010-05-01 22:14:25 +02:00
glVertex2f ( x , y ) ;
2010-03-13 22:10:45 +01:00
glTexCoord2f ( 0.f , 1.f ) ;
2010-05-01 22:14:25 +02:00
glVertex2f ( x , y + h ) ;
2010-03-13 22:10:45 +01:00
glTexCoord2f ( 1.f , 0.f ) ;
2010-05-01 22:14:25 +02:00
glVertex2f ( x + w , y ) ;
2010-03-13 22:10:45 +01:00
glTexCoord2f ( 1.f , 1.f ) ;
2010-05-01 22:14:25 +02:00
glVertex2f ( x + w , y + h ) ;
2010-03-13 22:10:45 +01:00
glEnd ( ) ;
glDisable ( GL_TEXTURE_2D ) ;
//lighting
float anim = GraphicComponent : : getAnim ( ) ;
if ( anim > 0.5f ) anim = 1.f - anim ;
2011-03-25 19:42:08 +01:00
bool renderLighted = ( button - > getLighted ( ) & & button - > getEditable ( ) ) ;
if ( lightedOverride ! = NULL ) {
renderLighted = * lightedOverride ;
}
if ( renderLighted ) {
2010-03-13 22:10:45 +01:00
const int lightSize = 0 ;
2010-08-12 00:31:26 +02:00
const Vec4f color1 = Vec4f ( color . x , color . y , color . z , 0.1f + anim * 0.5f ) ;
const Vec4f color2 = Vec4f ( color . x , color . y , color . z , 0.3f + anim ) ;
2010-03-13 22:10:45 +01:00
glBegin ( GL_TRIANGLE_FAN ) ;
glColor4fv ( color2 . ptr ( ) ) ;
2010-05-01 22:14:25 +02:00
glVertex2f ( x + w / 2 , y + h / 2 ) ;
2010-03-13 22:10:45 +01:00
glColor4fv ( color1 . ptr ( ) ) ;
2010-05-01 22:14:25 +02:00
glVertex2f ( x - lightSize , y - lightSize ) ;
2010-03-13 22:10:45 +01:00
glColor4fv ( color1 . ptr ( ) ) ;
2010-05-01 22:14:25 +02:00
glVertex2f ( x + w + lightSize , y - lightSize ) ;
2010-03-13 22:10:45 +01:00
glColor4fv ( color1 . ptr ( ) ) ;
2010-05-01 22:14:25 +02:00
glVertex2f ( x + w + lightSize , y + h + lightSize ) ;
2010-03-13 22:10:45 +01:00
glColor4fv ( color1 . ptr ( ) ) ;
2010-05-01 22:14:25 +02:00
glVertex2f ( x + w + lightSize , y + h + lightSize ) ;
2010-03-13 22:10:45 +01:00
glColor4fv ( color1 . ptr ( ) ) ;
2010-05-01 22:14:25 +02:00
glVertex2f ( x - lightSize , y + h + lightSize ) ;
2010-03-13 22:10:45 +01:00
glColor4fv ( color1 . ptr ( ) ) ;
2010-05-01 22:14:25 +02:00
glVertex2f ( x - lightSize , y - lightSize ) ;
2010-03-13 22:10:45 +01:00
glEnd ( ) ;
}
2011-06-11 10:52:49 +02:00
//Vec2i textPos= Vec2i(x + w / 2, y + h / 2);
2010-03-13 22:10:45 +01:00
2011-03-25 11:11:16 +01:00
if ( button - > getEditable ( ) ) {
2011-06-10 05:09:19 +02:00
if ( renderText3DEnabled = = true ) {
2011-06-11 10:52:49 +02:00
//renderText3D(button->getText(), button->getFont3D(), color,x + (w / 2), y + (h / 2), true);
2012-07-26 08:27:00 +02:00
renderTextBoundingBox3D ( button - > getText ( ) , button - > getFont3D ( ) ,
2012-07-26 17:26:59 +02:00
color , x , y , w , h , true , true , false , - 1 , - 1 ) ;
2011-06-10 05:09:19 +02:00
}
else {
2011-06-11 10:52:49 +02:00
renderText ( button - > getText ( ) , button - > getFont ( ) , color , x + ( w / 2 ) , y + ( h / 2 ) , true ) ;
2011-06-10 05:09:19 +02:00
}
2010-04-22 01:13:39 +02:00
}
else {
2011-06-10 05:09:19 +02:00
if ( renderText3DEnabled = = true ) {
2011-06-11 10:52:49 +02:00
//renderText3D(button->getText(), button->getFont3D(),disabledTextColor,
// x + (w / 2), y + (h / 2), true);
renderTextBoundingBox3D ( button - > getText ( ) , button - > getFont3D ( ) , disabledTextColor ,
2012-07-26 17:26:59 +02:00
x , y , w , h , true , true , false , - 1 , - 1 ) ;
2011-06-10 05:09:19 +02:00
}
else {
renderText ( button - > getText ( ) , button - > getFont ( ) , disabledTextColor ,
2011-06-11 10:52:49 +02:00
x + ( w / 2 ) , y + ( h / 2 ) , true ) ;
2011-06-10 05:09:19 +02:00
}
2010-04-22 01:13:39 +02:00
}
2010-03-13 22:10:45 +01:00
glPopAttrib ( ) ;
2017-02-04 21:33:18 +01:00
}
catch ( const exception & e ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s Line: %d] \n Error [%s] For Control container [%s] name [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , e . what ( ) , button - > getContainerName ( ) . c_str ( ) , button - > getInstanceName ( ) . c_str ( ) ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , szBuf ) ;
throw megaglest_runtime_error ( szBuf ) ;
}
2010-03-13 22:10:45 +01:00
}
2010-12-27 01:59:57 +01:00
void Renderer : : renderCheckBox ( const GraphicCheckBox * box ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2010-12-27 01:59:57 +01:00
if ( box - > getVisible ( ) = = false ) {
return ;
}
int x = box - > getX ( ) ;
int y = box - > getY ( ) ;
int h = box - > getH ( ) ;
int w = box - > getW ( ) ;
2013-11-19 07:14:06 +01:00
//const Vec3f disabledTextColor= Vec3f(0.25f,0.25f,0.25f);
2010-12-27 01:59:57 +01:00
glPushAttrib ( GL_CURRENT_BIT | GL_ENABLE_BIT ) ;
//background
CoreData & coreData = CoreData : : getInstance ( ) ;
Texture2D * backTexture = box - > getValue ( ) ? coreData . getCheckedCheckBoxTexture ( ) : coreData . getCheckBoxTexture ( ) ;
glEnable ( GL_TEXTURE_2D ) ;
glEnable ( GL_BLEND ) ;
glBindTexture ( GL_TEXTURE_2D , static_cast < Texture2DGl * > ( backTexture ) - > getHandle ( ) ) ;
//box
Vec4f fontColor ;
//if(game!=NULL){
// fontColor=game->getGui()->getDisplay()->getColor();
// fontColor.w = GraphicComponent::getFade();
//}
//else {
// white shadowed is default ( in the menu for example )
fontColor = Vec4f ( 1.f , 1.f , 1.f , GraphicComponent : : getFade ( ) ) ;
//}
//Vec4f color= Vec4f(1.f, 1.f, 1.f, GraphicComponent::getFade());
Vec4f color = fontColor ;
glColor4fv ( color . ptr ( ) ) ;
glBegin ( GL_TRIANGLE_STRIP ) ;
glTexCoord2f ( 0.f , 0.f ) ;
glVertex2f ( x , y ) ;
glTexCoord2f ( 0.f , 1.f ) ;
glVertex2f ( x , y + h ) ;
glTexCoord2f ( 1.f , 0.f ) ;
glVertex2f ( x + w , y ) ;
glTexCoord2f ( 1.f , 1.f ) ;
glVertex2f ( x + w , y + h ) ;
glEnd ( ) ;
glDisable ( GL_TEXTURE_2D ) ;
//lighting
float anim = GraphicComponent : : getAnim ( ) ;
2011-06-12 07:54:54 +02:00
if ( anim > 0.5f ) {
anim = 1.f - anim ;
}
2010-12-27 01:59:57 +01:00
2011-06-12 07:54:54 +02:00
if ( box - > getLighted ( ) & & box - > getEditable ( ) ) {
2010-12-27 01:59:57 +01:00
const int lightSize = 0 ;
const Vec4f color1 = Vec4f ( color . x , color . y , color . z , 0.1f + anim * 0.5f ) ;
const Vec4f color2 = Vec4f ( color . x , color . y , color . z , 0.3f + anim ) ;
glBegin ( GL_TRIANGLE_FAN ) ;
glColor4fv ( color2 . ptr ( ) ) ;
glVertex2f ( x + w / 2 , y + h / 2 ) ;
glColor4fv ( color1 . ptr ( ) ) ;
glVertex2f ( x - lightSize , y - lightSize ) ;
glColor4fv ( color1 . ptr ( ) ) ;
glVertex2f ( x + w + lightSize , y - lightSize ) ;
glColor4fv ( color1 . ptr ( ) ) ;
glVertex2f ( x + w + lightSize , y + h + lightSize ) ;
glColor4fv ( color1 . ptr ( ) ) ;
glVertex2f ( x + w + lightSize , y + h + lightSize ) ;
glColor4fv ( color1 . ptr ( ) ) ;
glVertex2f ( x - lightSize , y + h + lightSize ) ;
glColor4fv ( color1 . ptr ( ) ) ;
glVertex2f ( x - lightSize , y - lightSize ) ;
glEnd ( ) ;
}
glPopAttrib ( ) ;
}
void Renderer : : renderLine ( const GraphicLine * line ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2010-12-27 01:59:57 +01:00
if ( line - > getVisible ( ) = = false ) {
return ;
}
int x = line - > getX ( ) ;
int y = line - > getY ( ) ;
int h = line - > getH ( ) ;
int w = line - > getW ( ) ;
2013-11-19 07:14:06 +01:00
//const Vec3f disabledTextColor= Vec3f(0.25f,0.25f,0.25f);
2010-12-27 01:59:57 +01:00
glPushAttrib ( GL_CURRENT_BIT | GL_ENABLE_BIT ) ;
//background
CoreData & coreData = CoreData : : getInstance ( ) ;
Texture2D * backTexture = line - > getHorizontal ( ) ? coreData . getHorizontalLineTexture ( ) : coreData . getVerticalLineTexture ( ) ;
glEnable ( GL_TEXTURE_2D ) ;
glEnable ( GL_BLEND ) ;
glBindTexture ( GL_TEXTURE_2D , static_cast < Texture2DGl * > ( backTexture ) - > getHandle ( ) ) ;
glBegin ( GL_TRIANGLE_STRIP ) ;
glTexCoord2f ( 0.f , 0.f ) ;
glVertex2f ( x , y ) ;
glTexCoord2f ( 0.f , 1.f ) ;
glVertex2f ( x , y + h ) ;
glTexCoord2f ( 1.f , 0.f ) ;
glVertex2f ( x + w , y ) ;
glTexCoord2f ( 1.f , 1.f ) ;
glVertex2f ( x + w , y + h ) ;
glEnd ( ) ;
glDisable ( GL_TEXTURE_2D ) ;
glPopAttrib ( ) ;
}
2010-12-31 18:16:49 +01:00
void Renderer : : renderScrollBar ( const GraphicScrollBar * sb ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2010-12-31 18:16:49 +01:00
if ( sb - > getVisible ( ) = = false ) {
return ;
}
int x = sb - > getX ( ) ;
int y = sb - > getY ( ) ;
int h = sb - > getH ( ) ;
int w = sb - > getW ( ) ;
2019-10-09 01:45:51 +02:00
// calc real length
if ( sb - > getElementCount ( ) < sb - > getVisibleSize ( ) ) {
int realLength = sb - > getElementCount ( ) * sb - > getLength ( ) / sb - > getVisibleSize ( ) ;
if ( sb - > getHorizontal ( ) ) {
x = x - ( w - realLength ) ;
}
else {
y = y + ( h - realLength ) ;
h = realLength ;
} ;
}
2010-12-31 18:16:49 +01:00
glPushAttrib ( GL_CURRENT_BIT | GL_ENABLE_BIT ) ;
/////////////////////
//background
////////////////////
CoreData & coreData = CoreData : : getInstance ( ) ;
Texture2D * backTexture = coreData . getHorizontalLineTexture ( ) ;
glEnable ( GL_TEXTURE_2D ) ;
glEnable ( GL_BLEND ) ;
2019-10-05 22:41:21 +02:00
Vec4f fontColor ;
fontColor = Vec4f ( 1.f , 1.f , 1.f , GraphicComponent : : getFade ( ) ) ;
Vec4f color = fontColor ;
glColor4fv ( color . ptr ( ) ) ;
2010-12-31 18:16:49 +01:00
glBindTexture ( GL_TEXTURE_2D , static_cast < Texture2DGl * > ( backTexture ) - > getHandle ( ) ) ;
glBegin ( GL_TRIANGLE_STRIP ) ;
glTexCoord2f ( 0.f , 0.f ) ;
glVertex2f ( x , y ) ;
glTexCoord2f ( 0.f , 1.f ) ;
glVertex2f ( x , y + h ) ;
glTexCoord2f ( 1.f , 0.f ) ;
glVertex2f ( x + w , y ) ;
glTexCoord2f ( 1.f , 1.f ) ;
glVertex2f ( x + w , y + h ) ;
glEnd ( ) ;
////////////////////
// selectBlock
////////////////////
2019-10-09 01:45:51 +02:00
if ( sb - > getElementCount ( ) > = sb - > getVisibleSize ( ) ) {
if ( sb - > getHorizontal ( ) ) {
x = x + sb - > getVisibleCompPosStart ( ) ;
w = sb - > getVisibleCompPosEnd ( ) - sb - > getVisibleCompPosStart ( ) ;
} else {
y = y + sb - > getVisibleCompPosStart ( ) ;
h = sb - > getVisibleCompPosEnd ( ) - sb - > getVisibleCompPosStart ( ) ;
}
}
2010-12-31 18:16:49 +01:00
Texture2D * selectTexture = coreData . getButtonBigTexture ( ) ;
2011-10-03 22:48:09 +02:00
assert ( selectTexture ! = NULL ) ;
2010-12-31 18:16:49 +01:00
glBindTexture ( GL_TEXTURE_2D , static_cast < Texture2DGl * > ( selectTexture ) - > getHandle ( ) ) ;
glBegin ( GL_TRIANGLE_STRIP ) ;
glTexCoord2f ( 0.f , 0.f ) ;
glVertex2f ( x , y ) ;
glTexCoord2f ( 0.f , 1.f ) ;
glVertex2f ( x , y + h ) ;
glTexCoord2f ( 1.f , 0.f ) ;
glVertex2f ( x + w , y ) ;
glTexCoord2f ( 1.f , 1.f ) ;
glVertex2f ( x + w , y + h ) ;
glEnd ( ) ;
glDisable ( GL_TEXTURE_2D ) ;
//lighting
float anim = GraphicComponent : : getAnim ( ) ;
if ( anim > 0.5f ) anim = 1.f - anim ;
if ( sb - > getLighted ( ) & & sb - > getEditable ( ) ) {
const int lightSize = 0 ;
const Vec4f color1 = Vec4f ( color . x , color . y , color . z , 0.1f + anim * 0.5f ) ;
const Vec4f color2 = Vec4f ( color . x , color . y , color . z , 0.3f + anim ) ;
glBegin ( GL_TRIANGLE_FAN ) ;
glColor4fv ( color2 . ptr ( ) ) ;
glVertex2f ( x + w / 2 , y + h / 2 ) ;
glColor4fv ( color1 . ptr ( ) ) ;
glVertex2f ( x - lightSize , y - lightSize ) ;
glColor4fv ( color1 . ptr ( ) ) ;
glVertex2f ( x + w + lightSize , y - lightSize ) ;
glColor4fv ( color1 . ptr ( ) ) ;
glVertex2f ( x + w + lightSize , y + h + lightSize ) ;
glColor4fv ( color1 . ptr ( ) ) ;
glVertex2f ( x + w + lightSize , y + h + lightSize ) ;
glColor4fv ( color1 . ptr ( ) ) ;
glVertex2f ( x - lightSize , y + h + lightSize ) ;
glColor4fv ( color1 . ptr ( ) ) ;
glVertex2f ( x - lightSize , y - lightSize ) ;
glEnd ( ) ;
}
glPopAttrib ( ) ;
}
2011-06-06 23:38:25 +02:00
void Renderer : : renderListBox ( GraphicListBox * listBox ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2010-09-11 08:08:50 +02:00
if ( listBox - > getVisible ( ) = = false ) {
return ;
}
2013-10-24 01:11:18 +02:00
//if(listBox->getLeftControlled()==true)
{
int x = listBox - > getX ( ) ;
int y = listBox - > getY ( ) ;
int h = listBox - > getH ( ) ;
int w = listBox - > getW ( ) ;
if ( h > 0 ) {
//background
glPushAttrib ( GL_ENABLE_BIT | GL_CURRENT_BIT ) ;
glEnable ( GL_BLEND ) ;
glColor4f ( 0.0f , 0.0f , 0.0f , 0.6f * listBox - > getFade ( ) ) ;
2010-03-13 22:10:45 +01:00
2013-10-24 01:11:18 +02:00
glBegin ( GL_TRIANGLE_STRIP ) ;
glVertex2i ( x , y ) ;
glVertex2i ( x , y + h ) ;
glVertex2i ( x + w , y ) ;
glVertex2i ( x + w , y + h ) ;
glEnd ( ) ;
glPopAttrib ( ) ;
}
}
2010-03-13 22:10:45 +01:00
renderButton ( listBox - > getButton1 ( ) ) ;
renderButton ( listBox - > getButton2 ( ) ) ;
glPushAttrib ( GL_ENABLE_BIT ) ;
glEnable ( GL_BLEND ) ;
2017-02-04 21:33:18 +01:00
GraphicLabel label ( " ListBox_render_label " , " label " , false ) ;
//label.setInstanceName("ListBox_render_label");
2013-10-24 01:11:18 +02:00
if ( listBox - > getLeftControlled ( ) = = true ) {
label . init ( listBox - > getX ( ) + listBox - > getButton1 ( ) - > getW ( ) + listBox - > getButton2 ( ) - > getW ( ) + 2 , listBox - > getY ( ) , listBox - > getW ( ) , listBox - > getH ( ) , false , listBox - > getTextColor ( ) ) ;
}
else {
label . init ( listBox - > getX ( ) , listBox - > getY ( ) , listBox - > getW ( ) , listBox - > getH ( ) , true , listBox - > getTextColor ( ) ) ;
}
2010-03-13 22:10:45 +01:00
label . setText ( listBox - > getText ( ) ) ;
2013-06-13 03:37:15 +02:00
label . setTextNativeTranslation ( listBox - > getTextNativeTranslation ( ) ) ;
2010-03-13 22:10:45 +01:00
label . setFont ( listBox - > getFont ( ) ) ;
2011-06-28 02:51:13 +02:00
label . setFont3D ( listBox - > getFont3D ( ) ) ;
2010-03-13 22:10:45 +01:00
renderLabel ( & label ) ;
2011-04-13 00:20:41 +02:00
//lighting
bool renderLighted = ( listBox - > getLighted ( ) ) ;
if ( renderLighted ) {
float anim = GraphicComponent : : getAnim ( ) ;
if ( anim > 0.5f ) anim = 1.f - anim ;
Vec3f color = listBox - > getTextColor ( ) ;
int x = listBox - > getX ( ) + listBox - > getButton1 ( ) - > getW ( ) ;
int y = listBox - > getY ( ) ;
int h = listBox - > getH ( ) ;
int w = listBox - > getW ( ) - listBox - > getButton1 ( ) - > getW ( ) - listBox - > getButton2 ( ) - > getW ( ) ;
const int lightSize = 0 ;
const Vec4f color1 = Vec4f ( color . x , color . y , color . z , 0.1f + anim * 0.5f ) ;
const Vec4f color2 = Vec4f ( color . x , color . y , color . z , 0.3f + anim ) ;
glBegin ( GL_TRIANGLE_FAN ) ;
glColor4fv ( color2 . ptr ( ) ) ;
glVertex2f ( x + w / 2 , y + h / 2 ) ;
glColor4fv ( color1 . ptr ( ) ) ;
2019-10-05 22:41:21 +02:00
glVertex2f ( x - lightSize , y - lightSize ) ;
glColor4fv ( color1 . ptr ( ) ) ;
glVertex2f ( x + w + lightSize , y - lightSize ) ;
glColor4fv ( color1 . ptr ( ) ) ;
glVertex2f ( x + w + lightSize , y + h + lightSize ) ;
glColor4fv ( color1 . ptr ( ) ) ;
glVertex2f ( x + w + lightSize , y + h + lightSize ) ;
glColor4fv ( color1 . ptr ( ) ) ;
glVertex2f ( x - lightSize , y + h + lightSize ) ;
glColor4fv ( color1 . ptr ( ) ) ;
glVertex2f ( x - lightSize , y - lightSize ) ;
glEnd ( ) ;
}
glPopAttrib ( ) ;
}
void Renderer : : renderComboBox ( GraphicComboBox * comboBox ) {
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
if ( comboBox - > getVisible ( ) = = false ) {
return ;
}
int x = comboBox - > getX ( ) ;
int y = comboBox - > getY ( ) ;
int h = comboBox - > getH ( ) ;
int w = comboBox - > getW ( ) ;
if ( h > 0 ) {
//background
glPushAttrib ( GL_ENABLE_BIT | GL_CURRENT_BIT ) ;
glEnable ( GL_BLEND ) ;
glColor4f ( 0.0f , 0.0f , 0.0f , 0.6f * comboBox - > getFade ( ) ) ;
glBegin ( GL_TRIANGLE_STRIP ) ;
glVertex2i ( x , y ) ;
glVertex2i ( x , y + h ) ;
glVertex2i ( x + w , y ) ;
glVertex2i ( x + w , y + h ) ;
glEnd ( ) ;
glPopAttrib ( ) ;
}
renderButton ( comboBox - > getButton ( ) ) ;
if ( comboBox - > isDropDownShowing ( ) ) {
renderScrollBar ( comboBox - > getScrollbar ( ) ) ;
if ( comboBox - > getPopupButtons ( ) - > size ( ) ! = 0 ) {
for ( int i = comboBox - > getScrollbar ( ) - > getVisibleStart ( ) ;
i < = comboBox - > getScrollbar ( ) - > getVisibleEnd ( ) ; + + i ) {
renderButton ( ( * comboBox - > getPopupButtons ( ) ) [ i ] ) ;
}
}
}
glPushAttrib ( GL_ENABLE_BIT ) ;
glEnable ( GL_BLEND ) ;
GraphicLabel label ( " ComboBox_render_label " , " label " , false ) ;
//label.setInstanceName("ComboBox_render_label");
label . init ( comboBox - > getX ( ) , comboBox - > getY ( ) , comboBox - > getW ( ) , comboBox - > getH ( ) , true , comboBox - > getTextColor ( ) ) ;
label . setText ( comboBox - > getText ( ) ) ;
label . setTextNativeTranslation ( comboBox - > getTextNativeTranslation ( ) ) ;
label . setFont ( comboBox - > getFont ( ) ) ;
label . setFont3D ( comboBox - > getFont3D ( ) ) ;
renderLabel ( & label ) ;
//lighting
bool renderLighted = ( comboBox - > getLighted ( ) ) ;
if ( renderLighted ) {
float anim = GraphicComponent : : getAnim ( ) ;
if ( anim > 0.5f ) anim = 1.f - anim ;
Vec3f color = comboBox - > getTextColor ( ) ;
int x = comboBox - > getX ( ) + comboBox - > getButton ( ) - > getW ( ) ;
int y = comboBox - > getY ( ) ;
int h = comboBox - > getH ( ) ;
int w = comboBox - > getW ( ) - comboBox - > getButton ( ) - > getW ( ) ;
const int lightSize = 0 ;
const Vec4f color1 = Vec4f ( color . x , color . y , color . z , 0.1f + anim * 0.5f ) ;
const Vec4f color2 = Vec4f ( color . x , color . y , color . z , 0.3f + anim ) ;
glBegin ( GL_TRIANGLE_FAN ) ;
glColor4fv ( color2 . ptr ( ) ) ;
glVertex2f ( x + w / 2 , y + h / 2 ) ;
glColor4fv ( color1 . ptr ( ) ) ;
2011-04-13 00:20:41 +02:00
glVertex2f ( x - lightSize , y - lightSize ) ;
glColor4fv ( color1 . ptr ( ) ) ;
glVertex2f ( x + w + lightSize , y - lightSize ) ;
glColor4fv ( color1 . ptr ( ) ) ;
glVertex2f ( x + w + lightSize , y + h + lightSize ) ;
glColor4fv ( color1 . ptr ( ) ) ;
glVertex2f ( x + w + lightSize , y + h + lightSize ) ;
glColor4fv ( color1 . ptr ( ) ) ;
glVertex2f ( x - lightSize , y + h + lightSize ) ;
glColor4fv ( color1 . ptr ( ) ) ;
glVertex2f ( x - lightSize , y - lightSize ) ;
glEnd ( ) ;
}
2010-03-13 22:10:45 +01:00
glPopAttrib ( ) ;
}
2011-06-06 23:38:25 +02:00
void Renderer : : renderMessageBox ( GraphicMessageBox * messageBox ) {
2014-12-18 01:04:37 +01:00
const int headerHeight = 25 ;
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2012-04-02 03:45:13 +02:00
try {
if ( messageBox - > getVisible ( ) = = false ) {
return ;
}
2010-03-13 22:10:45 +01:00
2012-04-02 03:45:13 +02:00
if ( ( renderText3DEnabled = = false & & messageBox - > getFont ( ) = = NULL ) | |
( renderText3DEnabled = = true & & messageBox - > getFont3D ( ) = = NULL ) ) {
messageBox - > setFont ( CoreData : : getInstance ( ) . getMenuFontNormal ( ) ) ;
messageBox - > setFont3D ( CoreData : : getInstance ( ) . getMenuFontNormal3D ( ) ) ;
}
2012-11-07 22:24:44 +01:00
string wrappedText = messageBox - > getText ( ) ;
2012-11-09 00:54:43 +01:00
if ( messageBox - > getAutoWordWrap ( ) = = true ) {
if ( renderText3DEnabled = = false ) {
wrappedText = messageBox - > getFont ( ) - > getMetrics ( ) - > wordWrapText ( wrappedText , messageBox - > getW ( ) * 0.90 ) ;
}
else {
wrappedText = messageBox - > getFont3D ( ) - > getMetrics ( ) - > wordWrapText ( wrappedText , messageBox - > getW ( ) * 0.90 ) ;
}
2012-11-07 22:24:44 +01:00
}
2012-04-02 03:45:13 +02:00
//background
glPushAttrib ( GL_ENABLE_BIT | GL_CURRENT_BIT ) ;
glEnable ( GL_BLEND ) ;
2010-03-13 22:10:45 +01:00
2012-04-02 03:45:13 +02:00
glColor4f ( 0.0f , 0.0f , 0.0f , 0.8f ) ;
glBegin ( GL_TRIANGLE_STRIP ) ;
2014-12-18 01:04:37 +01:00
glVertex2i ( messageBox - > getX ( ) , messageBox - > getY ( ) + messageBox - > getH ( ) - headerHeight ) ;
2012-04-02 03:45:13 +02:00
glVertex2i ( messageBox - > getX ( ) , messageBox - > getY ( ) ) ;
2014-12-18 01:04:37 +01:00
glVertex2i ( messageBox - > getX ( ) + messageBox - > getW ( ) , messageBox - > getY ( ) + messageBox - > getH ( ) - headerHeight ) ;
2012-04-02 03:45:13 +02:00
glVertex2i ( messageBox - > getX ( ) + messageBox - > getW ( ) , messageBox - > getY ( ) ) ;
glEnd ( ) ;
2010-03-13 22:10:45 +01:00
2012-04-02 03:45:13 +02:00
glColor4f ( 0.0f , 0.0f , 0.0f , 0.8f ) ;
glBegin ( GL_TRIANGLE_STRIP ) ;
glVertex2i ( messageBox - > getX ( ) , messageBox - > getY ( ) + messageBox - > getH ( ) ) ;
2014-12-18 01:04:37 +01:00
glVertex2i ( messageBox - > getX ( ) , messageBox - > getY ( ) + messageBox - > getH ( ) - headerHeight ) ;
2012-04-02 03:45:13 +02:00
glVertex2i ( messageBox - > getX ( ) + messageBox - > getW ( ) , messageBox - > getY ( ) + messageBox - > getH ( ) ) ;
2014-12-18 01:04:37 +01:00
glVertex2i ( messageBox - > getX ( ) + messageBox - > getW ( ) , messageBox - > getY ( ) + messageBox - > getH ( ) - headerHeight ) ;
2012-04-02 03:45:13 +02:00
glEnd ( ) ;
2010-03-13 22:10:45 +01:00
2012-04-02 03:45:13 +02:00
glBegin ( GL_LINE_LOOP ) ;
glColor4f ( 0.5f , 0.5f , 0.5f , 0.25f ) ;
glVertex2i ( messageBox - > getX ( ) , messageBox - > getY ( ) ) ;
2010-03-13 22:10:45 +01:00
2012-04-02 03:45:13 +02:00
glColor4f ( 0.0f , 0.0f , 0.0f , 0.25f ) ;
glVertex2i ( messageBox - > getX ( ) + messageBox - > getW ( ) , messageBox - > getY ( ) ) ;
2010-03-13 22:10:45 +01:00
2012-04-02 03:45:13 +02:00
glColor4f ( 0.5f , 0.5f , 0.5f , 0.25f ) ;
glVertex2i ( messageBox - > getX ( ) + messageBox - > getW ( ) , messageBox - > getY ( ) + messageBox - > getH ( ) ) ;
2010-03-13 22:10:45 +01:00
2012-04-02 03:45:13 +02:00
glColor4f ( 0.25f , 0.25f , 0.25f , 0.25f ) ;
glVertex2i ( messageBox - > getX ( ) , messageBox - > getY ( ) + messageBox - > getH ( ) ) ;
glEnd ( ) ;
2010-03-13 22:10:45 +01:00
2012-04-02 03:45:13 +02:00
glBegin ( GL_LINE_STRIP ) ;
glColor4f ( 1.0f , 1.0f , 1.0f , 0.25f ) ;
2014-12-18 01:04:37 +01:00
glVertex2i ( messageBox - > getX ( ) , messageBox - > getY ( ) + messageBox - > getH ( ) - headerHeight ) ;
2010-03-13 22:10:45 +01:00
2012-04-02 03:45:13 +02:00
glColor4f ( 0.5f , 0.5f , 0.5f , 0.25f ) ;
2014-12-18 01:04:37 +01:00
glVertex2i ( messageBox - > getX ( ) + messageBox - > getW ( ) , messageBox - > getY ( ) + messageBox - > getH ( ) - headerHeight ) ;
2012-04-02 03:45:13 +02:00
glEnd ( ) ;
2010-03-13 22:10:45 +01:00
2012-04-02 03:45:13 +02:00
glPopAttrib ( ) ;
2010-03-13 22:10:45 +01:00
2011-01-09 10:05:34 +01:00
2012-04-02 03:45:13 +02:00
//buttons
for ( int i = 0 ; i < messageBox - > getButtonCount ( ) ; i + + ) {
2010-03-13 22:10:45 +01:00
2012-04-02 03:45:13 +02:00
if ( ( renderText3DEnabled = = false & & messageBox - > getButton ( i ) - > getFont ( ) = = NULL ) | |
( renderText3DEnabled = = true & & messageBox - > getButton ( i ) - > getFont3D ( ) = = NULL ) ) {
messageBox - > getButton ( i ) - > setFont ( CoreData : : getInstance ( ) . getMenuFontNormal ( ) ) ;
messageBox - > getButton ( i ) - > setFont3D ( CoreData : : getInstance ( ) . getMenuFontNormal3D ( ) ) ;
}
renderButton ( messageBox - > getButton ( i ) ) ;
}
Vec4f fontColor ;
//if(game!=NULL){
// fontColor=game->getGui()->getDisplay()->getColor();
//}
//else {
// white shadowed is default ( in the menu for example )
fontColor = Vec4f ( 1.f , 1.f , 1.f , 1.0f ) ;
//}
if ( renderText3DEnabled = = true ) {
//text
renderTextShadow3D (
2012-11-07 22:24:44 +01:00
wrappedText , messageBox - > getFont3D ( ) , fontColor ,
2014-12-18 01:04:37 +01:00
messageBox - > getX ( ) + 15 , messageBox - > getY ( ) + messageBox - > getH ( ) - headerHeight * 2 ,
2012-04-02 03:45:13 +02:00
false ) ;
2010-08-12 00:31:26 +02:00
2012-04-02 03:45:13 +02:00
renderTextShadow3D (
messageBox - > getHeader ( ) , messageBox - > getFont3D ( ) , fontColor ,
2014-12-18 01:04:37 +01:00
messageBox - > getX ( ) + 15 , messageBox - > getY ( ) + messageBox - > getH ( ) - headerHeight + 8 ,
2012-04-02 03:45:13 +02:00
false ) ;
2010-03-13 22:10:45 +01:00
2012-04-02 03:45:13 +02:00
}
else {
//text
renderTextShadow (
2012-11-07 22:24:44 +01:00
wrappedText , messageBox - > getFont ( ) , fontColor ,
2014-12-18 01:04:37 +01:00
messageBox - > getX ( ) + 15 , messageBox - > getY ( ) + messageBox - > getH ( ) - headerHeight * 2 ,
2012-04-02 03:45:13 +02:00
false ) ;
2011-06-10 05:09:19 +02:00
2012-04-02 03:45:13 +02:00
renderTextShadow (
messageBox - > getHeader ( ) , messageBox - > getFont ( ) , fontColor ,
2014-12-18 01:04:37 +01:00
messageBox - > getX ( ) + 15 , messageBox - > getY ( ) + messageBox - > getH ( ) - headerHeight + 8 ,
2012-04-02 03:45:13 +02:00
false ) ;
}
2011-06-10 05:09:19 +02:00
}
2012-04-02 03:45:13 +02:00
catch ( const exception & e ) {
char szBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " In [%s::%s Line: %d] \n Error [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , e . what ( ) ) ;
2012-04-02 03:45:13 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , szBuf ) ;
2011-06-10 05:09:19 +02:00
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( szBuf ) ;
2011-06-10 05:09:19 +02:00
}
2010-03-13 22:10:45 +01:00
}
// ==================== complex rendering ====================
2017-10-10 05:21:14 +02:00
//VisibleQuadContainerVBOCache * Renderer::GetSurfaceVBOs(SurfaceData *cellData) {
// std::map<uint32,VisibleQuadContainerVBOCache >::iterator iterFind = mapSurfaceVBOCache.find(cellData->uniqueId);
// if(iterFind == mapSurfaceVBOCache.end()) {
// Vec2f *texCoords = &cellData->texCoords[0];
// Vec2f *texCoordsSurface = &cellData->texCoordsSurface[0];
// Vec3f *vertices = &cellData->vertices[0];
// Vec3f *normals = &cellData->normals[0];
//
// VisibleQuadContainerVBOCache vboCache;
//
// // Generate And Bind The Vertex Buffer
// glGenBuffersARB( 1, (GLuint*)&vboCache.m_nVBOVertices ); // Get A Valid Name
// glBindBufferARB( GL_ARRAY_BUFFER_ARB, vboCache.m_nVBOVertices ); // Bind The Buffer
// // Load The Data
// glBufferDataARB( GL_ARRAY_BUFFER_ARB, sizeof(Vec3f) * cellData->bufferCount, vertices, GL_STATIC_DRAW_ARB );
// glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
//
// assertGl();
// // Generate And Bind The Texture Coordinate Buffer
// glGenBuffersARB( 1, (GLuint*)&vboCache.m_nVBOFowTexCoords ); // Get A Valid Name
// glBindBufferARB( GL_ARRAY_BUFFER_ARB, vboCache.m_nVBOFowTexCoords ); // Bind The Buffer
// // Load The Data
// glBufferDataARB( GL_ARRAY_BUFFER_ARB, sizeof(Vec2f) * cellData->bufferCount, texCoords, GL_STATIC_DRAW_ARB );
// glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
//
// assertGl();
// // Generate And Bind The Texture Coordinate Buffer
// glGenBuffersARB( 1, (GLuint*)&vboCache.m_nVBOSurfaceTexCoords ); // Get A Valid Name
// glBindBufferARB( GL_ARRAY_BUFFER_ARB, vboCache.m_nVBOSurfaceTexCoords ); // Bind The Buffer
// // Load The Data
// glBufferDataARB( GL_ARRAY_BUFFER_ARB, sizeof(Vec2f) * cellData->bufferCount, texCoordsSurface, GL_STATIC_DRAW_ARB );
// glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
//
// assertGl();
// // Generate And Bind The Normal Buffer
// glGenBuffersARB( 1, (GLuint*)&vboCache.m_nVBONormals ); // Get A Valid Name
// glBindBufferARB( GL_ARRAY_BUFFER_ARB, vboCache.m_nVBONormals ); // Bind The Buffer
// // Load The Data
// glBufferDataARB( GL_ARRAY_BUFFER_ARB, sizeof(Vec3f) * cellData->bufferCount, normals, GL_STATIC_DRAW_ARB );
// glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
//
// vboCache.hasBuiltVBOs = true;
//
// mapSurfaceVBOCache[cellData->uniqueId] = vboCache;
//
// // don't need the data in computer RAM anymore its in the GPU now
// cellData->texCoords.clear();
// cellData->texCoordsSurface.clear();
// cellData->vertices.clear();
// cellData->normals.clear();
// }
//
// return &mapSurfaceVBOCache[cellData->uniqueId];
//}
2011-01-21 23:41:05 +01:00
void Renderer : : ReleaseSurfaceVBOs ( ) {
2011-02-05 06:07:05 +01:00
for ( std : : map < uint32 , VisibleQuadContainerVBOCache > : : iterator iterFind = mapSurfaceVBOCache . begin ( ) ;
2011-01-21 23:41:05 +01:00
iterFind ! = mapSurfaceVBOCache . end ( ) ; + + iterFind ) {
2011-02-05 06:07:05 +01:00
VisibleQuadContainerVBOCache & item = iterFind - > second ;
if ( item . hasBuiltVBOs = = true ) {
2011-10-18 03:13:38 +02:00
glDeleteBuffersARB ( 1 , ( GLuint * ) & item . m_nVBOVertices ) ; // Get A Valid Name
glDeleteBuffersARB ( 1 , ( GLuint * ) & item . m_nVBOFowTexCoords ) ; // Get A Valid Name
glDeleteBuffersARB ( 1 , ( GLuint * ) & item . m_nVBOSurfaceTexCoords ) ; // Get A Valid Name
glDeleteBuffersARB ( 1 , ( GLuint * ) & item . m_nVBONormals ) ; // Get A Valid Name
2011-02-05 06:07:05 +01:00
//glDeleteBuffersARB( 1, &item.m_nVBOIndexes ); // Get A Valid Name
2011-01-21 23:41:05 +01:00
}
}
mapSurfaceVBOCache . clear ( ) ;
}
2011-07-08 18:45:55 +02:00
Renderer : : MapRenderer : : Layer : : ~ Layer ( ) {
if ( vbo_vertices ) glDeleteBuffersARB ( 1 , & vbo_vertices ) ;
if ( vbo_normals ) glDeleteBuffersARB ( 1 , & vbo_normals ) ;
if ( vbo_fowTexCoords ) glDeleteBuffersARB ( 1 , & vbo_fowTexCoords ) ;
if ( vbo_surfTexCoords ) glDeleteBuffersARB ( 1 , & vbo_surfTexCoords ) ;
if ( vbo_indices ) glDeleteBuffersARB ( 1 , & vbo_indices ) ;
}
template < typename T > void _loadVBO ( GLuint & vbo , std : : vector < T > buf , int target = GL_ARRAY_BUFFER_ARB ) {
assert ( buf . size ( ) ) ;
if ( true /* vbo enabled? */ ) {
glGenBuffersARB ( 1 , & vbo ) ;
assert ( vbo ) ;
glBindBufferARB ( target , vbo ) ;
glBufferDataARB ( target , sizeof ( T ) * buf . size ( ) , & buf [ 0 ] , GL_STATIC_DRAW_ARB ) ;
2011-12-30 07:24:59 +01:00
glBindBufferARB ( target , 0 ) ;
2011-07-08 18:45:55 +02:00
assertGl ( ) ;
buf . clear ( ) ;
}
}
2011-07-10 07:42:11 +02:00
void Renderer : : MapRenderer : : Layer : : load_vbos ( bool vboEnabled ) {
2013-11-03 02:51:20 +01:00
indexCount = ( int ) indices . size ( ) ;
2011-07-10 07:42:11 +02:00
if ( vboEnabled ) {
_loadVBO ( vbo_vertices , vertices ) ;
_loadVBO ( vbo_normals , normals ) ;
_loadVBO ( vbo_fowTexCoords , fowTexCoords ) ;
_loadVBO ( vbo_surfTexCoords , surfTexCoords ) ;
_loadVBO ( vbo_indices , indices , GL_ELEMENT_ARRAY_BUFFER_ARB ) ;
}
else {
vbo_vertices = 0 ;
vbo_normals = 0 ;
vbo_fowTexCoords = 0 ;
vbo_surfTexCoords = 0 ;
vbo_indices = 0 ;
}
}
void Renderer : : MapRenderer : : loadVisibleLayers ( float coordStep , VisibleQuadContainerCache & qCache ) {
int totalCellCount = 0 ;
// we create a layer for each visible texture in the map
for ( int visibleIndex = 0 ;
2013-11-19 07:14:06 +01:00
visibleIndex < ( int ) qCache . visibleScaledCellList . size ( ) ; + + visibleIndex ) {
2011-07-10 07:42:11 +02:00
Vec2i & pos = qCache . visibleScaledCellList [ visibleIndex ] ;
totalCellCount + + ;
SurfaceCell * tc00 = map - > getSurfaceCell ( pos . x , pos . y ) ;
SurfaceCell * tc10 = map - > getSurfaceCell ( pos . x + 1 , pos . y ) ;
SurfaceCell * tc01 = map - > getSurfaceCell ( pos . x , pos . y + 1 ) ;
SurfaceCell * tc11 = map - > getSurfaceCell ( pos . x + 1 , pos . y + 1 ) ;
const Vec2f & surfCoord = tc00 - > getSurfTexCoord ( ) ;
SurfaceCell * tc [ 4 ] = {
tc00 ,
tc10 ,
tc01 ,
tc11
} ;
int textureHandle = static_cast < const Texture2DGl * > ( tc [ 0 ] - > getSurfaceTexture ( ) ) - > getHandle ( ) ;
string texturePath = static_cast < const Texture2DGl * > ( tc [ 0 ] - > getSurfaceTexture ( ) ) - > getPath ( ) ;
//int32 textureCRC = CalculatePixelsCRC(static_cast<const Texture2DGl*>(tc[0]->getSurfaceTexture()));
Layer * layer = NULL ;
for ( Layers : : iterator it = layers . begin ( ) ; it ! = layers . end ( ) ; + + it ) {
if ( ( * it ) - > textureHandle = = textureHandle ) {
//if((*it)->texturePath == texturePath) {
//if((*it)->textureCRC == textureCRC) {
layer = * it ;
break ;
}
}
if ( ! layer ) {
layer = new Layer ( textureHandle ) ;
layer - > texturePath = texturePath ;
//layer->textureCRC = textureCRC;
layers . push_back ( layer ) ;
//printf("Ading new unique texture [%s]\n",texturePath.c_str());
}
// we'll be super-lazy and re-emit all four corners just because its easier
int index [ 4 ] ;
int loopIndexes [ 4 ] = { 2 , 0 , 3 , 1 } ;
for ( int i = 0 ; i < 4 ; i + + ) {
2013-11-03 02:51:20 +01:00
index [ i ] = ( int ) layer - > vertices . size ( ) ;
2011-07-10 07:42:11 +02:00
SurfaceCell * corner = tc [ loopIndexes [ i ] ] ;
layer - > vertices . push_back ( corner - > getVertex ( ) ) ;
layer - > normals . push_back ( corner - > getNormal ( ) ) ;
layer - > fowTexCoords . push_back ( corner - > getFowTexCoord ( ) ) ;
}
layer - > surfTexCoords . push_back ( Vec2f ( surfCoord . x , surfCoord . y + coordStep ) ) ;
layer - > surfTexCoords . push_back ( Vec2f ( surfCoord . x , surfCoord . y ) ) ;
layer - > surfTexCoords . push_back ( Vec2f ( surfCoord . x + coordStep , surfCoord . y + coordStep ) ) ;
layer - > surfTexCoords . push_back ( Vec2f ( surfCoord . x + coordStep , surfCoord . y ) ) ;
// and make two triangles (no strip, we may be disjoint)
layer - > indices . push_back ( index [ 0 ] ) ;
layer - > indices . push_back ( index [ 1 ] ) ;
layer - > indices . push_back ( index [ 2 ] ) ;
layer - > indices . push_back ( index [ 1 ] ) ;
layer - > indices . push_back ( index [ 3 ] ) ;
layer - > indices . push_back ( index [ 2 ] ) ;
}
// turn them into vbos (actually this method will just calc the index count)
for ( Layers : : iterator layer = layers . begin ( ) ; layer ! = layers . end ( ) ; + + layer ) {
( * layer ) - > load_vbos ( false ) ;
}
//printf("Total # of layers for this map = %d totalCellCount = %d overall render reduction ratio = %d times\n",layers.size(),totalCellCount,(totalCellCount / layers.size()));
2011-07-08 18:45:55 +02:00
}
void Renderer : : MapRenderer : : load ( float coordStep ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2011-07-10 07:42:11 +02:00
int totalCellCount = 0 ;
2011-07-08 18:45:55 +02:00
// we create a layer for each texture in the map
for ( int y = 0 ; y < map - > getSurfaceH ( ) - 1 ; y + + ) {
for ( int x = 0 ; x < map - > getSurfaceW ( ) - 1 ; x + + ) {
2011-07-10 07:42:11 +02:00
totalCellCount + + ;
2011-07-08 18:45:55 +02:00
SurfaceCell * tc [ 4 ] = {
map - > getSurfaceCell ( x , y ) ,
map - > getSurfaceCell ( x + 1 , y ) ,
map - > getSurfaceCell ( x , y + 1 ) ,
map - > getSurfaceCell ( x + 1 , y + 1 )
} ;
int textureHandle = static_cast < const Texture2DGl * > ( tc [ 0 ] - > getSurfaceTexture ( ) ) - > getHandle ( ) ;
2011-07-10 07:42:11 +02:00
string texturePath = static_cast < const Texture2DGl * > ( tc [ 0 ] - > getSurfaceTexture ( ) ) - > getPath ( ) ;
//int32 textureCRC = CalculatePixelsCRC(static_cast<const Texture2DGl*>(tc[0]->getSurfaceTexture()));
2011-07-08 18:45:55 +02:00
Layer * layer = NULL ;
for ( Layers : : iterator it = layers . begin ( ) ; it ! = layers . end ( ) ; + + it ) {
if ( ( * it ) - > textureHandle = = textureHandle ) {
2011-07-10 07:42:11 +02:00
//if((*it)->texturePath == texturePath) {
//if((*it)->textureCRC == textureCRC) {
2011-07-08 18:45:55 +02:00
layer = * it ;
break ;
}
}
if ( ! layer ) {
layer = new Layer ( textureHandle ) ;
2011-07-10 07:42:11 +02:00
layer - > texturePath = texturePath ;
//layer->textureCRC = textureCRC;
2011-07-08 18:45:55 +02:00
layers . push_back ( layer ) ;
2011-07-10 07:42:11 +02:00
//printf("Ading new unique texture [%s]\n",texturePath.c_str());
2011-07-08 18:45:55 +02:00
}
// we'll be super-lazy and re-emit all four corners just because its easier
int index [ 4 ] ;
int loopIndexes [ 4 ] = { 2 , 0 , 3 , 1 } ;
for ( int i = 0 ; i < 4 ; i + + ) {
2013-11-03 02:51:20 +01:00
index [ i ] = ( int ) layer - > vertices . size ( ) ;
2011-07-08 18:45:55 +02:00
SurfaceCell * corner = tc [ loopIndexes [ i ] ] ;
layer - > vertices . push_back ( corner - > getVertex ( ) ) ;
layer - > normals . push_back ( corner - > getNormal ( ) ) ;
}
// the texture coords are all on the current texture obviously
layer - > fowTexCoords . push_back ( tc [ loopIndexes [ 0 ] ] - > getFowTexCoord ( ) ) ;
layer - > fowTexCoords . push_back ( tc [ loopIndexes [ 1 ] ] - > getFowTexCoord ( ) ) ;
layer - > fowTexCoords . push_back ( tc [ loopIndexes [ 2 ] ] - > getFowTexCoord ( ) ) ;
layer - > fowTexCoords . push_back ( tc [ loopIndexes [ 3 ] ] - > getFowTexCoord ( ) ) ;
layer - > surfTexCoords . push_back ( tc [ 0 ] - > getSurfTexCoord ( ) + Vec2f ( 0 , coordStep ) ) ;
layer - > surfTexCoords . push_back ( tc [ 0 ] - > getSurfTexCoord ( ) + Vec2f ( 0 , 0 ) ) ;
layer - > surfTexCoords . push_back ( tc [ 0 ] - > getSurfTexCoord ( ) + Vec2f ( coordStep , coordStep ) ) ;
layer - > surfTexCoords . push_back ( tc [ 0 ] - > getSurfTexCoord ( ) + Vec2f ( coordStep , 0 ) ) ;
2011-07-10 07:42:11 +02:00
2013-11-03 02:51:20 +01:00
layer - > cellToIndicesMap [ Vec2i ( x , y ) ] = ( int ) layer - > indices . size ( ) ;
2011-07-10 07:42:11 +02:00
2011-07-08 18:45:55 +02:00
// and make two triangles (no strip, we may be disjoint)
layer - > indices . push_back ( index [ 0 ] ) ;
layer - > indices . push_back ( index [ 1 ] ) ;
layer - > indices . push_back ( index [ 2 ] ) ;
layer - > indices . push_back ( index [ 1 ] ) ;
layer - > indices . push_back ( index [ 3 ] ) ;
layer - > indices . push_back ( index [ 2 ] ) ;
}
}
// turn them into vbos
for ( Layers : : iterator layer = layers . begin ( ) ; layer ! = layers . end ( ) ; + + layer ) {
2011-07-10 07:42:11 +02:00
( * layer ) - > load_vbos ( true ) ;
2011-07-08 18:45:55 +02:00
}
2011-07-10 07:42:11 +02:00
//printf("Total # of layers for this map = %d totalCellCount = %d overall render reduction ratio = %d times\n",layers.size(),totalCellCount,(totalCellCount / layers.size()));
2011-07-08 18:45:55 +02:00
}
2013-12-15 07:37:15 +01:00
template < typename T > void * _bindVBO ( GLuint vbo , std : : vector < T > & buf , int target = GL_ARRAY_BUFFER_ARB ) {
2013-12-14 08:04:12 +01:00
void * result = NULL ;
2011-07-08 18:45:55 +02:00
if ( vbo ) {
glBindBuffer ( target , vbo ) ;
}
2013-12-14 08:04:12 +01:00
else {
result = & buf [ 0 ] ;
}
return result ;
2011-07-08 18:45:55 +02:00
}
2011-07-10 07:42:11 +02:00
void Renderer : : MapRenderer : : Layer : : renderVisibleLayer ( ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2011-07-08 18:45:55 +02:00
2011-07-10 07:42:11 +02:00
//glBindTexture(GL_TEXTURE_2D, static_cast<const Texture2DGl*>(fowTex)->getHandle());
2011-07-08 18:45:55 +02:00
glClientActiveTexture ( Renderer : : fowTexUnit ) ;
2011-07-10 07:42:11 +02:00
glEnableClientState ( GL_TEXTURE_COORD_ARRAY ) ;
glTexCoordPointer ( 2 , GL_FLOAT , 0 , & fowTexCoords [ 0 ] ) ;
2011-07-08 18:45:55 +02:00
2011-07-10 07:42:11 +02:00
glBindTexture ( GL_TEXTURE_2D , textureHandle ) ;
2011-07-08 18:45:55 +02:00
glClientActiveTexture ( Renderer : : baseTexUnit ) ;
2011-07-10 07:42:11 +02:00
glEnableClientState ( GL_TEXTURE_COORD_ARRAY ) ;
glTexCoordPointer ( 2 , GL_FLOAT , 0 , & surfTexCoords [ 0 ] ) ;
glVertexPointer ( 3 , GL_FLOAT , 0 , & vertices [ 0 ] ) ;
glNormalPointer ( GL_FLOAT , 0 , & normals [ 0 ] ) ;
//glDrawArrays(GL_TRIANGLE_STRIP, 0, vertices.size());
//unsigned short faceIndices[4] = {0, 1, 2, 3};
//glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_SHORT, &faceIndices[0]);
glDrawElements ( GL_TRIANGLES , indexCount , GL_UNSIGNED_INT , & indices [ 0 ] ) ;
glClientActiveTexture ( Renderer : : fowTexUnit ) ;
glDisableClientState ( GL_TEXTURE_COORD_ARRAY ) ;
glClientActiveTexture ( Renderer : : baseTexUnit ) ;
glDisableClientState ( GL_TEXTURE_COORD_ARRAY ) ;
2011-07-08 18:45:55 +02:00
}
2011-07-10 07:42:11 +02:00
void Renderer : : MapRenderer : : Layer : : render ( VisibleQuadContainerCache & qCache ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2017-10-10 04:09:36 +02:00
// const bool renderOnlyVisibleQuad = true;
//
// if(renderOnlyVisibleQuad == true) {
2011-07-10 07:42:11 +02:00
vector < pair < int , int > > rowsToRender ;
if ( rowsToRenderCache . find ( qCache . lastVisibleQuad ) ! = rowsToRenderCache . end ( ) ) {
rowsToRender = rowsToRenderCache [ qCache . lastVisibleQuad ] ;
}
else {
2011-09-01 01:10:43 +02:00
int startIndex = - 1 ;
int lastValidIndex = - 1 ;
2011-07-10 07:42:11 +02:00
for ( int visibleIndex = 0 ;
2013-11-19 07:14:06 +01:00
visibleIndex < ( int ) qCache . visibleScaledCellList . size ( ) ; + + visibleIndex ) {
2011-07-10 07:42:11 +02:00
Vec2i & pos = qCache . visibleScaledCellList [ visibleIndex ] ;
if ( cellToIndicesMap . find ( pos ) ! = cellToIndicesMap . end ( ) ) {
//printf("Layer Render, visibleindex = %d pos [%s] cellToIndicesMap[pos] = %d lastValidIndex = %d\n",visibleIndex,pos.getString().c_str(),cellToIndicesMap[pos],lastValidIndex);
if ( startIndex < 0 | | cellToIndicesMap [ pos ] = = lastValidIndex + 6 ) {
lastValidIndex = cellToIndicesMap [ pos ] ;
if ( startIndex < 0 ) {
startIndex = lastValidIndex ;
}
}
else if ( startIndex > = 0 ) {
rowsToRender . push_back ( make_pair ( startIndex , lastValidIndex ) ) ;
lastValidIndex = cellToIndicesMap [ pos ] ;
startIndex = lastValidIndex ;
}
}
}
if ( startIndex > = 0 ) {
rowsToRender . push_back ( make_pair ( startIndex , lastValidIndex ) ) ;
}
rowsToRenderCache [ qCache . lastVisibleQuad ] = rowsToRender ;
}
2011-09-01 01:10:43 +02:00
if ( rowsToRender . empty ( ) = = false ) {
2011-07-10 07:42:11 +02:00
//printf("Layer has %d rows in visible quad, visible quad has %d cells\n",rowsToRender.size(),qCache.visibleScaledCellList.size());
glVertexPointer ( 3 , GL_FLOAT , 0 , _bindVBO ( vbo_vertices , vertices ) ) ;
glNormalPointer ( GL_FLOAT , 0 , _bindVBO ( vbo_normals , normals ) ) ;
glClientActiveTexture ( Renderer : : fowTexUnit ) ;
glTexCoordPointer ( 2 , GL_FLOAT , 0 , _bindVBO ( vbo_fowTexCoords , fowTexCoords ) ) ;
glClientActiveTexture ( Renderer : : baseTexUnit ) ;
glBindTexture ( GL_TEXTURE_2D , textureHandle ) ;
glTexCoordPointer ( 2 , GL_FLOAT , 0 , _bindVBO ( vbo_surfTexCoords , surfTexCoords ) ) ;
for ( unsigned int i = 0 ; i < rowsToRender . size ( ) ; + + i ) {
//glDrawElements(GL_TRIANGLES,indexCount,GL_UNSIGNED_INT,_bindVBO(vbo_indices,indices,GL_ELEMENT_ARRAY_BUFFER_ARB));
glDrawRangeElements ( GL_TRIANGLES , rowsToRender [ i ] . first , rowsToRender [ i ] . second , indexCount , GL_UNSIGNED_INT , _bindVBO ( vbo_indices , indices , GL_ELEMENT_ARRAY_BUFFER_ARB ) ) ;
}
}
2017-10-10 04:09:36 +02:00
// }
// else {
// glVertexPointer(3,GL_FLOAT,0,_bindVBO(vbo_vertices,vertices));
// glNormalPointer(GL_FLOAT,0,_bindVBO(vbo_normals,normals));
//
// glClientActiveTexture(Renderer::fowTexUnit);
// glTexCoordPointer(2,GL_FLOAT,0,_bindVBO(vbo_fowTexCoords,fowTexCoords));
//
// glClientActiveTexture(Renderer::baseTexUnit);
// glBindTexture(GL_TEXTURE_2D,textureHandle);
// glTexCoordPointer(2,GL_FLOAT,0,_bindVBO(vbo_surfTexCoords,surfTexCoords));
//
// glDrawElements(GL_TRIANGLES,indexCount,GL_UNSIGNED_INT,_bindVBO(vbo_indices,indices,GL_ELEMENT_ARRAY_BUFFER_ARB));
// }
2011-07-10 07:42:11 +02:00
}
void Renderer : : MapRenderer : : renderVisibleLayers ( const Map * map , float coordStep , VisibleQuadContainerCache & qCache ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2011-07-10 07:42:11 +02:00
if ( map ! = this - > map ) {
//printf("New Map loading\n");
destroy ( ) ; // clear any previous map data
this - > map = map ;
loadVisibleLayers ( coordStep , qCache ) ;
}
else if ( lastVisibleQuad ! = qCache . lastVisibleQuad ) {
//printf("New Visible Quad loading\n");
destroy ( ) ; // clear any previous map data
this - > map = map ;
loadVisibleLayers ( coordStep , qCache ) ;
}
lastVisibleQuad = qCache . lastVisibleQuad ;
//printf("About to render %d layers\n",layers.size());
glClientActiveTexture ( fowTexUnit ) ;
glEnableClientState ( GL_TEXTURE_COORD_ARRAY ) ;
glClientActiveTexture ( baseTexUnit ) ;
glEnableClientState ( GL_TEXTURE_COORD_ARRAY ) ;
glEnableClientState ( GL_VERTEX_ARRAY ) ;
glEnableClientState ( GL_NORMAL_ARRAY ) ;
for ( Layers : : iterator layer = layers . begin ( ) ; layer ! = layers . end ( ) ; + + layer )
( * layer ) - > renderVisibleLayer ( ) ;
glDisableClientState ( GL_VERTEX_ARRAY ) ;
glBindBuffer ( GL_ARRAY_BUFFER_ARB , 0 ) ;
glBindBuffer ( GL_ELEMENT_ARRAY_BUFFER_ARB , 0 ) ;
glDisableClientState ( GL_NORMAL_ARRAY ) ;
glClientActiveTexture ( fowTexUnit ) ;
glBindTexture ( GL_TEXTURE_2D , 0 ) ;
glDisableClientState ( GL_TEXTURE_COORD_ARRAY ) ;
glClientActiveTexture ( baseTexUnit ) ;
glBindTexture ( GL_TEXTURE_2D , 0 ) ;
glDisableClientState ( GL_TEXTURE_COORD_ARRAY ) ;
assertGl ( ) ;
}
void Renderer : : MapRenderer : : render ( const Map * map , float coordStep , VisibleQuadContainerCache & qCache ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2011-07-08 18:45:55 +02:00
if ( map ! = this - > map ) {
destroy ( ) ; // clear any previous map data
this - > map = map ;
load ( coordStep ) ;
}
2011-07-10 07:42:11 +02:00
//printf("About to render %d layers\n",layers.size());
2011-07-08 18:45:55 +02:00
glClientActiveTexture ( fowTexUnit ) ;
glEnableClientState ( GL_TEXTURE_COORD_ARRAY ) ;
glClientActiveTexture ( baseTexUnit ) ;
glEnableClientState ( GL_TEXTURE_COORD_ARRAY ) ;
glEnableClientState ( GL_VERTEX_ARRAY ) ;
glEnableClientState ( GL_NORMAL_ARRAY ) ;
for ( Layers : : iterator layer = layers . begin ( ) ; layer ! = layers . end ( ) ; + + layer )
2011-07-10 07:42:11 +02:00
( * layer ) - > render ( qCache ) ;
2011-07-08 18:45:55 +02:00
glDisableClientState ( GL_VERTEX_ARRAY ) ;
glBindBuffer ( GL_ARRAY_BUFFER_ARB , 0 ) ;
glBindBuffer ( GL_ELEMENT_ARRAY_BUFFER_ARB , 0 ) ;
glDisableClientState ( GL_NORMAL_ARRAY ) ;
glClientActiveTexture ( fowTexUnit ) ;
glBindTexture ( GL_TEXTURE_2D , 0 ) ;
glDisableClientState ( GL_TEXTURE_COORD_ARRAY ) ;
glClientActiveTexture ( baseTexUnit ) ;
glBindTexture ( GL_TEXTURE_2D , 0 ) ;
glDisableClientState ( GL_TEXTURE_COORD_ARRAY ) ;
assertGl ( ) ;
}
void Renderer : : MapRenderer : : destroy ( ) {
2011-09-01 20:08:56 +02:00
while ( layers . empty ( ) = = false ) {
2011-07-08 18:45:55 +02:00
delete layers . back ( ) ;
layers . pop_back ( ) ;
}
map = NULL ;
}
2010-10-04 20:31:17 +02:00
void Renderer : : renderSurface ( const int renderFps ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2011-01-20 16:56:30 +01:00
IF_DEBUG_EDITION (
if ( getDebugRenderer ( ) . willRenderSurface ( ) ) {
getDebugRenderer ( ) . renderSurface ( visibleQuad / Map : : cellScale ) ;
} else {
2010-07-13 07:33:43 +02:00
)
2011-07-08 18:45:55 +02:00
assertGl ( ) ;
2010-03-13 22:10:45 +01:00
const World * world = game - > getWorld ( ) ;
const Map * map = world - > getMap ( ) ;
float coordStep = world - > getTileset ( ) - > getSurfaceAtlas ( ) - > getCoordStep ( ) ;
const Texture2D * fowTex = world - > getMinimap ( ) - > getFowTexture ( ) ;
2012-04-02 03:45:13 +02:00
if ( fowTex = = NULL ) {
return ;
}
2010-03-13 22:10:45 +01:00
glPushAttrib ( GL_LIGHTING_BIT | GL_ENABLE_BIT | GL_FOG_BIT | GL_TEXTURE_BIT ) ;
glEnable ( GL_BLEND ) ;
glEnable ( GL_COLOR_MATERIAL ) ;
glDisable ( GL_ALPHA_TEST ) ;
2010-07-12 08:30:54 +02:00
glEnable ( GL_CULL_FACE ) ;
2010-03-13 22:10:45 +01:00
//fog of war tex unit
glActiveTexture ( fowTexUnit ) ;
glEnable ( GL_TEXTURE_2D ) ;
glBindTexture ( GL_TEXTURE_2D , static_cast < const Texture2DGl * > ( fowTex ) - > getHandle ( ) ) ;
2010-10-27 17:04:47 +02:00
2010-03-13 22:10:45 +01:00
glTexSubImage2D (
GL_TEXTURE_2D , 0 , 0 , 0 ,
2010-11-09 10:06:52 +01:00
fowTex - > getPixmapConst ( ) - > getW ( ) , fowTex - > getPixmapConst ( ) - > getH ( ) ,
GL_ALPHA , GL_UNSIGNED_BYTE , fowTex - > getPixmapConst ( ) - > getPixels ( ) ) ;
2010-03-13 22:10:45 +01:00
2011-01-15 09:45:17 +01:00
if ( shadowsOffDueToMinRender = = false ) {
2010-08-21 20:50:56 +02:00
//shadow texture
2011-01-15 19:56:03 +01:00
if ( shadows = = sProjected | | shadows = = sShadowMapping ) {
2010-08-21 20:50:56 +02:00
glActiveTexture ( shadowTexUnit ) ;
glEnable ( GL_TEXTURE_2D ) ;
2010-03-13 22:10:45 +01:00
2010-08-21 20:50:56 +02:00
glBindTexture ( GL_TEXTURE_2D , shadowMapHandle ) ;
2010-03-13 22:10:45 +01:00
2010-08-21 20:50:56 +02:00
static_cast < ModelRendererGl * > ( modelRenderer ) - > setDuplicateTexCoords ( true ) ;
enableProjectiveTexturing ( ) ;
}
2010-03-13 22:10:45 +01:00
}
2011-07-08 18:45:55 +02:00
const Rect2i mapBounds ( 0 , 0 , map - > getSurfaceW ( ) - 1 , map - > getSurfaceH ( ) - 1 ) ;
2010-03-13 22:10:45 +01:00
glActiveTexture ( baseTexUnit ) ;
2011-01-15 09:45:17 +01:00
VisibleQuadContainerCache & qCache = getQuadCache ( ) ;
2011-07-08 18:45:55 +02:00
bool useVBORendering = getVBOSupported ( ) ;
if ( useVBORendering = = true ) {
2011-07-10 07:42:11 +02:00
VisibleQuadContainerCache & qCache = getQuadCache ( ) ;
//mapRenderer.render(map,coordStep,qCache);
mapRenderer . renderVisibleLayers ( map , coordStep , qCache ) ;
2011-07-08 18:45:55 +02:00
}
2011-09-01 01:10:43 +02:00
else if ( qCache . visibleScaledCellList . empty ( ) = = false ) {
int lastTex = - 1 ;
2013-12-14 08:04:12 +01:00
//int currTex=-1;
2010-09-10 02:28:14 +02:00
2013-12-15 18:19:24 +01:00
//Quad2i snapshotOfvisibleQuad = visibleQuad;
2011-01-25 08:41:12 +01:00
2011-02-06 01:46:40 +01:00
//bool useVertexArrayRendering = getVBOSupported();
2013-12-14 08:04:12 +01:00
//bool useVertexArrayRendering = false;
//if(useVertexArrayRendering == false) {
2011-01-21 23:41:05 +01:00
//printf("\LEGACY qCache.visibleScaledCellList.size() = %d \n",qCache.visibleScaledCellList.size());
2011-02-08 08:35:37 +01:00
Vec2f texCoords [ 4 ] ;
Vec2f texCoordsSurface [ 4 ] ;
Vec3f vertices [ 4 ] ;
Vec3f normals [ 4 ] ;
glEnableClientState ( GL_VERTEX_ARRAY ) ;
glEnableClientState ( GL_NORMAL_ARRAY ) ;
2011-07-10 07:42:11 +02:00
std : : map < int , int > uniqueVisibleTextures ;
for ( int visibleIndex = 0 ;
2013-11-19 07:14:06 +01:00
visibleIndex < ( int ) qCache . visibleScaledCellList . size ( ) ; + + visibleIndex ) {
2011-07-10 07:42:11 +02:00
Vec2i & pos = qCache . visibleScaledCellList [ visibleIndex ] ;
SurfaceCell * tc00 = map - > getSurfaceCell ( pos . x , pos . y ) ;
int cellTex = static_cast < const Texture2DGl * > ( tc00 - > getSurfaceTexture ( ) ) - > getHandle ( ) ;
uniqueVisibleTextures [ cellTex ] + + ;
}
//printf("Current renders = %d possible = %d\n",qCache.visibleScaledCellList.size(),uniqueVisibleTextures.size());
2011-01-20 16:56:30 +01:00
for ( int visibleIndex = 0 ;
2013-11-19 07:14:06 +01:00
visibleIndex < ( int ) qCache . visibleScaledCellList . size ( ) ; + + visibleIndex ) {
2011-01-20 16:56:30 +01:00
Vec2i & pos = qCache . visibleScaledCellList [ visibleIndex ] ;
2010-03-13 22:10:45 +01:00
2011-01-20 16:56:30 +01:00
SurfaceCell * tc00 = map - > getSurfaceCell ( pos . x , pos . y ) ;
SurfaceCell * tc10 = map - > getSurfaceCell ( pos . x + 1 , pos . y ) ;
SurfaceCell * tc01 = map - > getSurfaceCell ( pos . x , pos . y + 1 ) ;
SurfaceCell * tc11 = map - > getSurfaceCell ( pos . x + 1 , pos . y + 1 ) ;
2010-03-13 22:10:45 +01:00
2011-01-20 16:56:30 +01:00
if ( tc00 = = NULL ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " tc00 == NULL " ) ;
2011-01-20 16:56:30 +01:00
}
if ( tc10 = = NULL ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " tc10 == NULL " ) ;
2011-01-20 16:56:30 +01:00
}
if ( tc01 = = NULL ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " tc01 == NULL " ) ;
2011-01-20 16:56:30 +01:00
}
if ( tc11 = = NULL ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " tc11 == NULL " ) ;
2011-01-20 16:56:30 +01:00
}
triangleCount + = 2 ;
pointCount + = 4 ;
//set texture
if ( tc00 - > getSurfaceTexture ( ) = = NULL ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " tc00->getSurfaceTexture() = = NULL " ) ;
2011-01-20 16:56:30 +01:00
}
2013-12-14 08:04:12 +01:00
int currTex = static_cast < const Texture2DGl * > ( tc00 - > getSurfaceTexture ( ) ) - > getHandle ( ) ;
2011-01-20 16:56:30 +01:00
if ( currTex ! = lastTex ) {
lastTex = currTex ;
2011-02-08 08:35:37 +01:00
//glBindTexture(GL_TEXTURE_2D, lastTex);
2011-01-20 16:56:30 +01:00
}
const Vec2f & surfCoord = tc00 - > getSurfTexCoord ( ) ;
2011-02-08 08:35:37 +01:00
texCoords [ 0 ] = tc01 - > getFowTexCoord ( ) ;
texCoordsSurface [ 0 ] = Vec2f ( surfCoord . x , surfCoord . y + coordStep ) ;
vertices [ 0 ] = tc01 - > getVertex ( ) ;
normals [ 0 ] = tc01 - > getNormal ( ) ; ;
texCoords [ 1 ] = tc00 - > getFowTexCoord ( ) ;
texCoordsSurface [ 1 ] = Vec2f ( surfCoord . x , surfCoord . y ) ;
vertices [ 1 ] = tc00 - > getVertex ( ) ;
normals [ 1 ] = tc00 - > getNormal ( ) ;
texCoords [ 2 ] = tc11 - > getFowTexCoord ( ) ;
texCoordsSurface [ 2 ] = Vec2f ( surfCoord . x + coordStep , surfCoord . y + coordStep ) ;
vertices [ 2 ] = tc11 - > getVertex ( ) ;
normals [ 2 ] = tc11 - > getNormal ( ) ;
texCoords [ 3 ] = tc10 - > getFowTexCoord ( ) ;
texCoordsSurface [ 3 ] = Vec2f ( surfCoord . x + coordStep , surfCoord . y ) ;
vertices [ 3 ] = tc10 - > getVertex ( ) ;
normals [ 3 ] = tc10 - > getNormal ( ) ;
//glBindTexture(GL_TEXTURE_2D, static_cast<const Texture2DGl*>(fowTex)->getHandle());
glClientActiveTexture ( fowTexUnit ) ;
glEnableClientState ( GL_TEXTURE_COORD_ARRAY ) ;
glTexCoordPointer ( 2 , GL_FLOAT , 0 , & texCoords [ 0 ] ) ;
glBindTexture ( GL_TEXTURE_2D , lastTex ) ;
glClientActiveTexture ( baseTexUnit ) ;
glEnableClientState ( GL_TEXTURE_COORD_ARRAY ) ;
glTexCoordPointer ( 2 , GL_FLOAT , 0 , & texCoordsSurface [ 0 ] ) ;
glVertexPointer ( 3 , GL_FLOAT , 0 , & vertices [ 0 ] ) ;
glNormalPointer ( GL_FLOAT , 0 , & normals [ 0 ] ) ;
glDrawArrays ( GL_TRIANGLE_STRIP , 0 , 4 ) ;
2011-06-30 20:59:58 +02:00
//unsigned short faceIndices[4] = {0, 1, 2, 3};
//glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_SHORT, &faceIndices[0]);
2011-02-08 08:35:37 +01:00
glClientActiveTexture ( fowTexUnit ) ;
glDisableClientState ( GL_TEXTURE_COORD_ARRAY ) ;
glClientActiveTexture ( baseTexUnit ) ;
glDisableClientState ( GL_TEXTURE_COORD_ARRAY ) ;
/*
2011-01-20 16:56:30 +01:00
glBegin ( GL_TRIANGLE_STRIP ) ;
//draw quad using immediate mode
glMultiTexCoord2fv ( fowTexUnit , tc01 - > getFowTexCoord ( ) . ptr ( ) ) ;
glMultiTexCoord2f ( baseTexUnit , surfCoord . x , surfCoord . y + coordStep ) ;
glNormal3fv ( tc01 - > getNormal ( ) . ptr ( ) ) ;
glVertex3fv ( tc01 - > getVertex ( ) . ptr ( ) ) ;
glMultiTexCoord2fv ( fowTexUnit , tc00 - > getFowTexCoord ( ) . ptr ( ) ) ;
glMultiTexCoord2f ( baseTexUnit , surfCoord . x , surfCoord . y ) ;
glNormal3fv ( tc00 - > getNormal ( ) . ptr ( ) ) ;
glVertex3fv ( tc00 - > getVertex ( ) . ptr ( ) ) ;
glMultiTexCoord2fv ( fowTexUnit , tc11 - > getFowTexCoord ( ) . ptr ( ) ) ;
glMultiTexCoord2f ( baseTexUnit , surfCoord . x + coordStep , surfCoord . y + coordStep ) ;
glNormal3fv ( tc11 - > getNormal ( ) . ptr ( ) ) ;
glVertex3fv ( tc11 - > getVertex ( ) . ptr ( ) ) ;
glMultiTexCoord2fv ( fowTexUnit , tc10 - > getFowTexCoord ( ) . ptr ( ) ) ;
glMultiTexCoord2f ( baseTexUnit , surfCoord . x + coordStep , surfCoord . y ) ;
glNormal3fv ( tc10 - > getNormal ( ) . ptr ( ) ) ;
glVertex3fv ( tc10 - > getVertex ( ) . ptr ( ) ) ;
glEnd ( ) ;
2011-02-08 08:35:37 +01:00
*/
2011-01-15 09:45:17 +01:00
}
2011-02-08 08:35:37 +01:00
glDisableClientState ( GL_NORMAL_ARRAY ) ;
glDisableClientState ( GL_VERTEX_ARRAY ) ;
2013-12-14 08:04:12 +01:00
// }
// else {
// const bool useVBOs = false;
// const bool useSurfaceCache = false;
//
// std::vector<SurfaceData> surfaceData;
// bool recalcSurface = false;
//
// if(useSurfaceCache == true) {
// std::map<string,std::pair<Chrono, std::vector<SurfaceData> > >::iterator iterFind = mapSurfaceData.find(snapshotOfvisibleQuad.getString());
// if(iterFind == mapSurfaceData.end()) {
// recalcSurface = true;
// //printf("#1 Calculating surface for Rendering using VA's [%s]\n",snapshotOfvisibleQuad.getString().c_str());
// }
///*
// else if(iterFind->second.first.getMillis() >= 250) {
// recalcSurface = true;
// mapSurfaceData.erase(snapshotOfvisibleQuad.getString());
// //printf("#2 RE-Calculating surface for Rendering using VA's [%s]\n",snapshotOfvisibleQuad.getString().c_str());
// }
//*/
// }
// else {
// recalcSurface = true;
// }
//
// if(recalcSurface == true) {
// //printf("Calculating surface for Rendering using VA's [%s]\n",snapshotOfvisibleQuad.getString().c_str());
//
// std::vector<SurfaceData> *surface = &surfaceData;
// if(useSurfaceCache == true) {
// std::pair<Chrono, std::vector<SurfaceData> > &surfaceCacheEntity = mapSurfaceData[snapshotOfvisibleQuad.getString()];
// surface = &surfaceCacheEntity.second;
// //surface.reserve(qCache.visibleScaledCellList.size());
// }
// surface->reserve(qCache.visibleScaledCellList.size());
//
// int lastSurfaceDataIndex = -1;
// for(int visibleIndex = 0;
// visibleIndex < (int)qCache.visibleScaledCellList.size(); ++visibleIndex) {
// Vec2i &pos = qCache.visibleScaledCellList[visibleIndex];
//
// SurfaceCell *tc00= map->getSurfaceCell(pos.x, pos.y);
// SurfaceCell *tc10= map->getSurfaceCell(pos.x+1, pos.y);
// SurfaceCell *tc01= map->getSurfaceCell(pos.x, pos.y+1);
// SurfaceCell *tc11= map->getSurfaceCell(pos.x+1, pos.y+1);
//
// if(tc00 == NULL) {
// throw megaglest_runtime_error("tc00 == NULL");
// }
// if(tc10 == NULL) {
// throw megaglest_runtime_error("tc10 == NULL");
// }
// if(tc01 == NULL) {
// throw megaglest_runtime_error("tc01 == NULL");
// }
// if(tc11 == NULL) {
// throw megaglest_runtime_error("tc11 == NULL");
// }
//
// triangleCount+= 2;
// pointCount+= 4;
//
// //set texture
// if(tc00->getSurfaceTexture() == NULL) {
// throw megaglest_runtime_error("tc00->getSurfaceTexture() == NULL");
// }
//
// int surfaceDataIndex = -1;
// currTex= static_cast<const Texture2DGl*>(tc00->getSurfaceTexture())->getHandle();
// if(currTex != lastTex) {
// lastTex = currTex;
// }
// else {
// surfaceDataIndex = lastSurfaceDataIndex;
// }
//
// if(surfaceDataIndex < 0) {
// SurfaceData newData;
// newData.uniqueId = SurfaceData::nextUniqueId;
// SurfaceData::nextUniqueId++;
// newData.bufferCount=0;
// newData.textureHandle = currTex;
// surface->push_back(newData);
//
// surfaceDataIndex = (int)surface->size() - 1;
// }
//
// lastSurfaceDataIndex = surfaceDataIndex;
//
// SurfaceData *cellData = &(*surface)[surfaceDataIndex];
//
// const Vec2f &surfCoord= tc00->getSurfTexCoord();
//
// cellData->texCoords.push_back(tc01->getFowTexCoord());
// cellData->texCoordsSurface.push_back(Vec2f(surfCoord.x, surfCoord.y + coordStep));
// cellData->vertices.push_back(tc01->getVertex());
// cellData->normals.push_back(tc01->getNormal());
// cellData->bufferCount++;
//
// cellData->texCoords.push_back(tc00->getFowTexCoord());
// cellData->texCoordsSurface.push_back(Vec2f(surfCoord.x, surfCoord.y));
// cellData->vertices.push_back(tc00->getVertex());
// cellData->normals.push_back(tc00->getNormal());
// cellData->bufferCount++;
//
// cellData->texCoords.push_back(tc11->getFowTexCoord());
// cellData->texCoordsSurface.push_back(Vec2f(surfCoord.x+coordStep, surfCoord.y+coordStep));
// cellData->vertices.push_back(tc11->getVertex());
// cellData->normals.push_back(tc11->getNormal());
// cellData->bufferCount++;
//
// cellData->texCoords.push_back(tc10->getFowTexCoord());
// cellData->texCoordsSurface.push_back(Vec2f(surfCoord.x+coordStep, surfCoord.y));
// cellData->vertices.push_back(tc10->getVertex());
// cellData->normals.push_back(tc10->getNormal());
// cellData->bufferCount++;
// }
// }
//
// std::vector<SurfaceData> *surface = &surfaceData;
// if(useSurfaceCache == true) {
// std::pair<Chrono, std::vector<SurfaceData> > &surfaceCacheEntity = mapSurfaceData[snapshotOfvisibleQuad.getString()];
// surface = &surfaceCacheEntity.second;
// }
//
// glEnableClientState(GL_VERTEX_ARRAY);
// glEnableClientState(GL_NORMAL_ARRAY);
//
// for(int i = 0; i < (int)surface->size(); ++i) {
// SurfaceData &data = (*surface)[i];
//
// if(useVBOs == true) {
// VisibleQuadContainerVBOCache *vboCache = GetSurfaceVBOs(&data);
//
// //glBindTexture(GL_TEXTURE_2D, static_cast<const Texture2DGl*>(fowTex)->getHandle());
// glClientActiveTexture(fowTexUnit);
// glEnableClientState(GL_TEXTURE_COORD_ARRAY);
//
// glBindBufferARB( GL_ARRAY_BUFFER_ARB, vboCache->m_nVBOFowTexCoords);
// glTexCoordPointer(2, GL_FLOAT, 0,(char *) NULL);
//
// glBindTexture(GL_TEXTURE_2D, data.textureHandle);
// glClientActiveTexture(baseTexUnit);
// glEnableClientState(GL_TEXTURE_COORD_ARRAY);
//
// glBindBufferARB( GL_ARRAY_BUFFER_ARB, vboCache->m_nVBOSurfaceTexCoords);
// glTexCoordPointer(2, GL_FLOAT, 0, (char *) NULL);
//
// glBindBufferARB( GL_ARRAY_BUFFER_ARB, vboCache->m_nVBOVertices);
// glVertexPointer(3, GL_FLOAT, 0, (char *) NULL);
//
// glBindBufferARB( GL_ARRAY_BUFFER_ARB, vboCache->m_nVBONormals);
// glNormalPointer(GL_FLOAT, 0, (char *) NULL);
//
// glDrawArrays(GL_TRIANGLE_STRIP, 0, data.bufferCount);
//
// glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );
//
// glClientActiveTexture(fowTexUnit);
// glDisableClientState(GL_TEXTURE_COORD_ARRAY);
// glClientActiveTexture(baseTexUnit);
// glDisableClientState(GL_TEXTURE_COORD_ARRAY);
//
// }
// else {
// Vec2f *texCoords = &data.texCoords[0];
// Vec2f *texCoordsSurface = &data.texCoordsSurface[0];
// Vec3f *vertices = &data.vertices[0];
// Vec3f *normals = &data.normals[0];
//
// //glBindTexture(GL_TEXTURE_2D, static_cast<const Texture2DGl*>(fowTex)->getHandle());
// glClientActiveTexture(fowTexUnit);
// glEnableClientState(GL_TEXTURE_COORD_ARRAY);
// glTexCoordPointer(2, GL_FLOAT, 0,texCoords);
//
// glBindTexture(GL_TEXTURE_2D, data.textureHandle);
// glClientActiveTexture(baseTexUnit);
// glEnableClientState(GL_TEXTURE_COORD_ARRAY);
// glTexCoordPointer(2, GL_FLOAT, 0, texCoordsSurface);
//
// glVertexPointer(3, GL_FLOAT, 0, vertices);
// glNormalPointer(GL_FLOAT, 0, normals);
//
// glDrawArrays(GL_TRIANGLE_STRIP, 0, data.bufferCount);
//
// glClientActiveTexture(fowTexUnit);
// glDisableClientState(GL_TEXTURE_COORD_ARRAY);
// glClientActiveTexture(baseTexUnit);
// glDisableClientState(GL_TEXTURE_COORD_ARRAY);
// }
// }
//
// glDisableClientState(GL_NORMAL_ARRAY);
// glDisableClientState(GL_VERTEX_ARRAY);
//
// //printf("Surface Render before [%d] after [%d]\n",qCache.visibleScaledCellList.size(),surface.size());
// }
2010-03-13 22:10:45 +01:00
}
//Restore
static_cast < ModelRendererGl * > ( modelRenderer ) - > setDuplicateTexCoords ( false ) ;
2011-07-01 09:46:18 +02:00
glDisable ( GL_TEXTURE_2D ) ;
2010-03-13 22:10:45 +01:00
glPopAttrib ( ) ;
//assert
2013-12-14 08:04:12 +01:00
GLenum glresult = glGetError ( ) ; //remove when first mtex problem solved
if ( glresult ) {
assertGl ( ) ;
}
2010-03-13 22:10:45 +01:00
assertGl ( ) ;
2011-01-20 16:56:30 +01:00
IF_DEBUG_EDITION (
} // end else, if not renderering debug textures instead of regular terrain
getDebugRenderer ( ) . renderEffects ( visibleQuad / Map : : cellScale ) ;
2010-07-13 07:33:43 +02:00
)
2010-03-13 22:10:45 +01:00
}
2010-10-04 20:31:17 +02:00
void Renderer : : renderObjects ( const int renderFps ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2010-06-22 06:09:23 +02:00
const World * world = game - > getWorld ( ) ;
2013-11-19 07:14:06 +01:00
//const Map *map= world->getMap();
2010-06-22 06:09:23 +02:00
2013-05-19 14:30:10 +02:00
Config & config = Config : : getInstance ( ) ;
int tilesetObjectsToAnimate = config . getInt ( " AnimatedTilesetObjects " , " -1 " ) ;
2010-07-07 20:50:55 +02:00
assertGl ( ) ;
2010-03-13 22:10:45 +01:00
2011-11-23 09:00:09 +01:00
const Texture2D * fowTex = world - > getMinimap ( ) - > getFowTexture ( ) ;
const Pixmap2D * fowTexPixmap = fowTex - > getPixmapConst ( ) ;
2012-01-07 21:24:54 +01:00
Vec3f baseFogColor = world - > getTileset ( ) - > getFogColor ( ) * world - > getTimeFlow ( ) - > computeLightColor ( ) ;
2010-05-07 08:46:55 +02:00
2010-09-10 02:28:14 +02:00
bool modelRenderStarted = false ;
2011-01-15 09:45:17 +01:00
VisibleQuadContainerCache & qCache = getQuadCache ( ) ;
2013-05-19 14:30:10 +02:00
// for(int visibleIndex = 0;
// visibleIndex < qCache.visibleObjectList.size(); ++visibleIndex) {
// render from last to first object so animated objects which are on bottom of screen are
// rendered first which looks better for limited number of animated tileset objects
2013-11-03 02:51:20 +01:00
for ( int visibleIndex = ( int ) qCache . visibleObjectList . size ( ) - 1 ;
2013-06-12 02:53:52 +02:00
visibleIndex > = 0 ; - - visibleIndex ) {
2011-01-15 09:45:17 +01:00
Object * o = qCache . visibleObjectList [ visibleIndex ] ;
2010-09-10 02:28:14 +02:00
2011-01-18 08:52:06 +01:00
Model * objModel = o - > getModelPtr ( ) ;
2012-03-27 01:24:29 +02:00
//objModel->updateInterpolationData(o->getAnimProgress(), true);
2013-10-03 02:17:51 +02:00
const Vec3f v = o - > getConstPos ( ) ;
2010-09-10 02:28:14 +02:00
2011-01-15 09:45:17 +01:00
if ( modelRenderStarted = = false ) {
modelRenderStarted = true ;
2010-09-10 02:28:14 +02:00
2011-01-15 09:45:17 +01:00
glPushAttrib ( GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_FOG_BIT | GL_LIGHTING_BIT | GL_TEXTURE_BIT ) ;
2010-09-10 02:28:14 +02:00
2011-11-23 09:00:09 +01:00
if ( shadowsOffDueToMinRender = = false & &
2011-01-15 09:45:17 +01:00
shadows = = sShadowMapping ) {
glActiveTexture ( shadowTexUnit ) ;
glEnable ( GL_TEXTURE_2D ) ;
2010-09-10 02:28:14 +02:00
2011-01-15 09:45:17 +01:00
glBindTexture ( GL_TEXTURE_2D , shadowMapHandle ) ;
2010-09-10 02:28:14 +02:00
2011-01-15 09:45:17 +01:00
static_cast < ModelRendererGl * > ( modelRenderer ) - > setDuplicateTexCoords ( true ) ;
enableProjectiveTexturing ( ) ;
2010-09-10 10:51:32 +02:00
}
2010-09-10 02:28:14 +02:00
2011-01-15 09:45:17 +01:00
glActiveTexture ( baseTexUnit ) ;
glEnable ( GL_COLOR_MATERIAL ) ;
glAlphaFunc ( GL_GREATER , 0.5f ) ;
2010-09-10 02:28:14 +02:00
2013-01-15 04:18:26 +01:00
modelRenderer - > begin ( true , true , false , false ) ;
2010-09-10 10:51:32 +02:00
}
2011-01-15 09:45:17 +01:00
//ambient and diffuse color is taken from cell color
2010-05-08 11:06:30 +02:00
2011-01-15 09:45:17 +01:00
float fowFactor = fowTexPixmap - > getPixelf ( o - > getMapPos ( ) . x / Map : : cellScale , o - > getMapPos ( ) . y / Map : : cellScale ) ;
Vec4f color = Vec4f ( Vec3f ( fowFactor ) , 1.f ) ;
glColor4fv ( color . ptr ( ) ) ;
glMaterialfv ( GL_FRONT_AND_BACK , GL_AMBIENT , ( color * ambFactor ) . ptr ( ) ) ;
glFogfv ( GL_FOG_COLOR , ( baseFogColor * fowFactor ) . ptr ( ) ) ;
2010-08-21 21:15:39 +02:00
2011-01-15 09:45:17 +01:00
glMatrixMode ( GL_MODELVIEW ) ;
glPushMatrix ( ) ;
glTranslatef ( v . x , v . y , v . z ) ;
glRotatef ( o - > getRotation ( ) , 0.f , 1.f , 0.f ) ;
2010-08-21 21:15:39 +02:00
2013-03-14 22:16:16 +01:00
//We use OpenGL Lights so no manual action is needed here. In fact this call did bad things on lighting big rocks for example
// if(o->getRotation() != 0.0) {
// setupLightingForRotatedModel();
// }
2012-08-13 23:46:27 +02:00
2012-03-27 01:24:29 +02:00
//objModel->updateInterpolationData(0.f, true);
2012-10-06 04:10:23 +02:00
//if(this->gameCamera->getPos().dist(o->getPos()) <= SKIP_INTERPOLATION_DISTANCE) {
2013-05-19 14:30:10 +02:00
if ( tilesetObjectsToAnimate = = - 1 ) {
objModel - > updateInterpolationData ( o - > getAnimProgress ( ) , true ) ;
} else if ( tilesetObjectsToAnimate > 0 & & o - > isAnimated ( ) ) {
tilesetObjectsToAnimate - - ;
2012-10-06 04:10:23 +02:00
objModel - > updateInterpolationData ( o - > getAnimProgress ( ) , true ) ;
2013-05-19 14:30:10 +02:00
} else {
objModel - > updateInterpolationData ( 0 , true ) ;
}
// objModel->updateInterpolationData(o->getAnimProgress(), true);
2012-10-06 04:10:23 +02:00
//}
2011-01-15 09:45:17 +01:00
modelRenderer - > render ( objModel ) ;
2010-08-21 20:50:56 +02:00
2011-01-15 09:45:17 +01:00
triangleCount + = objModel - > getTriangleCount ( ) ;
pointCount + = objModel - > getVertexCount ( ) ;
2010-05-08 11:06:30 +02:00
2011-01-15 09:45:17 +01:00
glPopMatrix ( ) ;
}
2010-07-07 20:50:55 +02:00
2011-01-15 09:45:17 +01:00
if ( modelRenderStarted = = true ) {
modelRenderer - > end ( ) ;
glPopAttrib ( ) ;
}
2010-07-07 20:50:55 +02:00
2011-01-15 09:45:17 +01:00
//restore
static_cast < ModelRendererGl * > ( modelRenderer ) - > setDuplicateTexCoords ( true ) ;
2010-08-22 21:49:33 +02:00
assertGl ( ) ;
2010-03-13 22:10:45 +01:00
}
2010-09-10 10:51:32 +02:00
void Renderer : : renderWater ( ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2010-03-13 22:10:45 +01:00
const World * world = game - > getWorld ( ) ;
const Map * map = world - > getMap ( ) ;
2012-04-02 03:45:13 +02:00
const Texture2D * fowTex = world - > getMinimap ( ) - > getFowTexture ( ) ;
if ( fowTex = = NULL ) {
return ;
}
2010-03-13 22:10:45 +01:00
float waterAnim = world - > getWaterEffects ( ) - > getAmin ( ) ;
//assert
assertGl ( ) ;
glPushAttrib ( GL_TEXTURE_BIT | GL_ENABLE_BIT | GL_CURRENT_BIT ) ;
//water texture nit
glDisable ( GL_TEXTURE_2D ) ;
glEnable ( GL_BLEND ) ;
2013-12-22 01:36:54 +01:00
glBlendFunc ( GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA ) ;
2012-05-12 02:01:05 +02:00
if ( textures3D ) {
2010-03-13 22:10:45 +01:00
Texture3D * waterTex = world - > getTileset ( ) - > getWaterTex ( ) ;
2010-09-10 10:51:32 +02:00
if ( waterTex = = NULL ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " waterTex == NULL " ) ;
2010-09-10 10:51:32 +02:00
}
2010-03-13 22:10:45 +01:00
glEnable ( GL_TEXTURE_3D ) ;
glBindTexture ( GL_TEXTURE_3D , static_cast < Texture3DGl * > ( waterTex ) - > getHandle ( ) ) ;
}
else {
glEnable ( GL_COLOR_MATERIAL ) ;
glColor4f ( 0.5f , 0.5f , 1.0f , 0.5f ) ;
glBindTexture ( GL_TEXTURE_3D , 0 ) ;
}
assertGl ( ) ;
//fog of War texture Unit
2012-04-02 03:45:13 +02:00
//const Texture2D *fowTex= world->getMinimap()->getFowTexture();
2010-03-13 22:10:45 +01:00
glActiveTexture ( fowTexUnit ) ;
glEnable ( GL_TEXTURE_2D ) ;
glBindTexture ( GL_TEXTURE_2D , static_cast < const Texture2DGl * > ( fowTex ) - > getHandle ( ) ) ;
glActiveTexture ( baseTexUnit ) ;
assertGl ( ) ;
2012-05-12 02:01:05 +02:00
int thisTeamIndex = world - > getThisTeamIndex ( ) ;
bool cellExplored = world - > showWorldForPlayer ( world - > getThisFactionIndex ( ) ) ;
bool closed = false ;
2010-03-13 22:10:45 +01:00
Rect2i boundingRect = visibleQuad . computeBoundingRect ( ) ;
Rect2i scaledRect = boundingRect / Map : : cellScale ;
scaledRect . clamp ( 0 , 0 , map - > getSurfaceW ( ) - 1 , map - > getSurfaceH ( ) - 1 ) ;
float waterLevel = world - > getMap ( ) - > getWaterLevel ( ) ;
for ( int j = scaledRect . p [ 0 ] . y ; j < scaledRect . p [ 1 ] . y ; + + j ) {
glBegin ( GL_TRIANGLE_STRIP ) ;
for ( int i = scaledRect . p [ 0 ] . x ; i < = scaledRect . p [ 1 ] . x ; + + i ) {
SurfaceCell * tc0 = map - > getSurfaceCell ( i , j ) ;
SurfaceCell * tc1 = map - > getSurfaceCell ( i , j + 1 ) ;
2011-05-18 23:49:11 +02:00
if ( tc0 = = NULL ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " tc0 == NULL " ) ;
2011-05-18 23:49:11 +02:00
}
if ( tc1 = = NULL ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " tc1 == NULL " ) ;
2011-05-18 23:49:11 +02:00
}
2010-03-13 22:10:45 +01:00
2010-12-25 09:14:35 +01:00
if ( cellExplored = = false ) {
cellExplored = ( tc0 - > isExplored ( thisTeamIndex ) | | tc1 - > isExplored ( thisTeamIndex ) ) ;
}
2012-05-12 02:01:05 +02:00
if ( cellExplored = = true & & tc0 - > getNearSubmerged ( ) ) {
2010-03-13 22:10:45 +01:00
glNormal3f ( 0.f , 1.f , 0.f ) ;
closed = false ;
triangleCount + = 2 ;
pointCount + = 2 ;
//vertex 1
glMaterialfv (
GL_FRONT_AND_BACK , GL_AMBIENT_AND_DIFFUSE ,
computeWaterColor ( waterLevel , tc1 - > getHeight ( ) ) . ptr ( ) ) ;
glMultiTexCoord2fv ( GL_TEXTURE1 , tc1 - > getFowTexCoord ( ) . ptr ( ) ) ;
2010-05-01 22:14:25 +02:00
glTexCoord3f ( i , 1.f , waterAnim ) ;
2010-03-13 22:10:45 +01:00
glVertex3f (
static_cast < float > ( i ) * Map : : mapScale ,
waterLevel ,
static_cast < float > ( j + 1 ) * Map : : mapScale ) ;
//vertex 2
glMaterialfv (
GL_FRONT_AND_BACK , GL_AMBIENT_AND_DIFFUSE ,
computeWaterColor ( waterLevel , tc0 - > getHeight ( ) ) . ptr ( ) ) ;
glMultiTexCoord2fv ( GL_TEXTURE1 , tc0 - > getFowTexCoord ( ) . ptr ( ) ) ;
2010-05-01 22:14:25 +02:00
glTexCoord3f ( i , 0.f , waterAnim ) ;
2010-03-13 22:10:45 +01:00
glVertex3f (
static_cast < float > ( i ) * Map : : mapScale ,
waterLevel ,
static_cast < float > ( j ) * Map : : mapScale ) ;
}
else {
2012-05-12 02:01:05 +02:00
if ( closed = = false ) {
2010-03-13 22:10:45 +01:00
pointCount + = 2 ;
//vertex 1
glMaterialfv (
GL_FRONT_AND_BACK , GL_AMBIENT_AND_DIFFUSE ,
computeWaterColor ( waterLevel , tc1 - > getHeight ( ) ) . ptr ( ) ) ;
glMultiTexCoord2fv ( GL_TEXTURE1 , tc1 - > getFowTexCoord ( ) . ptr ( ) ) ;
2010-05-01 22:14:25 +02:00
glTexCoord3f ( i , 1.f , waterAnim ) ;
2010-03-13 22:10:45 +01:00
glVertex3f (
static_cast < float > ( i ) * Map : : mapScale ,
waterLevel ,
static_cast < float > ( j + 1 ) * Map : : mapScale ) ;
//vertex 2
glMaterialfv (
GL_FRONT_AND_BACK , GL_AMBIENT_AND_DIFFUSE ,
computeWaterColor ( waterLevel , tc0 - > getHeight ( ) ) . ptr ( ) ) ;
glMultiTexCoord2fv ( GL_TEXTURE1 , tc0 - > getFowTexCoord ( ) . ptr ( ) ) ;
2010-05-01 22:14:25 +02:00
glTexCoord3f ( i , 0.f , waterAnim ) ;
2010-03-13 22:10:45 +01:00
glVertex3f (
static_cast < float > ( i ) * Map : : mapScale ,
waterLevel ,
static_cast < float > ( j ) * Map : : mapScale ) ;
glEnd ( ) ;
glBegin ( GL_TRIANGLE_STRIP ) ;
closed = true ;
}
}
}
glEnd ( ) ;
}
//restore
glPopAttrib ( ) ;
assertGl ( ) ;
}
2011-07-07 00:02:38 +02:00
void Renderer : : renderTeamColorCircle ( ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2011-07-07 00:02:38 +02:00
VisibleQuadContainerCache & qCache = getQuadCache ( ) ;
2011-09-01 01:10:43 +02:00
if ( qCache . visibleQuadUnitList . empty ( ) = = false ) {
2011-07-07 00:02:38 +02:00
glPushAttrib ( GL_ENABLE_BIT | GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT ) ;
glDisable ( GL_LIGHTING ) ;
glDisable ( GL_TEXTURE_2D ) ;
glDepthFunc ( GL_ALWAYS ) ;
glDisable ( GL_STENCIL_TEST ) ;
glDisable ( GL_CULL_FACE ) ;
glEnable ( GL_BLEND ) ;
glLineWidth ( 2.f ) ;
for ( int visibleUnitIndex = 0 ;
2013-11-19 07:14:06 +01:00
visibleUnitIndex < ( int ) qCache . visibleQuadUnitList . size ( ) ; + + visibleUnitIndex ) {
2011-07-07 00:02:38 +02:00
Unit * unit = qCache . visibleQuadUnitList [ visibleUnitIndex ] ;
2013-10-03 02:17:51 +02:00
Vec3f currVec = unit - > getCurrVectorFlat ( ) ;
2011-07-07 00:02:38 +02:00
Vec3f color = unit - > getFaction ( ) - > getTexture ( ) - > getPixmapConst ( ) - > getPixel3f ( 0 , 0 ) ;
glColor4f ( color . x , color . y , color . z , 0.7f ) ;
renderSelectionCircle ( currVec , unit - > getType ( ) - > getSize ( ) , 0.8f , 0.05f ) ;
}
glPopAttrib ( ) ;
}
}
2012-10-13 09:33:33 +02:00
void Renderer : : renderSpecialHighlightUnits ( std : : map < int , HighlightSpecialUnitInfo > unitHighlightList ) {
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true | | unitHighlightList . empty ( ) = = true ) {
return ;
}
VisibleQuadContainerCache & qCache = getQuadCache ( ) ;
if ( qCache . visibleQuadUnitList . empty ( ) = = false ) {
glPushAttrib ( GL_ENABLE_BIT | GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT ) ;
glDisable ( GL_LIGHTING ) ;
glDisable ( GL_TEXTURE_2D ) ;
glDepthFunc ( GL_ALWAYS ) ;
glDisable ( GL_STENCIL_TEST ) ;
glDisable ( GL_CULL_FACE ) ;
glEnable ( GL_BLEND ) ;
glLineWidth ( 2.f ) ;
for ( int visibleUnitIndex = 0 ;
2013-11-19 07:14:06 +01:00
visibleUnitIndex < ( int ) qCache . visibleQuadUnitList . size ( ) ; + + visibleUnitIndex ) {
2012-10-13 09:33:33 +02:00
Unit * unit = qCache . visibleQuadUnitList [ visibleUnitIndex ] ;
std : : map < int , HighlightSpecialUnitInfo > : : iterator iterFindSpecialUnit = unitHighlightList . find ( unit - > getId ( ) ) ;
if ( iterFindSpecialUnit ! = unitHighlightList . end ( ) ) {
Vec3f color = unit - > getFaction ( ) - > getTexture ( ) - > getPixmapConst ( ) - > getPixel3f ( 0 , 0 ) ;
float radius = 1.0f ;
float thickness = 0.1f ;
float alpha = 0.65f ;
HighlightSpecialUnitInfo & specialInfo = iterFindSpecialUnit - > second ;
if ( specialInfo . color . x > = 0 ) {
color . x = specialInfo . color . x ;
color . y = specialInfo . color . y ;
color . z = specialInfo . color . z ;
}
if ( specialInfo . color . w > = 0 ) {
alpha = specialInfo . color . w ;
}
if ( specialInfo . radius > 0 ) {
radius = specialInfo . radius ;
}
if ( specialInfo . thickness > 0 ) {
thickness = specialInfo . thickness ;
}
glColor4f ( color . x , color . y , color . z , alpha ) ;
2013-10-03 02:17:51 +02:00
Vec3f currVec = unit - > getCurrVectorFlat ( ) ;
2012-10-13 09:33:33 +02:00
renderSelectionCircle ( currVec , unit - > getType ( ) - > getSize ( ) , radius , thickness ) ;
}
}
glPopAttrib ( ) ;
}
}
2011-07-07 00:02:38 +02:00
void Renderer : : renderTeamColorPlane ( ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2011-07-07 00:02:38 +02:00
VisibleQuadContainerCache & qCache = getQuadCache ( ) ;
2011-09-01 01:10:43 +02:00
if ( qCache . visibleQuadUnitList . empty ( ) = = false ) {
2011-07-07 00:02:38 +02:00
glPushAttrib ( GL_ENABLE_BIT ) ;
glDisable ( GL_LIGHTING ) ;
glEnable ( GL_TEXTURE_2D ) ;
glEnable ( GL_BLEND ) ;
glEnable ( GL_COLOR_MATERIAL ) ;
const Texture2D * texture = CoreData : : getInstance ( ) . getTeamColorTexture ( ) ;
for ( int visibleUnitIndex = 0 ;
2013-11-19 07:14:06 +01:00
visibleUnitIndex < ( int ) qCache . visibleQuadUnitList . size ( ) ; + + visibleUnitIndex ) {
2011-07-07 00:02:38 +02:00
Unit * unit = qCache . visibleQuadUnitList [ visibleUnitIndex ] ;
2017-02-06 01:04:20 +01:00
if ( unit - > isAlive ( ) ) {
Vec3f currVec = unit - > getCurrVectorFlat ( ) ;
renderTeamColorEffect ( currVec , visibleUnitIndex , unit - > getType ( ) - > getSize ( ) ,
unit - > getFaction ( ) - > getTexture ( ) - > getPixmapConst ( ) - > getPixel3f ( 0 , 0 ) , texture ) ;
}
2011-07-07 00:02:38 +02:00
}
glDisable ( GL_COLOR_MATERIAL ) ;
glPopAttrib ( ) ;
}
}
2012-06-22 15:30:15 +02:00
void Renderer : : renderGhostModel ( const UnitType * building , const Vec2i pos , CardinalDir facing , Vec4f * forceColor ) {
2012-06-22 06:58:44 +02:00
//const UnitType *building= gui->getBuilding();
//const Vec2i &pos= gui->getPosObjWorld();
2012-09-22 22:37:42 +02:00
//const Gui *gui= game->getGui();
2012-06-22 06:58:44 +02:00
//const Mouse3d *mouse3d= gui->getMouse3d();
const Map * map = game - > getWorld ( ) - > getMap ( ) ;
if ( map = = NULL ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s] Line: %d map == NULL " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2012-06-22 06:58:44 +02:00
throw megaglest_runtime_error ( szBuf ) ;
}
glPushMatrix ( ) ;
Vec3f pos3f = Vec3f ( pos . x , map - > getCell ( pos ) - > getHeight ( ) , pos . y ) ;
2011-07-07 00:02:38 +02:00
2012-06-22 06:58:44 +02:00
//selection building placement
float offset = building - > getSize ( ) / 2.f - 0.5f ;
glTranslatef ( pos3f . x + offset , pos3f . y , pos3f . z + offset ) ;
//choose color
Vec4f color ;
if ( forceColor ! = NULL ) {
color = * forceColor ;
}
else {
if ( map - > isFreeCells ( pos , building - > getSize ( ) , fLand ) ) {
color = Vec4f ( 1.f , 1.f , 1.f , 0.5f ) ;
}
else {
2012-07-14 23:29:15 +02:00
// Uint64 tc=game->getTickCount();
// float red=0.49f+((tc%4*1.0f)/2);
color = Vec4f ( 1.0f , 0.f , 0.f , 0.5f ) ;
2012-06-22 06:58:44 +02:00
}
}
glColor4fv ( color . ptr ( ) ) ;
glMaterialfv ( GL_FRONT_AND_BACK , GL_AMBIENT , color . ptr ( ) ) ;
Model * buildingModel = building - > getFirstStOfClass ( scStop ) - > getAnimation ( ) ;
2012-06-22 15:30:15 +02:00
if ( facing ! = CardinalDir : : NORTH ) {
float rotateAmount = facing * 90.f ;
2012-06-22 06:58:44 +02:00
if ( rotateAmount > 0 ) {
glRotatef ( rotateAmount , 0.f , 1.f , 0.f ) ;
}
}
buildingModel - > updateInterpolationData ( 0.f , false ) ;
modelRenderer - > render ( buildingModel ) ;
glPopMatrix ( ) ;
}
2011-07-07 00:02:38 +02:00
2013-12-22 01:36:54 +01:00
void Renderer : : renderUnits ( bool airUnits , const int renderFps ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2011-09-01 01:10:43 +02:00
//Unit *unit=NULL;
//const World *world= game->getWorld();
2010-03-13 22:10:45 +01:00
MeshCallbackTeamColor meshCallbackTeamColor ;
//assert
assertGl ( ) ;
2011-04-18 18:51:30 +02:00
if ( visibleFrameUnitList . empty ( ) = = false ) {
visibleFrameUnitList . clear ( ) ;
//visibleFrameUnitListCameraKey = "";
//if(visibleFrameUnitListCameraKey != game->getGameCamera()->getCameraMovementKey()) {
// worldToScreenPosCache.clear();
//}
}
2010-09-01 01:14:15 +02:00
2011-01-15 09:45:17 +01:00
VisibleQuadContainerCache & qCache = getQuadCache ( ) ;
2011-09-01 01:10:43 +02:00
if ( qCache . visibleQuadUnitList . empty ( ) = = false ) {
2012-10-06 09:06:40 +02:00
bool modelRenderStarted = false ;
2011-01-15 09:45:17 +01:00
for ( int visibleUnitIndex = 0 ;
2013-11-19 07:14:06 +01:00
visibleUnitIndex < ( int ) qCache . visibleQuadUnitList . size ( ) ; + + visibleUnitIndex ) {
2011-01-15 09:45:17 +01:00
Unit * unit = qCache . visibleQuadUnitList [ visibleUnitIndex ] ;
2010-03-13 22:10:45 +01:00
2013-12-22 01:36:54 +01:00
if ( ( airUnits = = false & & unit - > getType ( ) - > getField ( ) = = fAir ) | | ( airUnits = = true & & unit - > getType ( ) - > getField ( ) ! = fAir ) ) {
continue ;
}
2011-01-15 09:45:17 +01:00
meshCallbackTeamColor . setTeamTexture ( unit - > getFaction ( ) - > getTexture ( ) ) ;
2010-07-07 20:50:55 +02:00
2011-01-15 09:45:17 +01:00
if ( modelRenderStarted = = false ) {
modelRenderStarted = true ;
2010-08-21 21:15:39 +02:00
2011-01-15 09:45:17 +01:00
glPushAttrib ( GL_ENABLE_BIT | GL_FOG_BIT | GL_LIGHTING_BIT | GL_TEXTURE_BIT ) ;
glEnable ( GL_COLOR_MATERIAL ) ;
2010-08-21 21:15:39 +02:00
2011-01-15 09:45:17 +01:00
if ( ! shadowsOffDueToMinRender ) {
if ( shadows = = sShadowMapping ) {
glActiveTexture ( shadowTexUnit ) ;
glEnable ( GL_TEXTURE_2D ) ;
2010-08-21 21:15:39 +02:00
2011-01-15 09:45:17 +01:00
glBindTexture ( GL_TEXTURE_2D , shadowMapHandle ) ;
2010-08-21 21:15:39 +02:00
2011-01-15 09:45:17 +01:00
static_cast < ModelRendererGl * > ( modelRenderer ) - > setDuplicateTexCoords ( true ) ;
enableProjectiveTexturing ( ) ;
2010-08-21 21:15:39 +02:00
}
2010-07-07 20:50:55 +02:00
}
2011-01-15 09:45:17 +01:00
glActiveTexture ( baseTexUnit ) ;
2010-07-07 20:50:55 +02:00
2013-01-15 04:18:26 +01:00
modelRenderer - > begin ( true , true , true , false , & meshCallbackTeamColor ) ;
2011-01-15 09:45:17 +01:00
}
2010-07-07 20:50:55 +02:00
2011-01-15 09:45:17 +01:00
glMatrixMode ( GL_MODELVIEW ) ;
glPushMatrix ( ) ;
2010-07-07 20:50:55 +02:00
2011-01-15 09:45:17 +01:00
//translate
2013-10-03 02:17:51 +02:00
Vec3f currVec = unit - > getCurrVectorFlat ( ) ;
2011-01-15 09:45:17 +01:00
glTranslatef ( currVec . x , currVec . y , currVec . z ) ;
//rotate
2011-07-12 01:59:16 +02:00
float zrot = unit - > getRotationZ ( ) ;
float xrot = unit - > getRotationX ( ) ;
if ( zrot ! = .0f ) {
glRotatef ( zrot , 0.f , 0.f , 1.f ) ;
}
if ( xrot ! = .0f ) {
glRotatef ( xrot , 1.f , 0.f , 0.f ) ;
}
2011-01-15 09:45:17 +01:00
glRotatef ( unit - > getRotation ( ) , 0.f , 1.f , 0.f ) ;
//dead alpha
const SkillType * st = unit - > getCurrSkill ( ) ;
if ( st - > getClass ( ) = = scDie & & static_cast < const DieSkillType * > ( st ) - > getFade ( ) ) {
2013-05-31 09:09:25 +02:00
float alpha = 1.0f - unit - > getAnimProgressAsFloat ( ) ;
2011-01-15 09:45:17 +01:00
glDisable ( GL_COLOR_MATERIAL ) ;
glMaterialfv ( GL_FRONT_AND_BACK , GL_AMBIENT_AND_DIFFUSE , Vec4f ( 1.0f , 1.0f , 1.0f , alpha ) . ptr ( ) ) ;
2010-03-13 22:10:45 +01:00
}
2011-01-15 09:45:17 +01:00
else {
2013-12-18 21:35:04 +01:00
glEnable ( GL_COLOR_MATERIAL ) ;
2013-12-22 01:36:54 +01:00
// we cut off a tiny bit here to avoid problems with fully transparent texture parts cutting units in background rendered later.
glAlphaFunc ( GL_GREATER , 0.02f ) ;
2010-03-13 22:10:45 +01:00
}
2010-05-10 19:50:57 +02:00
2011-01-15 09:45:17 +01:00
//render
2011-01-18 08:52:06 +01:00
Model * model = unit - > getCurrentModelPtr ( ) ;
2012-10-06 04:10:23 +02:00
//printf("Rendering model [%d - %s]\n[%s]\nCamera [%s]\nDistance: %f\n",unit->getId(),unit->getType()->getName().c_str(),unit->getCurrVector().getString().c_str(),this->gameCamera->getPos().getString().c_str(),this->gameCamera->getPos().dist(unit->getCurrVector()));
//if(this->gameCamera->getPos().dist(unit->getCurrVector()) <= SKIP_INTERPOLATION_DISTANCE) {
2013-05-31 09:09:25 +02:00
model - > updateInterpolationData ( unit - > getAnimProgressAsFloat ( ) , unit - > isAlive ( ) & & ! unit - > isAnimProgressBound ( ) ) ;
2012-10-06 04:10:23 +02:00
//}
2010-05-10 19:50:57 +02:00
2011-01-15 09:45:17 +01:00
modelRenderer - > render ( model ) ;
triangleCount + = model - > getTriangleCount ( ) ;
pointCount + = model - > getVertexCount ( ) ;
2010-05-10 19:50:57 +02:00
2011-01-15 09:45:17 +01:00
glPopMatrix ( ) ;
unit - > setVisible ( true ) ;
2011-11-15 05:48:57 +01:00
2011-04-18 18:51:30 +02:00
if ( showDebugUI = = true & &
( showDebugUILevel & debugui_unit_titles ) = = debugui_unit_titles ) {
2011-11-15 05:48:57 +01:00
unit - > setScreenPos ( computeScreenPosition ( currVec ) ) ;
2011-04-18 18:51:30 +02:00
visibleFrameUnitList . push_back ( unit ) ;
visibleFrameUnitListCameraKey = game - > getGameCamera ( ) - > getCameraMovementKey ( ) ;
}
2010-09-10 10:51:32 +02:00
}
2011-01-15 09:45:17 +01:00
2010-09-10 10:51:32 +02:00
if ( modelRenderStarted = = true ) {
modelRenderer - > end ( ) ;
glPopAttrib ( ) ;
}
2010-05-10 19:50:57 +02:00
}
2011-01-15 09:45:17 +01:00
//restore
static_cast < ModelRendererGl * > ( modelRenderer ) - > setDuplicateTexCoords ( true ) ;
2010-09-26 01:03:27 +02:00
// reset alpha
glAlphaFunc ( GL_GREATER , 0.0f ) ;
2010-09-10 10:51:32 +02:00
//assert
assertGl ( ) ;
2011-07-07 00:02:38 +02:00
2010-05-10 19:50:57 +02:00
}
2012-06-22 06:58:44 +02:00
void Renderer : : renderUnitsToBuild ( const int renderFps ) {
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
//assert
assertGl ( ) ;
VisibleQuadContainerCache & qCache = getQuadCache ( ) ;
if ( qCache . visibleQuadUnitBuildList . empty ( ) = = false ) {
glMatrixMode ( GL_MODELVIEW ) ;
glPushAttrib ( GL_CURRENT_BIT | GL_LIGHTING_BIT | GL_ENABLE_BIT | GL_DEPTH_BUFFER_BIT ) ;
glEnable ( GL_BLEND ) ;
glDisable ( GL_STENCIL_TEST ) ;
glDepthFunc ( GL_LESS ) ;
glEnable ( GL_COLOR_MATERIAL ) ;
glDepthMask ( GL_FALSE ) ;
2013-01-15 04:18:26 +01:00
modelRenderer - > begin ( true , true , false , false ) ;
2012-06-22 06:58:44 +02:00
for ( int visibleUnitIndex = 0 ;
2013-11-19 07:14:06 +01:00
visibleUnitIndex < ( int ) qCache . visibleQuadUnitBuildList . size ( ) ; + + visibleUnitIndex ) {
2012-06-22 15:30:15 +02:00
const UnitBuildInfo & buildUnit = qCache . visibleQuadUnitBuildList [ visibleUnitIndex ] ;
//Vec4f modelColor= Vec4f(0.f, 1.f, 0.f, 0.5f);
const Vec3f teamColor = buildUnit . unit - > getFaction ( ) - > getTexture ( ) - > getPixmapConst ( ) - > getPixel3f ( 0 , 0 ) ;
2012-07-14 01:19:53 +02:00
Vec4f modelColor = Vec4f ( teamColor . x , teamColor . y , teamColor . z , 0.4f ) ;
2012-06-22 15:30:15 +02:00
renderGhostModel ( buildUnit . buildUnit , buildUnit . pos , buildUnit . facing , & modelColor ) ;
2012-06-22 06:58:44 +02:00
//printf("Rendering to build unit index = %d\n",visibleUnitIndex);
}
modelRenderer - > end ( ) ;
glDisable ( GL_COLOR_MATERIAL ) ;
glPopAttrib ( ) ;
}
//assert
assertGl ( ) ;
}
2011-07-07 00:02:38 +02:00
void Renderer : : renderTeamColorEffect ( Vec3f & v , int heigth , int size , Vec3f color , const Texture2D * texture ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2011-09-01 01:10:43 +02:00
//GLUquadricObj *disc;
2011-07-07 00:02:38 +02:00
float halfSize = size ;
2011-09-01 01:10:43 +02:00
//halfSize=halfSize;
2011-07-07 00:02:38 +02:00
float heigthoffset = 0.5 + heigth % 25 * 0.004 ;
glPushMatrix ( ) ;
glBindTexture ( GL_TEXTURE_2D , static_cast < const Texture2DGl * > ( texture ) - > getHandle ( ) ) ;
glColor4f ( color . x , color . y , color . z , 1.0f ) ;
glBegin ( GL_TRIANGLE_STRIP ) ;
glTexCoord2i ( 0 , 1 ) ;
glVertex3f ( v . x - halfSize , v . y + heigthoffset , v . z + halfSize ) ;
glTexCoord2i ( 0 , 0 ) ;
glVertex3f ( v . x - halfSize , v . y + heigthoffset , v . z - halfSize ) ;
glTexCoord2i ( 1 , 1 ) ;
glVertex3f ( v . x + halfSize , v . y + heigthoffset , v . z + halfSize ) ;
glTexCoord2i ( 1 , 0 ) ;
glVertex3f ( v . x + halfSize , v . y + heigthoffset , v . z - halfSize ) ;
glEnd ( ) ;
glPopMatrix ( ) ;
}
2012-09-11 23:16:24 +02:00
void Renderer : : renderMorphEffects ( ) {
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
VisibleQuadContainerCache & qCache = getQuadCache ( ) ;
if ( qCache . visibleQuadUnitList . empty ( ) = = false ) {
bool initialized = false ;
2012-09-12 00:16:44 +02:00
int frameCycle = 0 ;
2012-09-11 23:16:24 +02:00
for ( int visibleUnitIndex = 0 ;
2013-11-19 07:14:06 +01:00
visibleUnitIndex < ( int ) qCache . visibleQuadUnitList . size ( ) ; + + visibleUnitIndex ) {
2012-09-11 23:16:24 +02:00
Unit * unit = qCache . visibleQuadUnitList [ visibleUnitIndex ] ;
if ( unit - > getCurrSkill ( ) ! = NULL & & unit - > getCurrSkill ( ) - > getClass ( ) = = scMorph ) {
Command * command = unit - > getCurrCommand ( ) ;
if ( command ! = NULL & & command - > getCommandType ( ) - > commandTypeClass = = ccMorph ) {
const MorphCommandType * mct = static_cast < const MorphCommandType * > ( command - > getCommandType ( ) ) ;
const UnitType * mType = mct - > getMorphUnit ( ) ;
2012-09-12 00:50:59 +02:00
if ( mType - > getSize ( ) > unit - > getType ( ) - > getSize ( ) | |
mType - > getField ( ) ! = unit - > getType ( ) - > getField ( ) ) {
if ( ! initialized ) {
const World * world = game - > getWorld ( ) ;
frameCycle = world - > getFrameCount ( ) % 40 ;
glPushAttrib ( GL_ENABLE_BIT | GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT ) ;
glDisable ( GL_LIGHTING ) ;
glDisable ( GL_TEXTURE_2D ) ;
glDepthFunc ( GL_ALWAYS ) ;
glDisable ( GL_STENCIL_TEST ) ;
glDisable ( GL_CULL_FACE ) ;
glEnable ( GL_BLEND ) ;
glLineWidth ( 2.f ) ;
initialized = true ;
}
2012-09-11 23:16:24 +02:00
2013-10-03 02:17:51 +02:00
Vec3f currVec = unit - > getCurrVectorFlat ( ) ;
2012-09-12 00:50:59 +02:00
currVec = Vec3f ( currVec . x , currVec . y + 0.3f , currVec . z ) ;
if ( mType - > getField ( ) = = fAir & & unit - > getType ( ) - > getField ( ) = = fLand ) {
2013-06-13 09:34:32 +02:00
currVec = Vec3f ( currVec . x , currVec . y + game - > getWorld ( ) - > getTileset ( ) - > getAirHeight ( ) , currVec . z ) ;
2012-09-12 00:50:59 +02:00
}
if ( mType - > getField ( ) = = fLand & & unit - > getType ( ) - > getField ( ) = = fAir ) {
2013-06-13 09:34:32 +02:00
currVec = Vec3f ( currVec . x , currVec . y - game - > getWorld ( ) - > getTileset ( ) - > getAirHeight ( ) , currVec . z ) ;
2012-09-12 00:50:59 +02:00
}
2012-09-12 00:16:44 +02:00
2012-09-12 00:50:59 +02:00
float color = frameCycle * 0.4f / 40 ;
glColor4f ( color , color , 0.4f , 0.4f ) ;
renderSelectionCircle ( currVec , mType - > getSize ( ) , frameCycle * 0.85f / 40 , 0.2f ) ;
}
2012-09-11 23:16:24 +02:00
}
}
}
if ( initialized ) {
glPopAttrib ( ) ;
}
}
}
2011-07-07 00:02:38 +02:00
2014-11-22 23:15:19 +01:00
void Renderer : : renderSelectionEffects ( int healthbarMode ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2010-03-13 22:10:45 +01:00
2012-02-03 07:16:50 +01:00
Config & config = Config : : getInstance ( ) ;
if ( config . getBool ( " RecordMode " , " false " ) = = true ) {
return ;
}
2010-03-13 22:10:45 +01:00
const World * world = game - > getWorld ( ) ;
const Map * map = world - > getMap ( ) ;
const Selection * selection = game - > getGui ( ) - > getSelection ( ) ;
2011-02-13 22:04:30 +01:00
const Object * selectedResourceObject = game - > getGui ( ) - > getSelectedResourceObject ( ) ;
2010-03-13 22:10:45 +01:00
glPushAttrib ( GL_ENABLE_BIT | GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT ) ;
glDisable ( GL_LIGHTING ) ;
glDisable ( GL_TEXTURE_2D ) ;
glDepthFunc ( GL_ALWAYS ) ;
glDisable ( GL_STENCIL_TEST ) ;
glDisable ( GL_CULL_FACE ) ;
glEnable ( GL_BLEND ) ;
glLineWidth ( 2.f ) ;
//units
for ( int i = 0 ; i < selection - > getCount ( ) ; + + i ) {
const Unit * unit = selection - > getUnit ( i ) ;
2012-11-15 00:42:12 +01:00
if ( unit ! = NULL ) {
//translate
2013-10-03 02:17:51 +02:00
Vec3f currVec = unit - > getCurrVectorFlat ( ) ;
2012-11-15 00:42:12 +01:00
currVec . y + = 0.3f ;
//selection circle
2014-11-29 05:49:04 +01:00
int finalHealthbarMode = hbvUndefined ;
if ( healthbarMode = = hbvUndefined ) {
finalHealthbarMode = unit - > getFaction ( ) - > getType ( ) - > getHealthbarVisible ( ) ;
2014-11-22 23:15:19 +01:00
}
2014-11-29 05:49:04 +01:00
else {
finalHealthbarMode = healthbarMode ;
}
bool healthbarsVisible = ( ( finalHealthbarMode & hbvAlways ) | |
( finalHealthbarMode & hbvSelected ) | |
( finalHealthbarMode & hbvIfNeeded ) ) ;
float selectionCircleThickness = 0.2f ;
float hpRatio = unit - > getHpRatio ( ) ;
2014-11-22 23:15:19 +01:00
if ( healthbarsVisible ) {
2014-11-29 05:49:04 +01:00
selectionCircleThickness = 0.05f ;
hpRatio = 1.0f ;
2014-11-22 23:15:19 +01:00
}
2012-11-15 00:42:12 +01:00
if ( world - > getThisFactionIndex ( ) = = unit - > getFactionIndex ( ) ) {
if ( showDebugUI = = true & &
( ( showDebugUILevel & debugui_unit_titles ) = = debugui_unit_titles ) & &
unit - > getCommandSize ( ) > 0 & &
dynamic_cast < const BuildCommandType * > ( unit - > getCurrCommand ( ) - > getCommandType ( ) ) ! = NULL ) {
2014-11-22 23:15:19 +01:00
glColor4f ( hpRatio , hpRatio , hpRatio , 0.3f ) ;
2012-11-15 00:42:12 +01:00
}
else {
2014-11-22 23:15:19 +01:00
glColor4f ( 0 , hpRatio , 0 , 0.3f ) ;
2012-11-15 00:42:12 +01:00
}
2010-09-01 01:14:15 +02:00
}
2012-11-15 00:42:12 +01:00
else if ( world - > getThisTeamIndex ( ) = = unit - > getTeam ( ) ) {
2014-11-22 23:15:19 +01:00
glColor4f ( hpRatio , hpRatio , 0 , 0.3f ) ;
2010-09-01 01:14:15 +02:00
}
2014-11-29 05:49:04 +01:00
else {
2014-11-22 23:15:19 +01:00
glColor4f ( hpRatio , 0 , 0 , 0.3f ) ;
2012-11-15 00:42:12 +01:00
}
2014-11-22 23:15:19 +01:00
renderSelectionCircle ( currVec , unit - > getType ( ) - > getSize ( ) , selectionCircleRadius , selectionCircleThickness ) ;
2010-03-13 22:10:45 +01:00
2012-11-15 00:42:12 +01:00
if ( showDebugUI = = true & &
( showDebugUILevel & debugui_unit_titles ) = = debugui_unit_titles ) {
2011-02-11 05:48:17 +01:00
2012-11-15 00:42:12 +01:00
const UnitPathInterface * path = unit - > getPath ( ) ;
2013-12-14 08:04:12 +01:00
const UnitPathBasic * pathfinder = ( path = = NULL ? NULL : dynamic_cast < const UnitPathBasic * > ( path ) ) ;
if ( pathfinder ! = NULL ) {
vector < Vec2i > pathList = pathfinder - > getQueue ( ) ;
2011-02-11 05:48:17 +01:00
2012-11-15 00:42:12 +01:00
Vec2i lastPosValue ;
2013-11-19 07:14:06 +01:00
for ( int i = 0 ; i < ( int ) pathList . size ( ) ; + + i ) {
2012-11-15 00:42:12 +01:00
Vec2i curPosValue = pathList [ i ] ;
if ( i = = 0 ) {
lastPosValue = curPosValue ;
}
2013-10-03 02:17:51 +02:00
Vec3f currVec2 = unit - > getVectorFlat ( lastPosValue , curPosValue ) ;
2012-11-15 00:42:12 +01:00
currVec2 . y + = 0.3f ;
renderSelectionCircle ( currVec2 , 1 , selectionCircleRadius ) ;
2011-02-11 05:48:17 +01:00
}
}
}
2012-11-15 00:42:12 +01:00
//magic circle
2014-11-22 23:15:19 +01:00
if ( ! healthbarsVisible & & world - > getThisFactionIndex ( ) = = unit - > getFactionIndex ( ) & & unit - > getType ( ) - > getMaxEp ( ) > 0 ) {
2012-11-15 00:42:12 +01:00
glColor4f ( unit - > getEpRatio ( ) / 2.f , unit - > getEpRatio ( ) , unit - > getEpRatio ( ) , 0.5f ) ;
renderSelectionCircle ( currVec , unit - > getType ( ) - > getSize ( ) , magicCircleRadius ) ;
}
2011-06-25 16:18:53 +02:00
2012-11-15 00:42:12 +01:00
// Render Attack-boost circles
if ( showDebugUI = = true ) {
//const std::pair<const SkillType *,std::vector<Unit *> > ¤tAttackBoostUnits = unit->getCurrentAttackBoostUnits();
const UnitAttackBoostEffectOriginator & effect = unit - > getAttackBoostOriginatorEffect ( ) ;
2011-06-25 16:18:53 +02:00
2012-11-15 00:42:12 +01:00
if ( effect . skillType - > isAttackBoostEnabled ( ) = = true ) {
glColor4f ( MAGENTA . x , MAGENTA . y , MAGENTA . z , MAGENTA . w ) ;
2014-11-24 22:14:09 +01:00
renderSelectionCircle ( currVec , 1 , effect . skillType - > getAttackBoost ( ) - > radius , .25f / effect . skillType - > getAttackBoost ( ) - > radius ) ;
2011-06-25 16:18:53 +02:00
2012-11-15 00:42:12 +01:00
for ( unsigned int i = 0 ; i < effect . currentAttackBoostUnits . size ( ) ; + + i ) {
// Remove attack boost upgrades from unit
int findUnitId = effect . currentAttackBoostUnits [ i ] ;
Unit * affectedUnit = game - > getWorld ( ) - > findUnitById ( findUnitId ) ;
if ( affectedUnit ! = NULL ) {
2013-10-03 02:17:51 +02:00
Vec3f currVecBoost = affectedUnit - > getCurrVectorFlat ( ) ;
2012-11-15 00:42:12 +01:00
currVecBoost . y + = 0.3f ;
2011-06-25 16:18:53 +02:00
2012-11-15 00:42:12 +01:00
renderSelectionCircle ( currVecBoost , affectedUnit - > getType ( ) - > getSize ( ) , 1.f ) ;
}
2011-07-06 07:16:25 +02:00
}
2011-06-25 16:18:53 +02:00
}
}
2017-03-10 01:14:27 +01:00
//meeting point arrow
if ( unit - > getType ( ) - > getMeetingPoint ( ) ) {
Vec2i pos = unit - > getMeetingPos ( ) ;
map - > clampPos ( pos ) ;
Vec3f arrowTarget = Vec3f ( pos . x , map - > getCell ( pos ) - > getHeight ( ) , pos . y ) ;
renderArrow ( unit - > getCurrVectorFlat ( ) , arrowTarget , Vec3f ( 0.f , 0.f , 1.f ) , 0.3f ) ;
}
2011-06-25 16:18:53 +02:00
}
2010-03-13 22:10:45 +01:00
}
2012-11-15 00:42:12 +01:00
if ( selectedResourceObject ! = NULL & & selectedResourceObject - > getResource ( ) ! = NULL & & selection - > getCount ( ) < 1 ) {
2011-02-13 22:04:30 +01:00
Resource * r = selectedResourceObject - > getResource ( ) ;
int defaultValue = r - > getType ( ) - > getDefResPerPatch ( ) ;
float colorValue = static_cast < float > ( r - > getAmount ( ) ) / static_cast < float > ( defaultValue ) ;
glColor4f ( 0.1f , 0.1f , colorValue , 0.4f ) ;
2013-10-03 02:17:51 +02:00
renderSelectionCircle ( selectedResourceObject - > getPos ( ) , 2 , selectionCircleRadius ) ;
2011-02-13 22:04:30 +01:00
}
2010-03-13 22:10:45 +01:00
//target arrow
2010-09-10 10:51:32 +02:00
if ( selection - > getCount ( ) = = 1 ) {
2010-03-13 22:10:45 +01:00
const Unit * unit = selection - > getUnit ( 0 ) ;
2012-11-15 00:42:12 +01:00
if ( unit ! = NULL ) {
//comand arrow
if ( focusArrows & & unit - > anyCommand ( ) ) {
const CommandType * ct = unit - > getCurrCommand ( ) - > getCommandType ( ) ;
if ( ct - > getClicks ( ) ! = cOne ) {
//arrow color
Vec3f arrowColor ;
switch ( ct - > getClass ( ) ) {
case ccMove :
arrowColor = Vec3f ( 0.f , 1.f , 0.f ) ;
break ;
case ccAttack :
case ccAttackStopped :
arrowColor = Vec3f ( 1.f , 0.f , 0.f ) ;
break ;
default :
arrowColor = Vec3f ( 1.f , 1.f , 0.f ) ;
break ;
}
2010-03-13 22:10:45 +01:00
2012-11-15 00:42:12 +01:00
//arrow target
Vec3f arrowTarget ;
Command * c = unit - > getCurrCommand ( ) ;
if ( c - > getUnit ( ) ! = NULL ) {
2013-10-03 02:17:51 +02:00
arrowTarget = c - > getUnit ( ) - > getCurrVectorFlat ( ) ;
2012-11-15 00:42:12 +01:00
}
else {
Vec2i pos = c - > getPos ( ) ;
map - > clampPos ( pos ) ;
2010-03-13 22:10:45 +01:00
2012-11-15 00:42:12 +01:00
arrowTarget = Vec3f ( pos . x , map - > getCell ( pos ) - > getHeight ( ) , pos . y ) ;
}
2011-02-23 22:54:51 +01:00
2013-10-03 02:17:51 +02:00
renderArrow ( unit - > getCurrVectorFlat ( ) , arrowTarget , arrowColor , 0.3f ) ;
2010-03-13 22:10:45 +01:00
}
}
}
}
//render selection hightlights
2012-11-15 00:42:12 +01:00
if ( game - > getGui ( ) - > getHighlightedUnit ( ) ! = NULL ) {
2012-04-05 00:57:32 +02:00
const Unit * unit = game - > getGui ( ) - > getHighlightedUnit ( ) ;
2010-03-13 22:10:45 +01:00
2012-04-05 00:57:32 +02:00
if ( unit - > isHighlighted ( ) ) {
float highlight = unit - > getHightlight ( ) ;
if ( game - > getWorld ( ) - > getThisFactionIndex ( ) = = unit - > getFactionIndex ( ) ) {
glColor4f ( 0.f , 1.f , 0.f , highlight ) ;
}
else {
glColor4f ( 1.f , 0.f , 0.f , highlight ) ;
2010-03-13 22:10:45 +01:00
}
2012-04-05 00:57:32 +02:00
2013-10-03 02:17:51 +02:00
Vec3f v = unit - > getCurrVectorFlat ( ) ;
2012-04-05 00:57:32 +02:00
v . y + = 0.3f ;
renderSelectionCircle ( v , unit - > getType ( ) - > getSize ( ) , 0.5f + 0.4f * highlight ) ;
2010-03-13 22:10:45 +01:00
}
}
2012-04-05 00:57:32 +02:00
// old inefficient way to render highlights
// for(int i=0; i < world->getFactionCount(); ++i) {
// for(int j=0; j < world->getFaction(i)->getUnitCount(); ++j) {
// const Unit *unit= world->getFaction(i)->getUnit(j);
//
// if(unit->isHighlighted()) {
// float highlight= unit->getHightlight();
// if(game->getWorld()->getThisFactionIndex() == unit->getFactionIndex()) {
// glColor4f(0.f, 1.f, 0.f, highlight);
// }
// else{
// glColor4f(1.f, 0.f, 0.f, highlight);
// }
//
// Vec3f v= unit->getCurrVectorFlat();
// v.y+= 0.3f;
// renderSelectionCircle(v, unit->getType()->getSize(), 0.5f+0.4f*highlight );
// }
// }
// }
2012-04-04 02:30:16 +02:00
//render resource selection highlight
2012-11-15 00:42:12 +01:00
if ( game - > getGui ( ) - > getHighlightedResourceObject ( ) ! = NULL ) {
2012-04-04 02:30:16 +02:00
const Object * object = game - > getGui ( ) - > getHighlightedResourceObject ( ) ;
2012-11-15 00:42:12 +01:00
if ( object - > isHighlighted ( ) ) {
2012-04-04 02:30:16 +02:00
float highlight = object - > getHightlight ( ) ;
glColor4f ( 0.1f , 0.1f , 1.0f , highlight ) ;
2013-10-03 02:17:51 +02:00
Vec3f v = object - > getPos ( ) ;
2012-04-04 02:30:16 +02:00
v . y + = 0.3f ;
renderSelectionCircle ( v , 2 , 0.4f + 0.4f * highlight ) ;
}
}
2010-03-13 22:10:45 +01:00
glPopAttrib ( ) ;
}
2014-10-27 16:16:50 +01:00
2014-11-06 21:12:47 +01:00
void Renderer : : renderHealthBars ( int healthbarMode ) {
2014-10-27 16:16:50 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
Config & config = Config : : getInstance ( ) ;
if ( config . getBool ( " RecordMode " , " false " ) = = true ) {
return ;
}
2014-10-30 00:55:18 +01:00
if ( config . getBool ( " PhotoMode " ) ) {
return ;
}
2014-10-27 16:16:50 +01:00
glPushAttrib ( GL_ENABLE_BIT | GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT ) ;
glDisable ( GL_LIGHTING ) ;
glDisable ( GL_TEXTURE_2D ) ;
glDepthFunc ( GL_ALWAYS ) ;
glDisable ( GL_STENCIL_TEST ) ;
glDisable ( GL_CULL_FACE ) ;
glEnable ( GL_BLEND ) ;
glLineWidth ( 2.f ) ;
VisibleQuadContainerCache & qCache = getQuadCache ( ) ;
if ( qCache . visibleQuadUnitList . empty ( ) = = false ) {
for ( int visibleUnitIndex = 0 ;
visibleUnitIndex < ( int ) qCache . visibleQuadUnitList . size ( ) ; + + visibleUnitIndex ) {
Unit * unit = qCache . visibleQuadUnitList [ visibleUnitIndex ] ;
2014-11-22 23:15:19 +01:00
if ( isHealthBarVisible ( unit , healthbarMode ) ) {
float healthbarheight ;
float healthbarthickness ;
const Texture2D * healthbarTexture ;
const Texture2D * healthbarBackgroundTexture ;
bool healthbarLineBorder ;
//get settings of the faction
healthbarheight = unit - > getFaction ( ) - > getType ( ) - > getHealthbarHeight ( ) ;
healthbarthickness = unit - > getFaction ( ) - > getType ( ) - > getHealthbarThickness ( ) ;
healthbarLineBorder = unit - > getFaction ( ) - > getType ( ) - > isHealthbarLineBorder ( ) ;
CoreData & coreData = CoreData : : getInstance ( ) ;
//First try faction texture then use core Texture
if ( unit - > getFaction ( ) - > getType ( ) - > isHealthbarBorderTextureEnabled ( ) ) {
healthbarTexture = unit - > getFaction ( ) - > getType ( ) - > getHealthbarTexture ( ) ;
if ( healthbarTexture = = NULL ) {
healthbarTexture = coreData . getHealthbarTexture ( ) ;
}
} else {
healthbarTexture = NULL ;
2014-11-05 02:05:47 +01:00
}
2014-11-22 23:15:19 +01:00
if ( unit - > getFaction ( ) - > getType ( ) - > isHealthbarBackgroundTextureEnabled ( ) ) {
healthbarBackgroundTexture = unit - > getFaction ( ) - > getType ( ) - > getHealthbarBackgroundTexture ( ) ;
if ( healthbarBackgroundTexture = = NULL ) {
healthbarBackgroundTexture = coreData . getHealthbarBackgroundTexture ( ) ;
}
} else {
healthbarBackgroundTexture = NULL ;
2014-11-05 02:05:47 +01:00
}
2014-10-29 22:23:46 +01:00
2014-11-22 23:15:19 +01:00
//replace them by the ones from the unit if existent
if ( unit - > getType ( ) - > getHealthbarVisible ( ) ! = hbvOff & & unit - > getType ( ) - > getHealthbarVisible ( ) ! = hbvUndefined ) {
if ( unit - > getType ( ) - > getHealthbarHeight ( ) ! = - 100.0f ) {
healthbarheight = unit - > getType ( ) - > getHealthbarHeight ( ) ;
}
if ( unit - > getType ( ) - > getHealthbarThickness ( ) ! = - 1.0f ) {
healthbarthickness = unit - > getType ( ) - > getHealthbarThickness ( ) ;
}
2014-11-06 21:12:47 +01:00
}
2014-10-29 22:23:46 +01:00
2014-10-29 00:50:45 +01:00
Vec3f currVec = unit - > getCurrVectorFlat ( ) ;
2014-10-29 22:23:46 +01:00
if ( healthbarheight = = - 100.0f ) {
2014-10-30 00:55:18 +01:00
currVec . y + = unit - > getType ( ) - > getHeight ( ) ;
2014-10-29 00:50:45 +01:00
} else {
2014-10-29 22:23:46 +01:00
currVec . y + = healthbarheight ;
2014-10-29 00:50:45 +01:00
}
2014-11-22 23:15:19 +01:00
renderHealthBar ( currVec , unit , healthbarthickness , healthbarLineBorder , healthbarTexture , healthbarBackgroundTexture ) ;
2014-10-27 16:16:50 +01:00
}
}
}
glPopAttrib ( ) ;
}
2010-03-13 22:10:45 +01:00
2014-11-22 23:15:19 +01:00
bool Renderer : : isHealthBarVisible ( const Unit * unit , int healthbarMode ) {
int healthbarVisible = hbvUndefined ;
//check options (hotkey)
if ( healthbarMode = = hbvUndefined ) {
healthbarVisible = unit - > getFaction ( ) - > getType ( ) - > getHealthbarVisible ( ) ;
} else {
healthbarVisible = healthbarMode ;
}
//replace them by the ones from the unit if existent
if ( unit - > getType ( ) - > getHealthbarVisible ( ) ! = hbvOff & & unit - > getType ( ) - > getHealthbarVisible ( ) ! = hbvUndefined ) {
if ( healthbarMode = = hbvUndefined ) { //don't override the visible setting when hotkey is not hbvUndefined
healthbarVisible = unit - > getType ( ) - > getHealthbarVisible ( ) ;
}
}
bool settingsWantToRenderThem = ! ( healthbarVisible = = hbvUndefined | | ( healthbarVisible & hbvOff ) )
& & ( ( healthbarVisible & hbvAlways )
2014-11-24 01:39:29 +01:00
| | ( ( healthbarVisible & hbvIfNeeded ) & & unit - > getHp ( ) < unit - > getType ( ) - > getMaxHp ( ) + unit - > getTotalUpgrade ( ) - > getMaxHp ( ) )
2014-11-27 01:17:32 +01:00
| | ( ( healthbarVisible & hbvIfNeeded ) & & unit - > getType ( ) - > getMaxEp ( ) > 0 & & unit - > getEp ( ) < unit - > getType ( ) - > getMaxEp ( ) + unit - > getTotalUpgrade ( ) - > getMaxEp ( ) )
2014-11-22 23:15:19 +01:00
| | ( ( healthbarVisible & hbvIfNeeded ) & & unit - > getProductionPercent ( ) > 0 )
| | ( ( healthbarVisible & hbvSelected ) & & game - > getGui ( ) - > isSelected ( unit ) ) ) ;
if ( unit - > isAlive ( ) & & ( settingsWantToRenderThem ) ) {
return true ;
}
return false ;
}
2010-03-13 22:10:45 +01:00
void Renderer : : renderWaterEffects ( ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2010-03-13 22:10:45 +01:00
const World * world = game - > getWorld ( ) ;
const WaterEffects * we = world - > getWaterEffects ( ) ;
const Map * map = world - > getMap ( ) ;
2013-12-28 07:00:29 +01:00
CoreData & coreData = CoreData : : getInstance ( ) ;
2010-03-13 22:10:45 +01:00
float height = map - > getWaterLevel ( ) + 0.001f ;
assertGl ( ) ;
glPushAttrib ( GL_CURRENT_BIT | GL_ENABLE_BIT | GL_DEPTH_BUFFER_BIT ) ;
glEnable ( GL_BLEND ) ;
glDisable ( GL_ALPHA_TEST ) ;
glDepthMask ( GL_FALSE ) ;
glDepthFunc ( GL_LEQUAL ) ;
glEnable ( GL_COLOR_MATERIAL ) ;
2011-02-09 02:27:41 +01:00
//glNormal3f(0.f, 1.f, 0.f);
2010-03-13 22:10:45 +01:00
//splashes
glBindTexture ( GL_TEXTURE_2D , static_cast < Texture2DGl * > ( coreData . getWaterSplashTexture ( ) ) - > getHandle ( ) ) ;
2011-02-09 02:27:41 +01:00
//!!!
Vec2f texCoords [ 4 ] ;
Vec3f vertices [ 4 ] ;
Vec3f normals [ 4 ] ;
glEnableClientState ( GL_VERTEX_ARRAY ) ;
glEnableClientState ( GL_NORMAL_ARRAY ) ;
glEnableClientState ( GL_TEXTURE_COORD_ARRAY ) ;
2010-03-13 22:10:45 +01:00
for ( int i = 0 ; i < we - > getWaterSplashCount ( ) ; + + i ) {
const WaterSplash * ws = we - > getWaterSplash ( i ) ;
//render only if enabled
if ( ws - > getEnabled ( ) ) {
//render only if visible
Vec2i intPos = Vec2i ( static_cast < int > ( ws - > getPos ( ) . x ) , static_cast < int > ( ws - > getPos ( ) . y ) ) ;
2010-06-22 06:09:23 +02:00
const Vec2i & mapPos = Map : : toSurfCoords ( intPos ) ;
2011-01-27 23:17:31 +01:00
bool visible = map - > getSurfaceCell ( mapPos ) - > isVisible ( world - > getThisTeamIndex ( ) ) ;
if ( visible = = false & & world - > showWorldForPlayer ( world - > getThisFactionIndex ( ) ) = = true ) {
visible = true ;
}
if ( visible = = true ) {
2010-05-04 00:07:27 +02:00
float scale = ws - > getAnim ( ) * ws - > getSize ( ) ;
2011-02-09 02:27:41 +01:00
texCoords [ 0 ] = Vec2f ( 0.f , 1.f ) ;
vertices [ 0 ] = Vec3f ( ws - > getPos ( ) . x - scale , height , ws - > getPos ( ) . y + scale ) ;
normals [ 0 ] = Vec3f ( 0.f , 1.f , 0.f ) ;
texCoords [ 1 ] = Vec2f ( 0.f , 0.f ) ;
vertices [ 1 ] = Vec3f ( ws - > getPos ( ) . x - scale , height , ws - > getPos ( ) . y - scale ) ;
normals [ 1 ] = Vec3f ( 0.f , 1.f , 0.f ) ;
texCoords [ 2 ] = Vec2f ( 1.f , 1.f ) ;
vertices [ 2 ] = Vec3f ( ws - > getPos ( ) . x + scale , height , ws - > getPos ( ) . y + scale ) ;
normals [ 2 ] = Vec3f ( 0.f , 1.f , 0.f ) ;
texCoords [ 3 ] = Vec2f ( 1.f , 0.f ) ;
vertices [ 3 ] = Vec3f ( ws - > getPos ( ) . x + scale , height , ws - > getPos ( ) . y - scale ) ;
normals [ 3 ] = Vec3f ( 0.f , 1.f , 0.f ) ;
glColor4f ( 1.f , 1.f , 1.f , 1.f - ws - > getAnim ( ) ) ;
glTexCoordPointer ( 2 , GL_FLOAT , 0 , & texCoords [ 0 ] ) ;
glVertexPointer ( 3 , GL_FLOAT , 0 , & vertices [ 0 ] ) ;
glNormalPointer ( GL_FLOAT , 0 , & normals [ 0 ] ) ;
glDrawArrays ( GL_TRIANGLE_STRIP , 0 , 4 ) ;
2010-03-13 22:10:45 +01:00
2011-02-09 02:27:41 +01:00
/*
2010-03-13 22:10:45 +01:00
glBegin ( GL_TRIANGLE_STRIP ) ;
glTexCoord2f ( 0.f , 1.f ) ;
glVertex3f ( ws - > getPos ( ) . x - scale , height , ws - > getPos ( ) . y + scale ) ;
glTexCoord2f ( 0.f , 0.f ) ;
glVertex3f ( ws - > getPos ( ) . x - scale , height , ws - > getPos ( ) . y - scale ) ;
glTexCoord2f ( 1.f , 1.f ) ;
glVertex3f ( ws - > getPos ( ) . x + scale , height , ws - > getPos ( ) . y + scale ) ;
glTexCoord2f ( 1.f , 0.f ) ;
glVertex3f ( ws - > getPos ( ) . x + scale , height , ws - > getPos ( ) . y - scale ) ;
glEnd ( ) ;
2011-02-09 02:27:41 +01:00
*/
2010-03-13 22:10:45 +01:00
}
}
}
2011-02-09 02:27:41 +01:00
glDisableClientState ( GL_TEXTURE_COORD_ARRAY ) ;
glDisableClientState ( GL_NORMAL_ARRAY ) ;
glDisableClientState ( GL_VERTEX_ARRAY ) ;
2010-03-13 22:10:45 +01:00
glPopAttrib ( ) ;
assertGl ( ) ;
}
2011-06-09 02:59:03 +02:00
void Renderer : : renderHud ( ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2011-06-09 02:59:03 +02:00
Texture2D * hudTexture = game - > getGui ( ) - > getHudTexture ( ) ;
if ( hudTexture ! = NULL ) {
2011-07-07 00:02:38 +02:00
const Metrics & metrics = Metrics : : getInstance ( ) ;
2011-06-09 02:59:03 +02:00
renderTextureQuad ( 0 , 0 , metrics . getVirtualW ( ) , metrics . getVirtualH ( ) , hudTexture , 1.0f ) ;
}
}
2010-03-13 22:10:45 +01:00
void Renderer : : renderMinimap ( ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2010-03-13 22:10:45 +01:00
const World * world = game - > getWorld ( ) ;
const Minimap * minimap = world - > getMinimap ( ) ;
2012-04-02 03:45:13 +02:00
if ( minimap = = NULL | | minimap - > getTexture ( ) = = NULL ) {
return ;
}
2010-03-13 22:10:45 +01:00
const GameCamera * gameCamera = game - > getGameCamera ( ) ;
2010-11-09 10:06:52 +01:00
const Pixmap2D * pixmap = minimap - > getTexture ( ) - > getPixmapConst ( ) ;
2010-03-13 22:10:45 +01:00
const Metrics & metrics = Metrics : : getInstance ( ) ;
2010-12-19 23:33:08 +01:00
const WaterEffects * attackEffects = world - > getAttackEffects ( ) ;
2010-03-13 22:10:45 +01:00
int mx = metrics . getMinimapX ( ) ;
int my = metrics . getMinimapY ( ) ;
int mw = metrics . getMinimapW ( ) ;
int mh = metrics . getMinimapH ( ) ;
Vec2f zoom = Vec2f (
static_cast < float > ( mw ) / pixmap - > getW ( ) ,
static_cast < float > ( mh ) / pixmap - > getH ( ) ) ;
assertGl ( ) ;
2011-03-31 01:27:21 +02:00
// render minimap border
2011-03-31 00:39:52 +02:00
Vec4f col = game - > getGui ( ) - > getDisplay ( ) - > getColor ( ) ;
glColor4f ( col . x * 0.5f , col . y * 0.5f , col . z * 0.5f , 1.0 ) ;
2011-03-31 01:27:21 +02:00
2011-04-07 02:09:57 +02:00
int borderWidth = 2 ;
2011-03-31 01:27:21 +02:00
glBegin ( GL_QUADS ) ;
2011-04-07 02:09:57 +02:00
glVertex2i ( mx - borderWidth , my - borderWidth ) ;
glVertex2i ( mx - borderWidth , my ) ;
glVertex2i ( mx + mw + borderWidth , my ) ;
glVertex2i ( mx + mw + borderWidth , my - borderWidth ) ;
2011-03-31 01:27:21 +02:00
glEnd ( ) ;
glBegin ( GL_QUADS ) ;
2011-04-07 02:09:57 +02:00
glVertex2i ( mx - borderWidth , my + mh + borderWidth ) ;
glVertex2i ( mx - borderWidth , my + mh ) ;
glVertex2i ( mx + mw + borderWidth , my + mh ) ;
glVertex2i ( mx + mw + borderWidth , my + mh + borderWidth ) ;
2011-03-31 01:27:21 +02:00
glEnd ( ) ;
2011-03-31 00:39:52 +02:00
2011-03-31 01:27:21 +02:00
glBegin ( GL_QUADS ) ;
2011-04-07 02:09:57 +02:00
glVertex2i ( mx - borderWidth , my ) ;
glVertex2i ( mx - borderWidth , my + mh ) ;
2011-03-31 01:27:21 +02:00
glVertex2i ( mx , my + mh ) ;
glVertex2i ( mx , my ) ;
glEnd ( ) ;
glBegin ( GL_QUADS ) ;
glVertex2i ( mx + mw , my ) ;
glVertex2i ( mx + mw , my + mh ) ;
2011-04-07 02:09:57 +02:00
glVertex2i ( mx + mw + borderWidth , my + mh ) ;
glVertex2i ( mx + mw + borderWidth , my ) ;
2011-03-31 00:39:52 +02:00
glEnd ( ) ;
assertGl ( ) ;
glPushAttrib ( GL_CURRENT_BIT | GL_ENABLE_BIT | GL_LINE_BIT | GL_TEXTURE_BIT ) ;
2010-03-13 22:10:45 +01:00
//draw map
glEnable ( GL_TEXTURE_2D ) ;
glEnable ( GL_BLEND ) ;
glActiveTexture ( fowTexUnit ) ;
glEnable ( GL_TEXTURE_2D ) ;
glBindTexture ( GL_TEXTURE_2D , static_cast < const Texture2DGl * > ( minimap - > getFowTexture ( ) ) - > getHandle ( ) ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_TEXTURE_ENV_MODE , GL_COMBINE ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_COMBINE_RGB , GL_INTERPOLATE ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_SOURCE0_RGB , GL_PREVIOUS ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_SOURCE1_RGB , GL_PRIMARY_COLOR ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_SOURCE2_RGB , GL_TEXTURE ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_COMBINE_ALPHA , GL_ADD ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_SOURCE0_ALPHA , GL_PRIMARY_COLOR ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_SOURCE1_ALPHA , GL_TEXTURE ) ;
glActiveTexture ( baseTexUnit ) ;
glBindTexture ( GL_TEXTURE_2D , static_cast < const Texture2DGl * > ( minimap - > getTexture ( ) ) - > getHandle ( ) ) ;
2011-04-07 02:09:57 +02:00
glColor4f ( 0.5f , 0.5f , 0.5f , 0.2f ) ;
2011-03-31 01:27:21 +02:00
2010-03-13 22:10:45 +01:00
glBegin ( GL_TRIANGLE_STRIP ) ;
glTexCoord2f ( 0.0f , 1.0f ) ;
glMultiTexCoord2f ( fowTexUnit , 0.0f , 1.0f ) ;
glVertex2i ( mx , my ) ;
2011-02-09 09:04:21 +01:00
2010-03-13 22:10:45 +01:00
glTexCoord2f ( 0.0f , 0.0f ) ;
glMultiTexCoord2f ( fowTexUnit , 0.0f , 0.0f ) ;
glVertex2i ( mx , my + mh ) ;
2011-02-09 09:04:21 +01:00
2010-03-13 22:10:45 +01:00
glTexCoord2f ( 1.0f , 1.0f ) ;
glMultiTexCoord2f ( fowTexUnit , 1.0f , 1.0f ) ;
glVertex2i ( mx + mw , my ) ;
2011-02-09 09:04:21 +01:00
2010-03-13 22:10:45 +01:00
glTexCoord2f ( 1.0f , 0.0f ) ;
glMultiTexCoord2f ( fowTexUnit , 1.0f , 0.0f ) ;
glVertex2i ( mx + mw , my + mh ) ;
glEnd ( ) ;
glDisable ( GL_BLEND ) ;
glActiveTexture ( fowTexUnit ) ;
glDisable ( GL_TEXTURE_2D ) ;
glActiveTexture ( baseTexUnit ) ;
glDisable ( GL_TEXTURE_2D ) ;
2010-12-19 23:33:08 +01:00
glEnable ( GL_BLEND ) ;
2011-02-09 02:27:41 +01:00
const int itemCount = attackEffects - > getWaterSplashCount ( ) * 12 ;
2011-02-09 02:42:58 +01:00
if ( itemCount > 0 ) {
vector < Vec2f > vertices ;
vertices . resize ( itemCount ) ;
vector < Vec4f > colors ;
colors . resize ( itemCount ) ;
// draw attack alarm
int vertexIndex = 0 ;
for ( int i = 0 ; i < attackEffects - > getWaterSplashCount ( ) ; + + i ) {
const WaterSplash * ws = attackEffects - > getWaterSplash ( i ) ;
float scale = ( 1 / ws - > getAnim ( ) * ws - > getSize ( ) ) * 5 ;
//glColor4f(1.f, 1.f, 0.f, 1.f-ws->getAnim());
float alpha = ( 1.f - ws - > getAnim ( ) ) * 0.01f ;
Vec2f pos = ws - > getPos ( ) / Map : : cellScale ;
float attackX = mx + pos . x * zoom . x ;
float attackY = my + mh - pos . y * zoom . y ;
if ( ws - > getEnabled ( ) ) {
// glBegin(GL_QUADS);
// glVertex2f(attackX-scale, attackY-scale);
// glVertex2f(attackX-scale, attackY+scale);
// glVertex2f(attackX+scale, attackY+scale);
// glVertex2f(attackX+scale, attackY-scale);
// glEnd();
colors [ vertexIndex ] = Vec4f ( 1.f , 1.f , 0.f , alpha ) ;
vertices [ vertexIndex ] = Vec2f ( attackX - scale , attackY - scale ) ;
vertexIndex + + ;
colors [ vertexIndex ] = Vec4f ( 1.f , 1.f , 0.f , alpha ) ;
vertices [ vertexIndex ] = Vec2f ( attackX - scale , attackY + scale ) ;
vertexIndex + + ;
colors [ vertexIndex ] = Vec4f ( 1.f , 1.f , 0.f , 0.8f ) ;
2011-02-09 09:04:21 +01:00
vertices [ vertexIndex ] = Vec2f ( attackX , attackY ) ;
2011-02-09 02:42:58 +01:00
vertexIndex + + ;
2011-02-09 09:04:21 +01:00
2011-02-09 02:42:58 +01:00
colors [ vertexIndex ] = Vec4f ( 1.f , 1.f , 0.f , alpha ) ;
vertices [ vertexIndex ] = Vec2f ( attackX + scale , attackY + scale ) ;
vertexIndex + + ;
colors [ vertexIndex ] = Vec4f ( 1.f , 1.f , 0.f , alpha ) ;
2011-02-09 09:04:21 +01:00
vertices [ vertexIndex ] = Vec2f ( attackX - scale , attackY + scale ) ;
2011-02-09 02:42:58 +01:00
vertexIndex + + ;
colors [ vertexIndex ] = Vec4f ( 1.f , 1.f , 0.f , 0.8f ) ;
2011-02-09 09:04:21 +01:00
vertices [ vertexIndex ] = Vec2f ( attackX , attackY ) ;
2011-02-09 02:42:58 +01:00
vertexIndex + + ;
2011-02-09 09:04:21 +01:00
2011-02-09 02:42:58 +01:00
colors [ vertexIndex ] = Vec4f ( 1.f , 1.f , 0.f , alpha ) ;
2011-02-09 09:04:21 +01:00
vertices [ vertexIndex ] = Vec2f ( attackX + scale , attackY + scale ) ;
2011-02-09 02:42:58 +01:00
vertexIndex + + ;
colors [ vertexIndex ] = Vec4f ( 1.f , 1.f , 0.f , alpha ) ;
2011-02-09 09:04:21 +01:00
vertices [ vertexIndex ] = Vec2f ( attackX + scale , attackY - scale ) ;
2011-02-09 02:42:58 +01:00
vertexIndex + + ;
colors [ vertexIndex ] = Vec4f ( 1.f , 1.f , 0.f , 0.8f ) ;
vertices [ vertexIndex ] = Vec2f ( attackX , attackY ) ;
vertexIndex + + ;
2011-02-09 09:04:21 +01:00
2011-02-09 02:42:58 +01:00
colors [ vertexIndex ] = Vec4f ( 1.f , 1.f , 0.f , alpha ) ;
2011-02-09 09:04:21 +01:00
vertices [ vertexIndex ] = Vec2f ( attackX + scale , attackY - scale ) ;
2011-02-09 02:42:58 +01:00
vertexIndex + + ;
colors [ vertexIndex ] = Vec4f ( 1.f , 1.f , 0.f , alpha ) ;
2011-02-09 09:04:21 +01:00
vertices [ vertexIndex ] = Vec2f ( attackX - scale , attackY - scale ) ;
2011-02-09 02:42:58 +01:00
vertexIndex + + ;
colors [ vertexIndex ] = Vec4f ( 1.f , 1.f , 0.f , 0.8f ) ;
vertices [ vertexIndex ] = Vec2f ( attackX , attackY ) ;
vertexIndex + + ;
/*
glBegin ( GL_TRIANGLES ) ;
glColor4f ( 1.f , 1.f , 0.f , alpha ) ;
glVertex2f ( attackX - scale , attackY - scale ) ;
glVertex2f ( attackX - scale , attackY + scale ) ;
glColor4f ( 1.f , 1.f , 0.f , 0.8f ) ;
glVertex2f ( attackX , attackY ) ;
glEnd ( ) ;
glBegin ( GL_TRIANGLES ) ;
glColor4f ( 1.f , 1.f , 0.f , alpha ) ;
glVertex2f ( attackX - scale , attackY + scale ) ;
glVertex2f ( attackX + scale , attackY + scale ) ;
glColor4f ( 1.f , 1.f , 0.f , 0.8f ) ;
glVertex2f ( attackX , attackY ) ;
glEnd ( ) ;
glBegin ( GL_TRIANGLES ) ;
glColor4f ( 1.f , 1.f , 0.f , alpha ) ;
glVertex2f ( attackX + scale , attackY + scale ) ;
glVertex2f ( attackX + scale , attackY - scale ) ;
glColor4f ( 1.f , 1.f , 0.f , 0.8f ) ;
glVertex2f ( attackX , attackY ) ;
glEnd ( ) ;
glBegin ( GL_TRIANGLES ) ;
glColor4f ( 1.f , 1.f , 0.f , alpha ) ;
glVertex2f ( attackX + scale , attackY - scale ) ;
glVertex2f ( attackX - scale , attackY - scale ) ;
glColor4f ( 1.f , 1.f , 0.f , 0.8f ) ;
glVertex2f ( attackX , attackY ) ;
glEnd ( ) ;
*/
2010-12-24 03:10:31 +01:00
2011-02-09 02:42:58 +01:00
}
2010-12-19 23:33:08 +01:00
}
2011-02-09 02:27:41 +01:00
2011-02-09 02:42:58 +01:00
if ( vertexIndex > 0 ) {
glEnableClientState ( GL_COLOR_ARRAY ) ;
glEnableClientState ( GL_VERTEX_ARRAY ) ;
glColorPointer ( 4 , GL_FLOAT , 0 , & colors [ 0 ] ) ;
glVertexPointer ( 2 , GL_FLOAT , 0 , & vertices [ 0 ] ) ;
glDrawArrays ( GL_TRIANGLE_STRIP , 0 , vertexIndex ) ;
glDisableClientState ( GL_COLOR_ARRAY ) ;
glDisableClientState ( GL_VERTEX_ARRAY ) ;
}
2011-02-09 02:27:41 +01:00
}
2010-12-19 23:33:08 +01:00
glDisable ( GL_BLEND ) ;
2010-03-13 22:10:45 +01:00
//draw units
2011-01-15 09:45:17 +01:00
VisibleQuadContainerCache & qCache = getQuadCache ( ) ;
2013-03-10 01:40:38 +01:00
std : : vector < Unit * > visibleUnitList = qCache . visibleUnitList ;
const bool showAllUnitsInMinimap = Config : : getInstance ( ) . getBool ( " DebugGameSynchUI " , " false " ) ;
if ( showAllUnitsInMinimap = = true ) {
visibleUnitList . clear ( ) ;
const World * world = game - > getWorld ( ) ;
2013-11-19 07:14:06 +01:00
for ( unsigned int i = 0 ; i < ( unsigned int ) world - > getFactionCount ( ) ; + + i ) {
2013-03-10 01:40:38 +01:00
const Faction * faction = world - > getFaction ( i ) ;
2013-11-19 07:14:06 +01:00
for ( unsigned int j = 0 ; j < ( unsigned int ) faction - > getUnitCount ( ) ; + + j ) {
2013-03-10 01:40:38 +01:00
Unit * unit = faction - > getUnit ( j ) ;
visibleUnitList . push_back ( unit ) ;
}
}
}
if ( visibleUnitList . empty ( ) = = false ) {
2011-02-09 02:27:41 +01:00
uint32 unitIdx = 0 ;
2011-02-09 02:42:58 +01:00
vector < Vec2f > unit_vertices ;
2013-03-10 01:40:38 +01:00
unit_vertices . resize ( visibleUnitList . size ( ) * 4 ) ;
2011-02-09 02:42:58 +01:00
vector < Vec3f > unit_colors ;
2013-03-10 01:40:38 +01:00
unit_colors . resize ( visibleUnitList . size ( ) * 4 ) ;
2011-02-09 02:27:41 +01:00
2011-01-15 09:45:17 +01:00
for ( int visibleIndex = 0 ;
2013-11-19 07:14:06 +01:00
visibleIndex < ( int ) visibleUnitList . size ( ) ; + + visibleIndex ) {
2013-03-10 01:40:38 +01:00
Unit * unit = visibleUnitList [ visibleIndex ] ;
2011-02-09 02:27:41 +01:00
if ( unit - > isAlive ( ) = = false ) {
2011-01-15 09:45:17 +01:00
continue ;
}
2010-09-10 10:51:32 +02:00
2011-01-15 09:45:17 +01:00
Vec2i pos = unit - > getPos ( ) / Map : : cellScale ;
int size = unit - > getType ( ) - > getSize ( ) ;
Vec3f color = unit - > getFaction ( ) - > getTexture ( ) - > getPixmapConst ( ) - > getPixel3f ( 0 , 0 ) ;
2011-02-09 02:27:41 +01:00
unit_colors [ unitIdx ] = color ;
unit_vertices [ unitIdx ] = Vec2f ( mx + pos . x * zoom . x , my + mh - ( pos . y * zoom . y ) ) ;
unitIdx + + ;
unit_colors [ unitIdx ] = color ;
unit_vertices [ unitIdx ] = Vec2f ( mx + ( pos . x + 1 ) * zoom . x + size , my + mh - ( pos . y * zoom . y ) ) ;
unitIdx + + ;
unit_colors [ unitIdx ] = color ;
unit_vertices [ unitIdx ] = Vec2f ( mx + ( pos . x + 1 ) * zoom . x + size , my + mh - ( ( pos . y + size ) * zoom . y ) ) ;
unitIdx + + ;
unit_colors [ unitIdx ] = color ;
unit_vertices [ unitIdx ] = Vec2f ( mx + pos . x * zoom . x , my + mh - ( ( pos . y + size ) * zoom . y ) ) ;
unitIdx + + ;
2010-09-10 10:51:32 +02:00
}
2011-02-09 02:27:41 +01:00
if ( unitIdx > 0 ) {
glEnableClientState ( GL_COLOR_ARRAY ) ;
glEnableClientState ( GL_VERTEX_ARRAY ) ;
glColorPointer ( 3 , GL_FLOAT , 0 , & unit_colors [ 0 ] ) ;
glVertexPointer ( 2 , GL_FLOAT , 0 , & unit_vertices [ 0 ] ) ;
glDrawArrays ( GL_QUADS , 0 , unitIdx ) ;
glDisableClientState ( GL_COLOR_ARRAY ) ;
glDisableClientState ( GL_VERTEX_ARRAY ) ;
}
2010-09-10 10:51:32 +02:00
}
2010-03-13 22:10:45 +01:00
2012-06-12 22:37:00 +02:00
renderMarkedCellsOnMinimap ( ) ;
2010-03-13 22:10:45 +01:00
//draw camera
float wRatio = static_cast < float > ( metrics . getMinimapW ( ) ) / world - > getMap ( ) - > getW ( ) ;
float hRatio = static_cast < float > ( metrics . getMinimapH ( ) ) / world - > getMap ( ) - > getH ( ) ;
int x = static_cast < int > ( gameCamera - > getPos ( ) . x * wRatio ) ;
int y = static_cast < int > ( gameCamera - > getPos ( ) . z * hRatio ) ;
float ang = degToRad ( gameCamera - > getHAng ( ) ) ;
glEnable ( GL_BLEND ) ;
2012-10-06 09:06:40 +02:00
int x1 ;
int y1 ;
2013-06-12 03:07:53 +02:00
x1 = mx + x + static_cast < int > ( 20 * std : : sin ( ang - pi / 5 ) ) ;
y1 = my + mh - ( y - static_cast < int > ( 20 * std : : cos ( ang - pi / 5 ) ) ) ;
2010-09-10 10:51:32 +02:00
2012-10-06 09:06:40 +02:00
int x2 ;
int y2 ;
2013-06-12 03:07:53 +02:00
x2 = mx + x + static_cast < int > ( 20 * std : : sin ( ang + pi / 5 ) ) ;
y2 = my + mh - ( y - static_cast < int > ( 20 * std : : cos ( ang + pi / 5 ) ) ) ;
2010-09-10 10:51:32 +02:00
glColor4f ( 1.f , 1.f , 1.f , 1.f ) ;
glBegin ( GL_TRIANGLES ) ;
glVertex2i ( mx + x , my + mh - y ) ;
glColor4f ( 1.f , 1.f , 1.f , 0.0f ) ;
glVertex2i ( x1 , y1 ) ;
glColor4f ( 1.f , 1.f , 1.f , 0.0f ) ;
glVertex2i ( x2 , y2 ) ;
2010-03-13 22:10:45 +01:00
glEnd ( ) ;
2010-12-24 03:10:31 +01:00
2010-03-13 22:10:45 +01:00
glPopAttrib ( ) ;
assertGl ( ) ;
}
2012-07-13 23:50:34 +02:00
void Renderer : : renderHighlightedCellsOnMinimap ( ) {
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
// Draw marked cells
const std : : vector < MarkedCell > * highlightedCells = game - > getHighlightedCells ( ) ;
if ( highlightedCells - > empty ( ) = = false ) {
2012-09-22 22:37:42 +02:00
//const Map *map= game->getWorld()->getMap();
2012-07-13 23:50:34 +02:00
const World * world = game - > getWorld ( ) ;
const Minimap * minimap = world - > getMinimap ( ) ;
int pointersize = 10 ;
if ( minimap = = NULL | | minimap - > getTexture ( ) = = NULL ) {
return ;
}
2012-09-22 22:37:42 +02:00
//const GameCamera *gameCamera= game->getGameCamera();
2012-07-13 23:50:34 +02:00
const Pixmap2D * pixmap = minimap - > getTexture ( ) - > getPixmapConst ( ) ;
const Metrics & metrics = Metrics : : getInstance ( ) ;
2012-09-22 22:37:42 +02:00
//int mx= metrics.getMinimapX();
2015-01-11 21:46:37 +01:00
int my = metrics . getMinimapY ( ) ;
2012-07-13 23:50:34 +02:00
int mw = metrics . getMinimapW ( ) ;
int mh = metrics . getMinimapH ( ) ;
Vec2f zoom = Vec2f (
static_cast < float > ( mw ) / pixmap - > getW ( ) / 2 ,
static_cast < float > ( mh ) / pixmap - > getH ( ) / 2 ) ;
2013-11-19 07:14:06 +01:00
for ( int i = 0 ; i < ( int ) highlightedCells - > size ( ) ; i + + ) {
2012-07-13 23:50:34 +02:00
const MarkedCell * mc = & highlightedCells - > at ( i ) ;
2012-10-13 07:06:53 +02:00
if ( mc - > getFaction ( ) = = NULL | | ( mc - > getFaction ( ) - > getTeam ( ) = = game - > getWorld ( ) - > getThisFaction ( ) - > getTeam ( ) ) ) {
2012-07-13 23:50:34 +02:00
const Texture2D * texture = game - > getHighlightCellTexture ( ) ;
2012-10-13 07:06:53 +02:00
Vec3f color ( MarkedCell : : static_system_marker_color ) ;
if ( mc - > getFaction ( ) ! = NULL ) {
color = mc - > getFaction ( ) - > getTexture ( ) - > getPixmapConst ( ) - > getPixel3f ( 0 , 0 ) ;
}
2012-11-10 01:01:44 +01:00
int lighting = ( mc - > getAliveCount ( ) % 15 ) ;
Vec3f myColor = Vec3f ( color . x / 2 + .5f / lighting , color . y / 2 + .5f / lighting , color . z / 2 + .5f / lighting ) ;
2012-07-13 23:50:34 +02:00
Vec2i pos = mc - > getTargetPos ( ) ;
2013-01-25 03:55:28 +01:00
if ( texture ! = NULL ) {
//float alpha = 0.49f+0.5f/(mc->getAliveCount()%15);
float alpha = 1.0f ;
2015-01-11 21:46:37 +01:00
renderTextureQuad ( ( int ) ( pos . x * zoom . x ) + pointersize , my + mh - ( int ) ( pos . y * zoom . y ) , pointersize , pointersize , texture , alpha , & myColor ) ;
2012-07-13 23:50:34 +02:00
}
}
}
}
}
2012-06-12 22:37:00 +02:00
void Renderer : : renderMarkedCellsOnMinimap ( ) {
// Draw marked cells
std : : map < Vec2i , MarkedCell > markedCells = game - > getMapMarkedCellList ( ) ;
if ( markedCells . empty ( ) = = false ) {
2012-09-22 22:37:42 +02:00
//const Map *map= game->getWorld()->getMap();
2012-06-12 22:37:00 +02:00
const World * world = game - > getWorld ( ) ;
const Minimap * minimap = world - > getMinimap ( ) ;
if ( minimap = = NULL | | minimap - > getTexture ( ) = = NULL ) {
return ;
}
2012-09-22 22:37:42 +02:00
//const GameCamera *gameCamera= game->getGameCamera();
2012-06-12 22:37:00 +02:00
const Pixmap2D * pixmap = minimap - > getTexture ( ) - > getPixmapConst ( ) ;
const Metrics & metrics = Metrics : : getInstance ( ) ;
2012-09-22 22:37:42 +02:00
//const WaterEffects *attackEffects= world->getAttackEffects();
2012-06-12 22:37:00 +02:00
int mx = metrics . getMinimapX ( ) ;
int my = metrics . getMinimapY ( ) ;
int mw = metrics . getMinimapW ( ) ;
int mh = metrics . getMinimapH ( ) ;
Vec2f zoom = Vec2f (
static_cast < float > ( mw ) / pixmap - > getW ( ) ,
static_cast < float > ( mh ) / pixmap - > getH ( ) ) ;
uint32 unitIdx = 0 ;
vector < Vec2f > unit_vertices ;
unit_vertices . resize ( markedCells . size ( ) * 4 ) ;
vector < Vec4f > unit_colors ;
unit_colors . resize ( markedCells . size ( ) * 4 ) ;
for ( std : : map < Vec2i , MarkedCell > : : iterator iterMap = markedCells . begin ( ) ;
iterMap ! = markedCells . end ( ) ; + + iterMap ) {
MarkedCell & bm = iterMap - > second ;
2012-09-25 09:05:52 +02:00
if ( bm . getPlayerIndex ( ) < 0 | |
( bm . getFaction ( ) ! = NULL & &
bm . getFaction ( ) - > getTeam ( ) = = game - > getWorld ( ) - > getThisFaction ( ) - > getTeam ( ) ) ) {
2012-06-12 22:37:00 +02:00
Vec2i pos = bm . getTargetPos ( ) / Map : : cellScale ;
float size = 0.5f ;
2012-09-25 09:05:52 +02:00
Vec3f color ( MarkedCell : : static_system_marker_color ) ;
if ( bm . getFaction ( ) ! = NULL ) {
color = bm . getFaction ( ) - > getTexture ( ) - > getPixmapConst ( ) - > getPixel3f ( 0 , 0 ) ;
}
2013-01-23 07:53:55 +01:00
float alpha = 0.65f ;
2012-06-12 22:37:00 +02:00
unit_colors [ unitIdx ] = Vec4f ( color . x , color . y , color . z , alpha ) ;
unit_vertices [ unitIdx ] = Vec2f ( mx + pos . x * zoom . x , my + mh - ( pos . y * zoom . y ) ) ;
unitIdx + + ;
unit_colors [ unitIdx ] = Vec4f ( color . x , color . y , color . z , alpha ) ;
unit_vertices [ unitIdx ] = Vec2f ( mx + ( pos . x + 1 ) * zoom . x + size , my + mh - ( pos . y * zoom . y ) ) ;
unitIdx + + ;
unit_colors [ unitIdx ] = Vec4f ( color . x , color . y , color . z , alpha ) ;
unit_vertices [ unitIdx ] = Vec2f ( mx + ( pos . x + 1 ) * zoom . x + size , my + mh - ( ( pos . y + size ) * zoom . y ) ) ;
unitIdx + + ;
unit_colors [ unitIdx ] = Vec4f ( color . x , color . y , color . z , alpha ) ;
unit_vertices [ unitIdx ] = Vec2f ( mx + pos . x * zoom . x , my + mh - ( ( pos . y + size ) * zoom . y ) ) ;
unitIdx + + ;
}
}
if ( unitIdx > 0 ) {
glEnable ( GL_BLEND ) ;
glEnableClientState ( GL_COLOR_ARRAY ) ;
glEnableClientState ( GL_VERTEX_ARRAY ) ;
glColorPointer ( 4 , GL_FLOAT , 0 , & unit_colors [ 0 ] ) ;
glVertexPointer ( 2 , GL_FLOAT , 0 , & unit_vertices [ 0 ] ) ;
glDrawArrays ( GL_QUADS , 0 , unitIdx ) ;
//glDrawArrays(GL_TRIANGLE_STRIP, 0, unitIdx);
glDisableClientState ( GL_COLOR_ARRAY ) ;
glDisableClientState ( GL_VERTEX_ARRAY ) ;
glDisable ( GL_BLEND ) ;
}
}
}
2012-09-20 06:10:34 +02:00
void Renderer : : renderVisibleMarkedCells ( bool renderTextHint , int x , int y ) {
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2012-06-12 22:37:00 +02:00
// Draw marked cells
std : : map < Vec2i , MarkedCell > markedCells = game - > getMapMarkedCellList ( ) ;
if ( markedCells . empty ( ) = = false ) {
2012-09-20 06:53:58 +02:00
const Texture2D * texture = game - > getMarkCellTexture ( ) ;
2015-01-04 14:38:32 +01:00
const int yOffset = - 40 ;
2012-09-20 06:53:58 +02:00
2012-06-12 22:37:00 +02:00
for ( std : : map < Vec2i , MarkedCell > : : iterator iterMap = markedCells . begin ( ) ;
iterMap ! = markedCells . end ( ) ; + + iterMap ) {
MarkedCell & bm = iterMap - > second ;
2012-09-25 09:05:52 +02:00
if ( bm . getPlayerIndex ( ) < 0 | |
( bm . getFaction ( ) ! = NULL & &
bm . getFaction ( ) - > getTeam ( ) = = game - > getWorld ( ) - > getThisFaction ( ) - > getTeam ( ) ) ) {
2012-06-12 22:37:00 +02:00
const Map * map = game - > getWorld ( ) - > getMap ( ) ;
std : : pair < bool , Vec3f > bmVisible = posInCellQuadCache (
map - > toSurfCoords ( bm . getTargetPos ( ) ) ) ;
if ( bmVisible . first = = true ) {
2012-09-20 06:10:34 +02:00
if ( renderTextHint = = true ) {
if ( bm . getNote ( ) ! = " " ) {
bool validPosObjWorld = x > bmVisible . second . x & &
2012-09-20 06:53:58 +02:00
y > bmVisible . second . y + yOffset & &
x < bmVisible . second . x + texture - > getTextureWidth ( ) & &
y < bmVisible . second . y + yOffset + texture - > getTextureHeight ( ) ;
2012-09-20 06:10:34 +02:00
if ( validPosObjWorld ) {
//printf("Checking for hint text render mouse [%d,%d] marker pos [%d,%d] validPosObjWorld = %d, hint [%s]\n",x,y,bm.getTargetPos().x,bm.getTargetPos().y,validPosObjWorld,bm.getNote().c_str());
//Lang &lang= Lang::getInstance();
Vec4f fontColor = Vec4f ( 1.0f , 1.0f , 1.0f , 0.25f ) ;
if ( renderText3DEnabled = = true ) {
renderTextShadow3D ( bm . getNote ( ) , CoreData : : getInstance ( ) . getConsoleFont3D ( ) , fontColor ,
bmVisible . second . x , bmVisible . second . y ) ;
}
else {
renderTextShadow ( bm . getNote ( ) , CoreData : : getInstance ( ) . getConsoleFont ( ) , fontColor ,
bmVisible . second . x , bmVisible . second . y ) ;
}
}
}
}
else {
2012-09-21 02:54:22 +02:00
/*
//texture 0
glTexEnvi ( GL_TEXTURE_ENV , GL_TEXTURE_ENV_MODE , GL_COMBINE ) ;
//set color to interpolation
glTexEnvi ( GL_TEXTURE_ENV , GL_COMBINE_RGB , GL_INTERPOLATE ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_SOURCE0_RGB , GL_TEXTURE ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_OPERAND0_RGB , GL_SRC_COLOR ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_SOURCE1_RGB , GL_TEXTURE1 ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_OPERAND1_RGB , GL_SRC_COLOR ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_SOURCE2_RGB , GL_TEXTURE ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_OPERAND2_RGB , GL_SRC_ALPHA ) ;
//set alpha to 1
glTexEnvi ( GL_TEXTURE_ENV , GL_COMBINE_ALPHA , GL_REPLACE ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_SOURCE0_ALPHA , GL_TEXTURE ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_OPERAND0_ALPHA , GL_SRC_ALPHA ) ;
//texture 1
glActiveTexture ( GL_TEXTURE1 ) ;
glMultiTexCoord2f ( GL_TEXTURE1 , 0.f , 0.f ) ;
glEnable ( GL_TEXTURE_2D ) ;
glBindTexture ( GL_TEXTURE_2D , static_cast < const Texture2DGl * > ( bm . getFaction ( ) - > getTexture ( ) ) - > getHandle ( ) ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_TEXTURE_ENV_MODE , GL_COMBINE ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_COMBINE_RGB , GL_MODULATE ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_SOURCE0_RGB , GL_PRIMARY_COLOR ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_OPERAND0_RGB , GL_SRC_COLOR ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_SOURCE1_RGB , GL_PREVIOUS ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_OPERAND1_RGB , GL_SRC_COLOR ) ;
//set alpha to 1
glTexEnvi ( GL_TEXTURE_ENV , GL_COMBINE_ALPHA , GL_REPLACE ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_SOURCE0_ALPHA , GL_PRIMARY_COLOR ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_OPERAND0_ALPHA , GL_SRC_ALPHA ) ;
glActiveTexture ( GL_TEXTURE0 ) ;
*/
glTexEnvi ( GL_TEXTURE_ENV , GL_TEXTURE_ENV_MODE , GL_MODULATE ) ;
glEnable ( GL_BLEND ) ;
glBlendFunc ( GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA ) ;
2012-09-25 09:05:52 +02:00
Vec3f color ( MarkedCell : : static_system_marker_color ) ;
if ( bm . getFaction ( ) ! = NULL ) {
color = bm . getFaction ( ) - > getTexture ( ) - > getPixmapConst ( ) - > getPixel3f ( 0 , 0 ) ;
}
2012-09-21 02:54:22 +02:00
2012-09-20 06:53:58 +02:00
renderTextureQuad (
bmVisible . second . x , bmVisible . second . y + yOffset ,
2012-09-25 09:05:52 +02:00
texture - > getTextureWidth ( ) , texture - > getTextureHeight ( ) , texture , 0.8f , & color ) ;
2012-09-21 02:54:22 +02:00
/*
glActiveTexture ( GL_TEXTURE1 ) ;
glDisable ( GL_TEXTURE_2D ) ;
glActiveTexture ( GL_TEXTURE0 ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_TEXTURE_ENV_MODE , GL_MODULATE ) ;
*/
2012-09-20 06:10:34 +02:00
}
2012-06-12 22:37:00 +02:00
}
}
}
}
}
2011-06-10 05:09:19 +02:00
void Renderer : : renderDisplay ( ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2010-03-13 22:10:45 +01:00
CoreData & coreData = CoreData : : getInstance ( ) ;
const Metrics & metrics = Metrics : : getInstance ( ) ;
const Display * display = game - > getGui ( ) - > getDisplay ( ) ;
glPushAttrib ( GL_ENABLE_BIT ) ;
2010-09-10 10:51:32 +02:00
2011-06-10 05:09:19 +02:00
if ( renderText3DEnabled = = true ) {
//infoString
renderTextShadow3D (
display - > getInfoText ( ) . c_str ( ) ,
coreData . getDisplayFont3D ( ) ,
display - > getColor ( ) ,
metrics . getDisplayX ( ) ,
metrics . getDisplayY ( ) + Display : : infoStringY ) ;
2010-03-13 22:10:45 +01:00
2011-06-10 05:09:19 +02:00
//title
renderTextShadow3D (
display - > getTitle ( ) . c_str ( ) ,
coreData . getDisplayFont3D ( ) ,
display - > getColor ( ) ,
metrics . getDisplayX ( ) + 40 ,
metrics . getDisplayY ( ) + metrics . getDisplayH ( ) - 20 ) ;
2010-03-13 22:10:45 +01:00
2011-06-10 05:09:19 +02:00
glColor3f ( 0.0f , 0.0f , 0.0f ) ;
2010-03-13 22:10:45 +01:00
2011-06-10 05:09:19 +02:00
//text
renderTextShadow3D (
display - > getText ( ) . c_str ( ) ,
coreData . getDisplayFont3D ( ) ,
display - > getColor ( ) ,
metrics . getDisplayX ( ) - 1 ,
2013-11-14 01:23:01 +01:00
metrics . getDisplayY ( ) + metrics . getDisplayH ( ) - 56 ) ;
2011-06-10 05:09:19 +02:00
//progress Bar
if ( display - > getProgressBar ( ) ! = - 1 ) {
renderProgressBar3D (
display - > getProgressBar ( ) ,
metrics . getDisplayX ( ) ,
metrics . getDisplayY ( ) + metrics . getDisplayH ( ) - 50 ,
2015-02-06 01:02:34 +01:00
coreData . getDisplayFontSmall3D ( ) , 175 ) ;
2011-06-10 05:09:19 +02:00
}
}
else {
//infoString
renderTextShadow (
display - > getInfoText ( ) . c_str ( ) ,
coreData . getDisplayFont ( ) ,
display - > getColor ( ) ,
2010-03-13 22:10:45 +01:00
metrics . getDisplayX ( ) ,
2011-06-10 05:09:19 +02:00
metrics . getDisplayY ( ) + Display : : infoStringY ) ;
//title
renderTextShadow (
display - > getTitle ( ) . c_str ( ) ,
coreData . getDisplayFont ( ) ,
display - > getColor ( ) ,
metrics . getDisplayX ( ) + 40 ,
metrics . getDisplayY ( ) + metrics . getDisplayH ( ) - 20 ) ;
glColor3f ( 0.0f , 0.0f , 0.0f ) ;
//text
renderTextShadow (
display - > getText ( ) . c_str ( ) ,
coreData . getDisplayFont ( ) ,
display - > getColor ( ) ,
metrics . getDisplayX ( ) - 1 ,
metrics . getDisplayY ( ) + metrics . getDisplayH ( ) - 56 ) ;
//progress Bar
if ( display - > getProgressBar ( ) ! = - 1 ) {
renderProgressBar (
display - > getProgressBar ( ) ,
metrics . getDisplayX ( ) ,
metrics . getDisplayY ( ) + metrics . getDisplayH ( ) - 50 ,
coreData . getDisplayFontSmall ( ) ) ;
}
2010-03-13 22:10:45 +01:00
}
//up images
glEnable ( GL_TEXTURE_2D ) ;
glColor3f ( 1.f , 1.f , 1.f ) ;
for ( int i = 0 ; i < Display : : upCellCount ; + + i ) {
if ( display - > getUpImage ( i ) ! = NULL ) {
renderQuad (
metrics . getDisplayX ( ) + display - > computeUpX ( i ) ,
metrics . getDisplayY ( ) + display - > computeUpY ( i ) ,
2011-02-25 01:31:42 +01:00
display - > getUpImageSize ( ) , display - > getUpImageSize ( ) , display - > getUpImage ( i ) ) ;
2010-03-13 22:10:45 +01:00
}
}
//down images
for ( int i = 0 ; i < Display : : downCellCount ; + + i ) {
if ( display - > getDownImage ( i ) ! = NULL ) {
2019-10-21 00:46:06 +02:00
Vec3f c = display - > getDownImageColor ( i ) ;
glColor3f ( c . x , c . y , c . z ) ;
2010-03-13 22:10:45 +01:00
int x = metrics . getDisplayX ( ) + display - > computeDownX ( i ) ;
int y = metrics . getDisplayY ( ) + display - > computeDownY ( i ) ;
int size = Display : : imageSize ;
if ( display - > getDownSelectedPos ( ) = = i ) {
x - = 3 ;
y - = 3 ;
size + = 6 ;
}
renderQuad ( x , y , size , size , display - > getDownImage ( i ) ) ;
}
}
//selection
int downPos = display - > getDownSelectedPos ( ) ;
if ( downPos ! = Display : : invalidPos ) {
const Texture2D * texture = display - > getDownImage ( downPos ) ;
if ( texture ! = NULL ) {
int x = metrics . getDisplayX ( ) + display - > computeDownX ( downPos ) - 3 ;
int y = metrics . getDisplayY ( ) + display - > computeDownY ( downPos ) - 3 ;
int size = Display : : imageSize + 6 ;
renderQuad ( x , y , size , size , display - > getDownImage ( downPos ) ) ;
}
}
glPopAttrib ( ) ;
}
2011-10-12 07:24:30 +02:00
void Renderer : : renderMenuBackground ( const MenuBackground * menuBackground ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2010-03-13 22:10:45 +01:00
assertGl ( ) ;
2010-06-23 16:49:20 +02:00
const Vec3f & cameraPosition = menuBackground - > getCamera ( ) - > getConstPosition ( ) ;
2010-03-13 22:10:45 +01:00
glPushAttrib ( GL_LIGHTING_BIT | GL_ENABLE_BIT | GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT ) ;
//clear
Vec4f fogColor = Vec4f ( 0.4f , 0.4f , 0.4f , 1.f ) * menuBackground - > getFade ( ) ;
glClearColor ( fogColor . x , fogColor . y , fogColor . z , 1.f ) ;
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ;
glFogfv ( GL_FOG_COLOR , fogColor . ptr ( ) ) ;
//light
Vec4f lightPos = Vec4f ( 10.f , 10.f , 10.f , 1.f ) * menuBackground - > getFade ( ) ;
Vec4f diffLight = Vec4f ( 0.9f , 0.9f , 0.9f , 1.f ) * menuBackground - > getFade ( ) ;
Vec4f ambLight = Vec4f ( 0.3f , 0.3f , 0.3f , 1.f ) * menuBackground - > getFade ( ) ;
Vec4f specLight = Vec4f ( 0.1f , 0.1f , 0.1f , 1.f ) * menuBackground - > getFade ( ) ;
glEnable ( GL_LIGHT0 ) ;
glLightfv ( GL_LIGHT0 , GL_POSITION , lightPos . ptr ( ) ) ;
glLightfv ( GL_LIGHT0 , GL_DIFFUSE , diffLight . ptr ( ) ) ;
glLightfv ( GL_LIGHT0 , GL_AMBIENT , ambLight . ptr ( ) ) ;
glLightfv ( GL_LIGHT0 , GL_SPECULAR , specLight . ptr ( ) ) ;
//main model
glEnable ( GL_ALPHA_TEST ) ;
glAlphaFunc ( GL_GREATER , 0.5f ) ;
2013-01-15 04:18:26 +01:00
modelRenderer - > begin ( true , true , true , false ) ;
2011-10-12 07:24:30 +02:00
menuBackground - > getMainModelPtr ( ) - > updateInterpolationData ( menuBackground - > getAnim ( ) , true ) ;
2011-01-19 00:56:30 +01:00
modelRenderer - > render ( menuBackground - > getMainModelPtr ( ) ) ;
2010-03-13 22:10:45 +01:00
modelRenderer - > end ( ) ;
glDisable ( GL_ALPHA_TEST ) ;
//characters
float dist = menuBackground - > getAboutPosition ( ) . dist ( cameraPosition ) ;
float minDist = 3.f ;
2010-09-10 10:51:32 +02:00
if ( dist < minDist ) {
2010-03-13 22:10:45 +01:00
glAlphaFunc ( GL_GREATER , 0.0f ) ;
2010-09-10 10:51:32 +02:00
float alpha = clamp ( ( minDist - dist ) / minDist , 0.f , 1.f ) ;
2010-03-13 22:10:45 +01:00
glMaterialfv ( GL_FRONT_AND_BACK , GL_AMBIENT_AND_DIFFUSE , Vec4f ( 1.0f , 1.0f , 1.0f , alpha ) . ptr ( ) ) ;
2011-11-15 05:48:57 +01:00
std : : vector < Vec3f > & characterMenuScreenPositionListCache =
CacheManager : : getCachedItem < std : : vector < Vec3f > > ( GameConstants : : characterMenuScreenPositionListCacheLookupKey ) ;
characterMenuScreenPositionListCache . clear ( ) ;
2013-01-15 04:18:26 +01:00
modelRenderer - > begin ( true , true , false , false ) ;
2010-03-13 22:10:45 +01:00
2010-09-10 10:51:32 +02:00
for ( int i = 0 ; i < MenuBackground : : characterCount ; + + i ) {
2010-03-13 22:10:45 +01:00
glMatrixMode ( GL_MODELVIEW ) ;
glPushMatrix ( ) ;
glLoadIdentity ( ) ;
2011-11-15 05:48:57 +01:00
Vec3f worldPos ( i * 2.f - 4.f , - 1.4f , - 7.5f ) ;
glTranslatef ( worldPos . x , worldPos . y , worldPos . z ) ;
//
// Get the screen coordinates for each character model - START
2011-11-15 07:37:47 +01:00
//std::vector<GLdouble> projection(16);
//std::vector<GLdouble> modelview(16);
//std::vector<GLdouble> screen_coords(3);
2011-11-15 05:48:57 +01:00
2011-11-15 07:37:47 +01:00
//glGetDoublev(GL_PROJECTION_MATRIX, projection.data());
//glGetDoublev(GL_MODELVIEW_MATRIX, modelview.data());
2011-11-15 05:48:57 +01:00
const Metrics & metrics = Metrics : : getInstance ( ) ;
GLint viewport [ ] = { 0 , 0 , metrics . getVirtualW ( ) , metrics . getVirtualH ( ) } ;
2011-11-15 07:37:47 +01:00
//get matrices
GLdouble projection [ 16 ] ;
glGetDoublev ( GL_PROJECTION_MATRIX , projection ) ;
GLdouble modelview [ 16 ] ;
glGetDoublev ( GL_MODELVIEW_MATRIX , modelview ) ;
//get the screen coordinates
GLdouble screen_coords [ 3 ] ;
2011-11-15 05:48:57 +01:00
gluProject ( worldPos . x , worldPos . y , worldPos . z ,
2011-11-15 07:37:47 +01:00
modelview , projection , viewport ,
& screen_coords [ 0 ] , & screen_coords [ 1 ] , & screen_coords [ 2 ] ) ;
2011-11-15 05:48:57 +01:00
characterMenuScreenPositionListCache . push_back ( Vec3f ( screen_coords [ 0 ] , screen_coords [ 1 ] , screen_coords [ 2 ] ) ) ;
// Get the screen coordinates for each character model - END
//
2011-01-18 08:52:06 +01:00
menuBackground - > getCharacterModelPtr ( i ) - > updateInterpolationData ( menuBackground - > getAnim ( ) , true ) ;
2011-01-19 00:56:30 +01:00
modelRenderer - > render ( menuBackground - > getCharacterModelPtr ( i ) ) ;
2011-11-15 05:48:57 +01:00
2010-03-13 22:10:45 +01:00
glPopMatrix ( ) ;
}
modelRenderer - > end ( ) ;
}
//water
2010-09-10 10:51:32 +02:00
if ( menuBackground - > getWater ( ) ) {
2010-03-13 22:10:45 +01:00
//water surface
const int waterTesselation = 10 ;
const int waterSize = 250 ;
const int waterQuadSize = 2 * waterSize / waterTesselation ;
const float waterHeight = menuBackground - > getWaterHeight ( ) ;
glEnable ( GL_BLEND ) ;
glNormal3f ( 0.f , 1.f , 0.f ) ;
glMaterialfv ( GL_FRONT_AND_BACK , GL_AMBIENT_AND_DIFFUSE , Vec4f ( 1.f , 1.f , 1.f , 1.f ) . ptr ( ) ) ;
GLuint waterHandle = static_cast < Texture2DGl * > ( menuBackground - > getWaterTexture ( ) ) - > getHandle ( ) ;
glBindTexture ( GL_TEXTURE_2D , waterHandle ) ;
2010-09-10 10:51:32 +02:00
for ( int i = 1 ; i < waterTesselation ; + + i ) {
2010-09-13 21:33:00 +02:00
glBegin ( GL_TRIANGLE_STRIP ) ;
for ( int j = 1 ; j < waterTesselation ; + + j ) {
2010-03-13 22:10:45 +01:00
glTexCoord2i ( 1 , 2 % j ) ;
2010-05-01 22:14:25 +02:00
glVertex3f ( - waterSize + i * waterQuadSize , waterHeight , - waterSize + j * waterQuadSize ) ;
2010-03-13 22:10:45 +01:00
glTexCoord2i ( 0 , 2 % j ) ;
2010-05-01 22:14:25 +02:00
glVertex3f ( - waterSize + ( i + 1 ) * waterQuadSize , waterHeight , - waterSize + j * waterQuadSize ) ;
2010-03-13 22:10:45 +01:00
}
2010-09-13 21:33:00 +02:00
glEnd ( ) ;
2010-03-13 22:10:45 +01:00
}
glDisable ( GL_BLEND ) ;
//raindrops
2010-09-10 10:51:32 +02:00
if ( menuBackground - > getRain ( ) ) {
2010-03-13 22:10:45 +01:00
const float maxRaindropAlpha = 0.5f ;
glEnable ( GL_BLEND ) ;
glDisable ( GL_LIGHTING ) ;
glDisable ( GL_ALPHA_TEST ) ;
glDepthMask ( GL_FALSE ) ;
//splashes
CoreData & coreData = CoreData : : getInstance ( ) ;
glBindTexture ( GL_TEXTURE_2D , static_cast < Texture2DGl * > ( coreData . getWaterSplashTexture ( ) ) - > getHandle ( ) ) ;
2010-09-10 10:51:32 +02:00
for ( int i = 0 ; i < MenuBackground : : raindropCount ; + + i ) {
2010-03-13 22:10:45 +01:00
Vec2f pos = menuBackground - > getRaindropPos ( i ) ;
float scale = menuBackground - > getRaindropState ( i ) ;
float alpha = maxRaindropAlpha - scale * maxRaindropAlpha ;
glMatrixMode ( GL_MODELVIEW ) ;
glPushMatrix ( ) ;
glColor4f ( 1.f , 1.f , 1.f , alpha ) ;
glTranslatef ( pos . x , waterHeight + 0.01f , pos . y ) ;
glBegin ( GL_TRIANGLE_STRIP ) ;
glTexCoord2f ( 0.f , 1.f ) ;
glVertex3f ( - scale , 0 , scale ) ;
glTexCoord2f ( 0.f , 0.f ) ;
glVertex3f ( - scale , 0 , - scale ) ;
glTexCoord2f ( 1.f , 1.f ) ;
glVertex3f ( scale , 0 , scale ) ;
glTexCoord2f ( 1.f , 0.f ) ;
glVertex3f ( scale , 0 , - scale ) ;
glEnd ( ) ;
glPopMatrix ( ) ;
}
}
}
glPopAttrib ( ) ;
assertGl ( ) ;
}
2011-10-12 07:24:30 +02:00
void Renderer : : renderMenuBackground ( Camera * camera , float fade , Model * mainModel , vector < Model * > characterModels , const Vec3f characterPosition , float anim ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2011-10-12 07:24:30 +02:00
assertGl ( ) ;
const Vec3f & cameraPosition = camera - > getConstPosition ( ) ;
glPushAttrib ( GL_LIGHTING_BIT | GL_ENABLE_BIT | GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT ) ;
//clear
//Vec4f fogColor= Vec4f(0.4f, 0.4f, 0.4f, 1.f) * fade;
// Show black bacground
Vec4f fogColor = Vec4f ( 0.f , 0.f , 0.f , 1.f ) ;
glClearColor ( fogColor . x , fogColor . y , fogColor . z , 1.f ) ;
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ;
glFogfv ( GL_FOG_COLOR , fogColor . ptr ( ) ) ;
//light
Vec4f lightPos = Vec4f ( 10.f , 10.f , 10.f , 1.f ) * fade ;
Vec4f diffLight = Vec4f ( 0.9f , 0.9f , 0.9f , 1.f ) * fade ;
Vec4f ambLight = Vec4f ( 0.3f , 0.3f , 0.3f , 1.f ) * fade ;
Vec4f specLight = Vec4f ( 0.1f , 0.1f , 0.1f , 1.f ) * fade ;
glEnable ( GL_LIGHT0 ) ;
glLightfv ( GL_LIGHT0 , GL_POSITION , lightPos . ptr ( ) ) ;
glLightfv ( GL_LIGHT0 , GL_DIFFUSE , diffLight . ptr ( ) ) ;
glLightfv ( GL_LIGHT0 , GL_AMBIENT , ambLight . ptr ( ) ) ;
glLightfv ( GL_LIGHT0 , GL_SPECULAR , specLight . ptr ( ) ) ;
//main model
if ( mainModel ) {
glEnable ( GL_ALPHA_TEST ) ;
glAlphaFunc ( GL_GREATER , 0.5f ) ;
2013-01-15 04:18:26 +01:00
modelRenderer - > begin ( true , true , true , false ) ;
2011-10-12 07:24:30 +02:00
mainModel - > updateInterpolationData ( anim , true ) ;
modelRenderer - > render ( mainModel ) ;
modelRenderer - > end ( ) ;
glDisable ( GL_ALPHA_TEST ) ;
}
//characters
2011-12-02 17:07:59 +01:00
if ( characterModels . empty ( ) = = false ) {
2011-10-12 07:24:30 +02:00
float dist = characterPosition . dist ( cameraPosition ) ;
float minDist = 3.f ;
if ( dist < minDist ) {
glAlphaFunc ( GL_GREATER , 0.0f ) ;
float alpha = clamp ( ( minDist - dist ) / minDist , 0.f , 1.f ) ;
glMaterialfv ( GL_FRONT_AND_BACK , GL_AMBIENT_AND_DIFFUSE , Vec4f ( 1.0f , 1.0f , 1.0f , alpha ) . ptr ( ) ) ;
2013-01-15 04:18:26 +01:00
modelRenderer - > begin ( true , true , false , false ) ;
2011-10-12 07:24:30 +02:00
for ( unsigned int i = 0 ; i < characterModels . size ( ) ; + + i ) {
if ( characterModels [ i ] ) {
glMatrixMode ( GL_MODELVIEW ) ;
glPushMatrix ( ) ;
glLoadIdentity ( ) ;
glTranslatef ( i * 2.f - 4.f , - 1.4f , - 7.5f ) ;
characterModels [ i ] - > updateInterpolationData ( anim , true ) ;
modelRenderer - > render ( characterModels [ i ] ) ;
glPopMatrix ( ) ;
}
}
modelRenderer - > end ( ) ;
}
}
glPopAttrib ( ) ;
assertGl ( ) ;
}
2010-03-13 22:10:45 +01:00
// ==================== computing ====================
2015-01-04 14:38:32 +01:00
bool Renderer : : ccomputePosition ( const Vec2i & screenPos , Vec2i & worldPos , bool exactCoords ) {
2010-03-13 22:10:45 +01:00
assertGl ( ) ;
const Map * map = game - > getWorld ( ) - > getMap ( ) ;
const Metrics & metrics = Metrics : : getInstance ( ) ;
float depth = 0.0f ;
GLdouble modelviewMatrix [ 16 ] ;
GLdouble projectionMatrix [ 16 ] ;
GLint viewport [ 4 ] = { 0 , 0 , metrics . getScreenW ( ) , metrics . getScreenH ( ) } ;
GLdouble worldX ;
GLdouble worldY ;
GLdouble worldZ ;
GLint screenX = ( screenPos . x * metrics . getScreenW ( ) / metrics . getVirtualW ( ) ) ;
GLint screenY = ( screenPos . y * metrics . getScreenH ( ) / metrics . getVirtualH ( ) ) ;
//get the depth in the cursor pixel
glReadPixels ( screenX , screenY , 1 , 1 , GL_DEPTH_COMPONENT , GL_FLOAT , & depth ) ;
//load matrices
loadProjectionMatrix ( ) ;
loadGameCameraMatrix ( ) ;
//get matrices
glGetDoublev ( GL_MODELVIEW_MATRIX , modelviewMatrix ) ;
glGetDoublev ( GL_PROJECTION_MATRIX , projectionMatrix ) ;
//get the world coordinates
gluUnProject (
screenX , screenY , depth ,
modelviewMatrix , projectionMatrix , viewport ,
& worldX , & worldY , & worldZ ) ;
//conver coords to int
2012-06-12 22:37:00 +02:00
if ( exactCoords = = true ) {
worldPos = Vec2i ( static_cast < int > ( worldX ) , static_cast < int > ( worldZ ) ) ;
}
else {
worldPos = Vec2i ( static_cast < int > ( worldX + 0.5f ) , static_cast < int > ( worldZ + 0.5f ) ) ;
}
2010-03-13 22:10:45 +01:00
//clamp coords to map size
return map - > isInside ( worldPos ) ;
}
2010-05-29 07:41:40 +02:00
// This method takes world co-ordinates and translates them to screen co-ords
Vec3f Renderer : : computeScreenPosition ( const Vec3f & worldPos ) {
2012-06-22 15:30:15 +02:00
if ( worldToScreenPosCache . find ( worldPos ) ! = worldToScreenPosCache . end ( ) ) {
return worldToScreenPosCache [ worldPos ] ;
}
2010-05-29 07:41:40 +02:00
assertGl ( ) ;
const Metrics & metrics = Metrics : : getInstance ( ) ;
GLint viewport [ ] = { 0 , 0 , metrics . getVirtualW ( ) , metrics . getVirtualH ( ) } ;
GLdouble worldX = worldPos . x ;
GLdouble worldY = worldPos . y ;
GLdouble worldZ = worldPos . z ;
//load matrices
loadProjectionMatrix ( ) ;
loadGameCameraMatrix ( ) ;
//get matrices
GLdouble modelviewMatrix [ 16 ] ;
glGetDoublev ( GL_MODELVIEW_MATRIX , modelviewMatrix ) ;
GLdouble projectionMatrix [ 16 ] ;
glGetDoublev ( GL_PROJECTION_MATRIX , projectionMatrix ) ;
//get the screen coordinates
GLdouble screenX ;
GLdouble screenY ;
GLdouble screenZ ;
gluProject ( worldX , worldY , worldZ ,
modelviewMatrix , projectionMatrix , viewport ,
& screenX , & screenY , & screenZ ) ;
Vec3f screenPos ( screenX , screenY , screenZ ) ;
2012-06-22 15:30:15 +02:00
worldToScreenPosCache [ worldPos ] = screenPos ;
2010-11-02 20:52:20 +01:00
2010-05-29 07:41:40 +02:00
return screenPos ;
}
2011-12-13 02:30:52 +01:00
void Renderer : : computeSelected ( Selection : : UnitContainer & units , const Object * & obj ,
const bool withObjectSelection ,
2010-09-10 10:51:32 +02:00
const Vec2i & posDown , const Vec2i & posUp ) {
2013-06-20 23:42:01 +02:00
const string selectionType = toLower ( Config : : getInstance ( ) . getString ( " SelectionType " , Config : : colorPicking ) ) ;
2011-12-14 03:25:14 +01:00
2013-01-27 23:10:24 +01:00
if ( selectionType = = Config : : colorPicking ) {
2011-12-14 03:25:14 +01:00
selectUsingColorPicking ( units , obj , withObjectSelection , posDown , posUp ) ;
}
2013-02-11 23:51:36 +01:00
/// Frustum approach --> Currently not accurate enough
else if ( selectionType = = Config : : frustumPicking ) {
2011-12-14 03:25:14 +01:00
selectUsingFrustumSelection ( units , obj , withObjectSelection , posDown , posUp ) ;
}
else {
selectUsingSelectionBuffer ( units , obj , withObjectSelection , posDown , posUp ) ;
}
}
void Renderer : : selectUsingFrustumSelection ( Selection : : UnitContainer & units ,
const Object * & obj , const bool withObjectSelection ,
const Vec2i & posDown , const Vec2i & posUp ) {
glMatrixMode ( GL_PROJECTION ) ;
glPushMatrix ( ) ;
glLoadIdentity ( ) ;
2010-03-13 22:10:45 +01:00
const Metrics & metrics = Metrics : : getInstance ( ) ;
2011-12-14 03:25:14 +01:00
GLint view [ ] = { 0 , 0 , metrics . getVirtualW ( ) , metrics . getVirtualH ( ) } ;
2010-03-13 22:10:45 +01:00
//compute center and dimensions of selection rectangle
2011-12-13 02:30:52 +01:00
int x = ( posDown . x + posUp . x ) / 2 ;
int y = ( posDown . y + posUp . y ) / 2 ;
int w = abs ( posDown . x - posUp . x ) ;
int h = abs ( posDown . y - posUp . y ) ;
2013-04-27 19:38:35 +02:00
if ( w < 2 ) {
w = 2 ;
2011-12-13 02:30:52 +01:00
}
2013-04-27 19:38:35 +02:00
if ( h < 2 ) {
h = 2 ;
2011-12-13 02:30:52 +01:00
}
2011-12-14 03:25:14 +01:00
gluPickMatrix ( x , y , w , h , view ) ;
gluPerspective ( perspFov , metrics . getAspectRatio ( ) , perspNearPlane , perspFarPlane ) ;
loadGameCameraMatrix ( ) ;
2010-03-13 22:10:45 +01:00
2011-12-14 03:25:14 +01:00
VisibleQuadContainerCache quadSelectionCacheItem ;
ExtractFrustum ( quadSelectionCacheItem ) ;
2011-12-13 02:30:52 +01:00
2011-12-14 03:25:14 +01:00
//pop matrices
glMatrixMode ( GL_PROJECTION ) ;
glPopMatrix ( ) ;
2011-12-13 02:30:52 +01:00
2011-12-14 03:25:14 +01:00
VisibleQuadContainerCache & qCache = getQuadCache ( ) ;
if ( qCache . visibleQuadUnitList . empty ( ) = = false ) {
for ( int visibleUnitIndex = 0 ;
2013-11-19 07:14:06 +01:00
visibleUnitIndex < ( int ) qCache . visibleQuadUnitList . size ( ) ; + + visibleUnitIndex ) {
2011-12-14 03:25:14 +01:00
Unit * unit = qCache . visibleQuadUnitList [ visibleUnitIndex ] ;
if ( unit ! = NULL & & unit - > isAlive ( ) ) {
2014-11-25 23:40:47 +01:00
Vec3f unitPos = unit - > getCurrMidHeightVector ( ) ;
2011-12-14 03:25:14 +01:00
bool insideQuad = CubeInFrustum ( quadSelectionCacheItem . frustumData ,
2013-12-30 16:19:08 +01:00
unitPos . x , unitPos . y , unitPos . z , unit - > getType ( ) - > getRenderSize ( ) ) ;
2011-12-14 03:25:14 +01:00
if ( insideQuad = = true ) {
units . push_back ( unit ) ;
}
}
2011-12-13 02:30:52 +01:00
}
2011-12-14 03:25:14 +01:00
}
2011-12-13 02:30:52 +01:00
2011-12-14 03:25:14 +01:00
if ( withObjectSelection = = true ) {
if ( qCache . visibleObjectList . empty ( ) = = false ) {
for ( int visibleIndex = 0 ;
2013-11-19 07:14:06 +01:00
visibleIndex < ( int ) qCache . visibleObjectList . size ( ) ; + + visibleIndex ) {
2011-12-14 03:25:14 +01:00
Object * object = qCache . visibleObjectList [ visibleIndex ] ;
if ( object ! = NULL ) {
bool insideQuad = CubeInFrustum ( quadSelectionCacheItem . frustumData ,
object - > getPos ( ) . x , object - > getPos ( ) . y , object - > getPos ( ) . z , 1 ) ;
if ( insideQuad = = true ) {
2011-12-13 02:30:52 +01:00
obj = object ;
2017-10-10 04:09:36 +02:00
//if(withObjectSelection == true) {
break ;
//}
2011-12-13 02:30:52 +01:00
}
}
2011-02-13 15:35:17 +01:00
}
2011-12-13 02:30:52 +01:00
}
2011-12-14 03:25:14 +01:00
}
}
2011-12-13 02:30:52 +01:00
2011-12-14 03:25:14 +01:00
void Renderer : : selectUsingSelectionBuffer ( Selection : : UnitContainer & units ,
const Object * & obj , const bool withObjectSelection ,
const Vec2i & posDown , const Vec2i & posUp ) {
//compute center and dimensions of selection rectangle
int x = ( posDown . x + posUp . x ) / 2 ;
int y = ( posDown . y + posUp . y ) / 2 ;
int w = abs ( posDown . x - posUp . x ) ;
int h = abs ( posDown . y - posUp . y ) ;
2013-04-27 19:38:35 +02:00
if ( w < 2 ) {
w = 2 ;
2011-12-14 03:25:14 +01:00
}
2013-04-27 19:38:35 +02:00
if ( h < 2 ) {
h = 2 ;
2011-12-14 03:25:14 +01:00
}
2011-12-13 02:30:52 +01:00
2011-12-14 03:25:14 +01:00
//declarations
GLuint selectBuffer [ Gui : : maxSelBuff ] ;
2011-12-13 02:30:52 +01:00
2011-12-14 03:25:14 +01:00
//setup matrices
glSelectBuffer ( Gui : : maxSelBuff , selectBuffer ) ;
2012-11-15 08:28:48 +01:00
//glMatrixMode(GL_PROJECTION);
//glPushMatrix();
2011-12-13 02:30:52 +01:00
2011-12-14 03:25:14 +01:00
GLint renderModeResult = glRenderMode ( GL_SELECT ) ;
if ( renderModeResult < 0 ) {
const char * errorString = reinterpret_cast < const char * > ( gluErrorString ( renderModeResult ) ) ;
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " OpenGL error #%d [0x%X] : [%s] at file: [%s], line: %d " , renderModeResult , renderModeResult , errorString , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __LINE__ ) ;
2011-12-13 02:30:52 +01:00
2011-12-14 03:25:14 +01:00
printf ( " %s \n " , szBuf ) ;
}
2012-11-15 08:28:48 +01:00
2013-06-04 01:09:02 +02:00
2012-11-15 08:28:48 +01:00
glPushMatrix ( ) ;
2013-06-04 01:09:02 +02:00
glMatrixMode ( GL_PROJECTION ) ;
2012-11-15 08:28:48 +01:00
2011-12-14 03:25:14 +01:00
glLoadIdentity ( ) ;
2011-12-13 02:30:52 +01:00
2011-12-14 03:25:14 +01:00
const Metrics & metrics = Metrics : : getInstance ( ) ;
GLint view [ ] = { 0 , 0 , metrics . getVirtualW ( ) , metrics . getVirtualH ( ) } ;
2012-11-15 08:28:48 +01:00
//GLint view[4];
//glGetIntegerv(GL_VIEWPORT, view);
2011-12-14 03:25:14 +01:00
gluPickMatrix ( x , y , w , h , view ) ;
2012-11-15 15:45:22 +01:00
gluPerspective ( perspFov , metrics . getAspectRatio ( ) , perspNearPlane , perspFarPlane ) ;
//gluPerspective(perspFov, metrics.getAspectRatio(), 0.0001, 1000.0);
2012-11-15 08:28:48 +01:00
//gluPerspective(perspFov, (float)view[2]/(float)view[3], perspNearPlane, perspFarPlane);
2011-12-14 03:25:14 +01:00
loadGameCameraMatrix ( ) ;
2011-12-13 02:30:52 +01:00
2011-12-14 03:25:14 +01:00
//render units to find which ones should be selected
renderUnitsFast ( ) ;
if ( withObjectSelection = = true ) {
renderObjectsFast ( false , true ) ;
}
2011-12-13 02:30:52 +01:00
2011-12-14 03:25:14 +01:00
//pop matrices
glPopMatrix ( ) ;
2011-12-13 02:30:52 +01:00
2011-12-14 03:25:14 +01:00
// Added this to ensure all the selection calls are done now
// (see http://www.unknownroad.com/rtfm/graphics/glselection.html section: [0x4])
2012-11-15 08:28:48 +01:00
//glFlush();
2011-12-13 02:30:52 +01:00
2011-12-14 03:25:14 +01:00
//select units by checking the selected buffer
int selCount = glRenderMode ( GL_RENDER ) ;
if ( selCount > 0 ) {
2011-12-13 02:30:52 +01:00
VisibleQuadContainerCache & qCache = getQuadCache ( ) ;
2011-12-14 03:25:14 +01:00
for ( int i = 1 ; i < = selCount ; + + i ) {
int index = selectBuffer [ i * 4 - 1 ] ;
if ( index > = OBJECT_SELECT_OFFSET ) {
Object * object = qCache . visibleObjectList [ index - OBJECT_SELECT_OFFSET ] ;
if ( object ! = NULL ) {
obj = object ;
if ( withObjectSelection = = true ) {
break ;
2011-12-13 02:30:52 +01:00
}
}
}
2011-12-14 03:25:14 +01:00
else {
Unit * unit = qCache . visibleQuadUnitList [ index ] ;
if ( unit ! = NULL & & unit - > isAlive ( ) ) {
units . push_back ( unit ) ;
2011-12-13 02:30:52 +01:00
}
}
}
2011-12-14 03:25:14 +01:00
}
else if ( selCount < 0 ) {
const char * errorString = reinterpret_cast < const char * > ( gluErrorString ( selCount ) ) ;
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " OpenGL error #%d [0x%X] : [%s] at file: [%s], line: %d " , selCount , selCount , errorString , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __LINE__ ) ;
2011-12-13 02:30:52 +01:00
2011-12-14 03:25:14 +01:00
printf ( " %s \n " , szBuf ) ;
2011-12-13 02:30:52 +01:00
}
2011-12-14 03:25:14 +01:00
}
2011-12-13 02:30:52 +01:00
2011-12-14 03:25:14 +01:00
void Renderer : : selectUsingColorPicking ( Selection : : UnitContainer & units ,
const Object * & obj , const bool withObjectSelection ,
const Vec2i & posDown , const Vec2i & posUp ) {
2013-01-22 05:30:06 +01:00
int x1 = posDown . x ;
int y1 = posDown . y ;
int x2 = posUp . x ;
int y2 = posUp . y ;
int x = min ( x1 , x2 ) ;
int y = min ( y1 , y2 ) ;
int w = max ( x1 , x2 ) - min ( x1 , x2 ) ;
int h = max ( y1 , y2 ) - min ( y1 , y2 ) ;
2013-04-27 19:38:35 +02:00
if ( w < 2 ) {
w = 2 ;
2013-01-22 05:30:06 +01:00
}
2013-04-27 19:38:35 +02:00
if ( h < 2 ) {
h = 2 ;
2013-01-22 05:30:06 +01:00
}
const Metrics & metrics = Metrics : : getInstance ( ) ;
x = ( x * metrics . getScreenW ( ) / metrics . getVirtualW ( ) ) ;
y = ( y * metrics . getScreenH ( ) / metrics . getVirtualH ( ) ) ;
w = ( w * metrics . getScreenW ( ) / metrics . getVirtualW ( ) ) ;
h = ( h * metrics . getScreenH ( ) / metrics . getVirtualH ( ) ) ;
PixelBufferWrapper : : begin ( ) ;
2013-06-04 01:09:02 +02:00
2013-01-22 05:30:06 +01:00
glPushMatrix ( ) ;
2013-06-04 01:09:02 +02:00
glMatrixMode ( GL_PROJECTION ) ;
2013-01-22 05:30:06 +01:00
glLoadIdentity ( ) ;
//GLint view[]= {0, 0, metrics.getVirtualW(), metrics.getVirtualH()};
//gluPickMatrix(x, y, w, h, view);
gluPerspective ( perspFov , metrics . getAspectRatio ( ) , perspNearPlane , perspFarPlane ) ;
loadGameCameraMatrix ( ) ;
2013-01-24 16:52:11 +01:00
//render units to find which ones should be selected
//printf("In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2013-01-22 05:30:06 +01:00
vector < Unit * > rendererUnits = renderUnitsFast ( false , true ) ;
2013-01-24 16:52:11 +01:00
//printf("In [%s::%s] Line: %d rendererUnits = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,rendererUnits.size());
2013-01-22 05:30:06 +01:00
// Added this to ensure all the selection calls are done now
// (see http://www.unknownroad.com/rtfm/graphics/glselection.html section: [0x4])
2013-01-23 22:53:02 +01:00
//glFlush();
2013-01-22 05:30:06 +01:00
//GraphicsInterface::getInstance().getCurrentContext()->swapBuffers();
PixelBufferWrapper : : end ( ) ;
2013-04-25 01:06:11 +02:00
vector < BaseColorPickEntity * > unitsVector ;
bool unitFound = false ;
2013-01-22 05:30:06 +01:00
if ( rendererUnits . empty ( ) = = false ) {
2013-04-25 01:06:11 +02:00
copy ( rendererUnits . begin ( ) , rendererUnits . end ( ) , std : : inserter ( unitsVector , unitsVector . begin ( ) ) ) ;
2013-01-22 05:30:06 +01:00
}
2013-04-25 01:06:11 +02:00
if ( unitsVector . empty ( ) = = false ) {
vector < int > pickedList = BaseColorPickEntity : : getPickedList ( x , y , w , h , unitsVector ) ;
2013-01-24 16:52:11 +01:00
//printf("In [%s::%s] Line: %d pickedList = %d models rendered = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,pickedList.size(),rendererModels.size());
if ( pickedList . empty ( ) = = false ) {
units . reserve ( pickedList . size ( ) ) ;
for ( unsigned int i = 0 ; i < pickedList . size ( ) ; + + i ) {
int index = pickedList [ i ] ;
//printf("In [%s::%s] Line: %d searching for selected object i = %d index = %d units = %d objects = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,i,index,rendererUnits.size(),rendererObjects.size());
2013-01-22 05:30:06 +01:00
2013-11-19 07:14:06 +01:00
if ( rendererUnits . empty ( ) = = false & & index < ( int ) rendererUnits . size ( ) ) {
2013-01-24 16:52:11 +01:00
Unit * unit = rendererUnits [ index ] ;
if ( unit ! = NULL & & unit - > isAlive ( ) ) {
2013-04-25 01:06:11 +02:00
unitFound = true ;
2013-01-24 16:52:11 +01:00
units . push_back ( unit ) ;
}
}
2013-01-22 05:30:06 +01:00
}
}
}
2013-04-25 01:06:11 +02:00
if ( withObjectSelection = = true & & unitFound = = false ) {
vector < Object * > rendererObjects ;
vector < BaseColorPickEntity * > objectsVector ;
rendererObjects = renderObjectsFast ( false , true , true ) ;
if ( rendererObjects . empty ( ) = = false ) {
copy ( rendererObjects . begin ( ) , rendererObjects . end ( ) , std : : inserter ( objectsVector , objectsVector . begin ( ) ) ) ;
}
if ( objectsVector . empty ( ) = = false ) {
vector < int > pickedList = BaseColorPickEntity : : getPickedList ( x , y , w , h , objectsVector ) ;
//printf("In [%s::%s] Line: %d pickedList = %d models rendered = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,pickedList.size(),rendererModels.size());
if ( pickedList . empty ( ) = = false ) {
for ( unsigned int i = 0 ; i < pickedList . size ( ) ; + + i ) {
int index = pickedList [ i ] ;
//printf("In [%s::%s] Line: %d searching for selected object i = %d index = %d units = %d objects = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,i,index,rendererUnits.size(),rendererObjects.size());
2013-11-19 07:14:06 +01:00
if ( rendererObjects . empty ( ) = = false & & index < ( int ) rendererObjects . size ( ) ) {
2013-04-25 01:06:11 +02:00
Object * object = rendererObjects [ index ] ;
//printf("In [%s::%s] Line: %d searching for selected object i = %d index = %d [%p]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,i,index,object);
if ( object ! = NULL ) {
obj = object ;
2013-04-26 01:12:34 +02:00
break ;
2013-04-25 01:06:11 +02:00
}
}
}
}
}
}
//pop matrices
glPopMatrix ( ) ;
2010-03-13 22:10:45 +01:00
}
// ==================== shadows ====================
2010-06-15 18:27:52 +02:00
void Renderer : : renderShadowsToTexture ( const int renderFps ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2011-04-18 21:48:05 +02:00
if ( shadowsOffDueToMinRender = = false & &
2010-09-10 10:51:32 +02:00
( shadows = = sProjected | | shadows = = sShadowMapping ) ) {
2010-07-07 20:50:55 +02:00
2010-07-06 08:30:49 +02:00
shadowMapFrame = ( shadowMapFrame + 1 ) % ( shadowFrameSkip + 1 ) ;
2010-03-13 22:10:45 +01:00
2010-09-10 10:51:32 +02:00
if ( shadowMapFrame = = 0 ) {
2010-07-06 08:30:49 +02:00
assertGl ( ) ;
2010-03-13 22:10:45 +01:00
2010-07-06 08:30:49 +02:00
glPushAttrib ( GL_ENABLE_BIT | GL_CURRENT_BIT | GL_COLOR_BUFFER_BIT | GL_VIEWPORT_BIT | GL_POLYGON_BIT ) ;
2010-03-13 22:10:45 +01:00
2011-04-18 21:48:05 +02:00
if ( shadows = = sShadowMapping ) {
2010-07-06 08:30:49 +02:00
glClear ( GL_DEPTH_BUFFER_BIT ) ;
}
2011-04-18 21:48:05 +02:00
else {
2013-09-22 15:55:20 +02:00
float color = 1.0f - shadowIntensity ;
2010-07-06 08:30:49 +02:00
glColor3f ( color , color , color ) ;
glClearColor ( 1.f , 1.f , 1.f , 1.f ) ;
glDisable ( GL_DEPTH_TEST ) ;
glClear ( GL_COLOR_BUFFER_BIT ) ;
}
2010-03-13 22:10:45 +01:00
2011-04-18 21:48:05 +02:00
//assertGl();
2010-07-06 08:30:49 +02:00
//clear color buffer
//
//set viewport, we leave one texel always in white to avoid problems
glViewport ( 1 , 1 , shadowTextureSize - 2 , shadowTextureSize - 2 ) ;
2010-05-06 23:29:46 +02:00
2011-04-18 21:48:05 +02:00
//assertGl();
if ( nearestLightPos . w = = 0.f ) {
2010-07-06 08:30:49 +02:00
//directional light
2010-03-13 22:10:45 +01:00
2010-07-06 08:30:49 +02:00
//light pos
assert ( game ! = NULL ) ;
assert ( game - > getWorld ( ) ! = NULL ) ;
const TimeFlow * tf = game - > getWorld ( ) - > getTimeFlow ( ) ;
assert ( tf ! = NULL ) ;
float ang = tf - > isDay ( ) ? computeSunAngle ( tf - > getTime ( ) ) : computeMoonAngle ( tf - > getTime ( ) ) ;
ang = radToDeg ( ang ) ;
2010-03-13 22:10:45 +01:00
2010-07-06 08:30:49 +02:00
//push and set projection
glMatrixMode ( GL_PROJECTION ) ;
glPushMatrix ( ) ;
glLoadIdentity ( ) ;
2011-04-18 21:48:05 +02:00
//assertGl();
2010-07-06 08:30:49 +02:00
if ( game - > getGameCamera ( ) - > getState ( ) = = GameCamera : : sGame ) {
2010-10-29 02:46:54 +02:00
//glOrtho(-35, 5, -15, 15, -1000, 1000);
//glOrtho(-30, 30, -20, 20, -1000, 1000);
glOrtho ( - 30 , 5 , - 20 , 20 , - 1000 , 1000 ) ;
2010-06-15 18:27:52 +02:00
}
else {
2010-07-06 08:30:49 +02:00
glOrtho ( - 30 , 30 , - 20 , 20 , - 1000 , 1000 ) ;
2010-06-15 18:27:52 +02:00
}
2010-03-13 22:10:45 +01:00
2011-04-18 21:48:05 +02:00
//assertGl();
2010-07-06 08:30:49 +02:00
//push and set modelview
glMatrixMode ( GL_MODELVIEW ) ;
glPushMatrix ( ) ;
glLoadIdentity ( ) ;
2010-06-15 18:27:52 +02:00
2010-07-06 08:30:49 +02:00
glRotatef ( 15 , 0 , 1 , 0 ) ;
2010-03-13 22:10:45 +01:00
2010-07-06 08:30:49 +02:00
glRotatef ( ang , 1 , 0 , 0 ) ;
glRotatef ( 90 , 0 , 1 , 0 ) ;
2010-08-21 20:50:56 +02:00
const Vec3f & pos = game - > getGameCamera ( ) - > getPos ( ) ;
2010-03-13 22:10:45 +01:00
2010-07-06 08:30:49 +02:00
glTranslatef ( static_cast < int > ( - pos . x ) , 0 , static_cast < int > ( - pos . z ) ) ;
2011-04-18 21:48:05 +02:00
//assertGl();
2010-07-06 08:30:49 +02:00
}
2011-04-18 21:48:05 +02:00
else {
2010-07-06 08:30:49 +02:00
//non directional light
2010-03-13 22:10:45 +01:00
2010-07-06 08:30:49 +02:00
//push projection
glMatrixMode ( GL_PROJECTION ) ;
glPushMatrix ( ) ;
glLoadIdentity ( ) ;
2011-04-18 21:48:05 +02:00
//assertGl();
2010-10-29 02:46:54 +02:00
gluPerspective ( perspFov , 1.f , perspNearPlane , perspFarPlane ) ;
//const Metrics &metrics= Metrics::getInstance();
//gluPerspective(perspFov, metrics.getAspectRatio(), perspNearPlane, perspFarPlane);
2010-05-06 23:29:46 +02:00
2011-04-18 21:48:05 +02:00
assertGl ( ) ;
2010-07-06 08:30:49 +02:00
//push modelview
glMatrixMode ( GL_MODELVIEW ) ;
glPushMatrix ( ) ;
glLoadIdentity ( ) ;
glRotatef ( - 90 , - 1 , 0 , 0 ) ;
glTranslatef ( - nearestLightPos . x , - nearestLightPos . y - 2 , - nearestLightPos . z ) ;
2011-04-18 21:48:05 +02:00
//assertGl();
2010-07-06 08:30:49 +02:00
}
2010-03-13 22:10:45 +01:00
2010-09-10 10:51:32 +02:00
if ( shadows = = sShadowMapping ) {
2010-07-06 08:30:49 +02:00
glEnable ( GL_POLYGON_OFFSET_FILL ) ;
2011-03-05 15:34:36 +01:00
glPolygonOffset ( 1.0f , 16.0f ) ;
2011-04-18 21:48:05 +02:00
//assertGl();
2010-07-06 08:30:49 +02:00
}
2010-05-06 23:29:46 +02:00
2010-07-06 08:30:49 +02:00
//render 3d
2010-09-26 01:03:27 +02:00
renderUnitsFast ( true ) ;
2011-02-13 15:35:17 +01:00
renderObjectsFast ( true , false ) ;
2010-03-13 22:10:45 +01:00
2011-04-18 21:48:05 +02:00
//assertGl();
2010-07-06 08:30:49 +02:00
//read color buffer
glBindTexture ( GL_TEXTURE_2D , shadowMapHandle ) ;
2011-04-18 21:48:05 +02:00
assertGl ( ) ;
2010-07-06 08:30:49 +02:00
glCopyTexSubImage2D ( GL_TEXTURE_2D , 0 , 0 , 0 , 0 , 0 , shadowTextureSize , shadowTextureSize ) ;
2011-04-18 21:48:05 +02:00
GLenum error = glGetError ( ) ;
// This error can happen when a Linux user switches from an X session
// back to a running game, and 'seems' to be safe to ignore it
if ( error ! = GL_INVALID_OPERATION ) {
assertGlWithErrorNumber ( error ) ;
}
2010-03-13 22:10:45 +01:00
2010-07-06 08:30:49 +02:00
//get elemental matrices
2010-08-21 21:04:09 +02:00
static Matrix4f matrix1 ;
static bool matrix1Populate = true ;
if ( matrix1Populate = = true ) {
matrix1Populate = false ;
matrix1 [ 0 ] = 0.5f ; matrix1 [ 4 ] = 0.f ; matrix1 [ 8 ] = 0.f ; matrix1 [ 12 ] = 0.5f ;
matrix1 [ 1 ] = 0.f ; matrix1 [ 5 ] = 0.5f ; matrix1 [ 9 ] = 0.f ; matrix1 [ 13 ] = 0.5f ;
matrix1 [ 2 ] = 0.f ; matrix1 [ 6 ] = 0.f ; matrix1 [ 10 ] = 0.5f ; matrix1 [ 14 ] = 0.5f ;
matrix1 [ 3 ] = 0.f ; matrix1 [ 7 ] = 0.f ; matrix1 [ 11 ] = 0.f ; matrix1 [ 15 ] = 1.f ;
}
2010-07-06 08:30:49 +02:00
Matrix4f matrix2 ;
glGetFloatv ( GL_PROJECTION_MATRIX , matrix2 . ptr ( ) ) ;
2010-03-13 22:10:45 +01:00
2011-04-18 21:48:05 +02:00
//assertGl();
2010-07-06 08:30:49 +02:00
Matrix4f matrix3 ;
glGetFloatv ( GL_MODELVIEW_MATRIX , matrix3 . ptr ( ) ) ;
2010-03-13 22:10:45 +01:00
2010-07-06 08:30:49 +02:00
//pop both matrices
glPopMatrix ( ) ;
glMatrixMode ( GL_PROJECTION ) ;
glPopMatrix ( ) ;
2010-05-06 23:29:46 +02:00
2010-07-06 08:30:49 +02:00
glMatrixMode ( GL_PROJECTION ) ;
glPushMatrix ( ) ;
2010-03-13 22:10:45 +01:00
2011-04-18 21:48:05 +02:00
//assertGl();
2010-07-06 08:30:49 +02:00
//compute texture matrix
glLoadMatrixf ( matrix1 . ptr ( ) ) ;
glMultMatrixf ( matrix2 . ptr ( ) ) ;
glMultMatrixf ( matrix3 . ptr ( ) ) ;
glGetFloatv ( GL_TRANSPOSE_PROJECTION_MATRIX_ARB , shadowMapMatrix . ptr ( ) ) ;
2010-03-13 22:10:45 +01:00
2011-04-18 21:48:05 +02:00
//assertGl();
2011-02-09 09:04:21 +01:00
//if(shadows == sShadowMapping) {
// glDisable(GL_POLYGON_OFFSET_FILL);
// glPolygonOffset(0.0f, 0.0f);
//}
2010-07-06 08:30:49 +02:00
//pop
glPopMatrix ( ) ;
2010-03-13 22:10:45 +01:00
2011-04-18 21:48:05 +02:00
//assertGl();
2010-07-06 08:30:49 +02:00
glPopAttrib ( ) ;
2010-05-06 23:29:46 +02:00
2010-07-06 08:30:49 +02:00
assertGl ( ) ;
2010-03-13 22:10:45 +01:00
}
}
}
// ==================== gl wrap ====================
string Renderer : : getGlInfo ( ) {
2011-09-27 12:16:09 +02:00
string infoStr = " " ;
2010-03-13 22:10:45 +01:00
Lang & lang = Lang : : getInstance ( ) ;
2011-12-02 23:04:02 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = false ) {
2013-10-29 07:13:38 +01:00
infoStr + = lang . getString ( " OpenGlInfo " ) + " : \n " ;
infoStr + = " " + lang . getString ( " OpenGlVersion " ) + " : " ;
2011-09-27 12:16:09 +02:00
infoStr + = string ( ( getGlVersion ( ) ! = NULL ? getGlVersion ( ) : " ? " ) ) + " \n " ;
2013-10-29 07:13:38 +01:00
infoStr + = " " + lang . getString ( " OpenGlRenderer " ) + " : " ;
2011-09-27 12:16:09 +02:00
infoStr + = string ( ( getGlVersion ( ) ! = NULL ? getGlVersion ( ) : " ? " ) ) + " \n " ;
2013-10-29 07:13:38 +01:00
infoStr + = " " + lang . getString ( " OpenGlVendor " ) + " : " ;
2011-09-27 12:16:09 +02:00
infoStr + = string ( ( getGlVendor ( ) ! = NULL ? getGlVendor ( ) : " ? " ) ) + " \n " ;
2013-10-29 07:13:38 +01:00
infoStr + = " " + lang . getString ( " OpenGlMaxLights " ) + " : " ;
2011-09-27 12:16:09 +02:00
infoStr + = intToStr ( getGlMaxLights ( ) ) + " \n " ;
2013-10-29 07:13:38 +01:00
infoStr + = " " + lang . getString ( " OpenGlMaxTextureSize " ) + " : " ;
2011-09-27 12:16:09 +02:00
infoStr + = intToStr ( getGlMaxTextureSize ( ) ) + " \n " ;
2013-10-29 07:13:38 +01:00
infoStr + = " " + lang . getString ( " OpenGlMaxTextureUnits " ) + " : " ;
2011-09-27 12:16:09 +02:00
infoStr + = intToStr ( getGlMaxTextureUnits ( ) ) + " \n " ;
2013-10-29 07:13:38 +01:00
infoStr + = " " + lang . getString ( " OpenGlModelviewStack " ) + " : " ;
2011-09-27 12:16:09 +02:00
infoStr + = intToStr ( getGlModelviewMatrixStackDepth ( ) ) + " \n " ;
2013-10-29 07:13:38 +01:00
infoStr + = " " + lang . getString ( " OpenGlProjectionStack " ) + " : " ;
2011-09-27 12:16:09 +02:00
infoStr + = intToStr ( getGlProjectionMatrixStackDepth ( ) ) + " \n " ;
}
2010-03-13 22:10:45 +01:00
return infoStr ;
}
string Renderer : : getGlMoreInfo ( ) {
2011-09-27 12:16:09 +02:00
string infoStr = " " ;
2010-03-13 22:10:45 +01:00
Lang & lang = Lang : : getInstance ( ) ;
2011-12-02 23:04:02 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = false ) {
2011-09-27 12:16:09 +02:00
//gl extensions
2013-10-29 07:13:38 +01:00
infoStr + = lang . getString ( " OpenGlExtensions " ) + " : \n " ;
2011-09-27 12:16:09 +02:00
string extensions = getGlExtensions ( ) ;
int charCount = 0 ;
2013-11-19 07:14:06 +01:00
for ( int i = 0 ; i < ( int ) extensions . size ( ) ; + + i ) {
2011-09-27 12:16:09 +02:00
infoStr + = extensions [ i ] ;
if ( charCount > 120 & & extensions [ i ] = = ' ' ) {
infoStr + = " \n " ;
charCount = 0 ;
}
+ + charCount ;
2010-03-13 22:10:45 +01:00
}
2011-09-27 12:16:09 +02:00
//platform extensions
infoStr + = " \n \n " ;
2013-10-29 07:13:38 +01:00
infoStr + = lang . getString ( " OpenGlPlatformExtensions " ) + " : \n " ;
2011-09-27 12:16:09 +02:00
charCount = 0 ;
string platformExtensions = getGlPlatformExtensions ( ) ;
2013-11-19 07:14:06 +01:00
for ( int i = 0 ; i < ( int ) platformExtensions . size ( ) ; + + i ) {
2011-09-27 12:16:09 +02:00
infoStr + = platformExtensions [ i ] ;
if ( charCount > 120 & & platformExtensions [ i ] = = ' ' ) {
infoStr + = " \n " ;
charCount = 0 ;
}
+ + charCount ;
2010-03-13 22:10:45 +01:00
}
}
return infoStr ;
}
2011-09-27 12:16:09 +02:00
void Renderer : : autoConfig ( ) {
2011-12-02 23:04:02 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = false ) {
2011-09-27 12:16:09 +02:00
Config & config = Config : : getInstance ( ) ;
2010-03-13 22:10:45 +01:00
2011-09-27 12:16:09 +02:00
bool nvidiaCard = toLower ( getGlVendor ( ) ) . find ( " nvidia " ) ! = string : : npos ;
bool atiCard = toLower ( getGlVendor ( ) ) . find ( " ati " ) ! = string : : npos ;
//bool shadowExtensions = isGlExtensionSupported("GL_ARB_shadow") && isGlExtensionSupported("GL_ARB_shadow_ambient");
bool shadowExtensions = isGlExtensionSupported ( " GL_ARB_shadow " ) ;
2010-03-13 22:10:45 +01:00
2011-09-27 12:16:09 +02:00
//3D textures
config . setBool ( " Textures3D " , isGlExtensionSupported ( " GL_EXT_texture3D " ) ) ;
2010-03-13 22:10:45 +01:00
2011-09-27 12:16:09 +02:00
//shadows
string shadows = " " ;
if ( getGlMaxTextureUnits ( ) > = 3 ) {
if ( nvidiaCard & & shadowExtensions ) {
shadows = shadowsToStr ( sShadowMapping ) ;
}
else {
shadows = shadowsToStr ( sProjected ) ;
}
2010-03-13 22:10:45 +01:00
}
else {
2011-09-27 12:16:09 +02:00
shadows = shadowsToStr ( sDisabled ) ;
2010-03-13 22:10:45 +01:00
}
2011-09-27 12:16:09 +02:00
config . setString ( " Shadows " , shadows ) ;
2010-03-13 22:10:45 +01:00
2011-09-27 12:16:09 +02:00
//lights
config . setInt ( " MaxLights " , atiCard ? 1 : 4 ) ;
2010-03-13 22:10:45 +01:00
2011-09-27 12:16:09 +02:00
//filter
config . setString ( " Filter " , " Bilinear " ) ;
}
2010-03-13 22:10:45 +01:00
}
2011-09-27 12:16:09 +02:00
void Renderer : : clearBuffers ( ) {
2010-03-13 22:10:45 +01:00
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ;
}
2011-09-27 12:16:09 +02:00
void Renderer : : clearZBuffer ( ) {
2010-03-13 22:10:45 +01:00
glClear ( GL_DEPTH_BUFFER_BIT ) ;
}
2010-11-01 17:44:05 +01:00
void Renderer : : loadConfig ( ) {
2010-03-13 22:10:45 +01:00
Config & config = Config : : getInstance ( ) ;
//cache most used config params
maxLights = config . getInt ( " MaxLights " ) ;
photoMode = config . getBool ( " PhotoMode " ) ;
focusArrows = config . getBool ( " FocusArrows " ) ;
textures3D = config . getBool ( " Textures3D " ) ;
2012-03-13 01:44:55 +01:00
float gammaValue = config . getFloat ( " GammaValue " , " 0.0 " ) ;
2012-03-13 02:34:14 +01:00
if ( this - > program = = NULL ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " this->program == NULL " ) ;
2012-03-13 02:34:14 +01:00
}
2012-04-16 08:14:10 +02:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = false ) {
//if(this->program != NULL) {
if ( gammaValue ! = 0.0 ) {
this - > program - > getWindow ( ) - > setGamma ( gammaValue ) ;
}
//}
2012-03-13 19:59:33 +01:00
}
2010-03-13 22:10:45 +01:00
//load shadows
shadows = strToShadows ( config . getString ( " Shadows " ) ) ;
if ( shadows = = sProjected | | shadows = = sShadowMapping ) {
shadowTextureSize = config . getInt ( " ShadowTextureSize " ) ;
shadowFrameSkip = config . getInt ( " ShadowFrameSkip " ) ;
2013-09-22 02:51:47 +02:00
shadowIntensity = config . getFloat ( " ShadowIntensity " , " 1.0 " ) ;
2010-03-13 22:10:45 +01:00
}
//load filter settings
Texture2D : : Filter textureFilter = strToTextureFilter ( config . getString ( " Filter " ) ) ;
int maxAnisotropy = config . getInt ( " FilterMaxAnisotropy " ) ;
2011-09-27 07:29:57 +02:00
2011-12-02 23:04:02 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = false ) {
2011-09-27 07:29:57 +02:00
for ( int i = 0 ; i < rsCount ; + + i ) {
textureManager [ i ] - > setFilter ( textureFilter ) ;
textureManager [ i ] - > setMaxAnisotropy ( maxAnisotropy ) ;
}
2010-03-13 22:10:45 +01:00
}
}
2017-10-10 05:21:14 +02:00
//Texture2D *Renderer::saveScreenToTexture(int x, int y, int width, int height) {
// if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
//
// Config &config= Config::getInstance();
// Texture2D::Filter textureFilter = strToTextureFilter(config.getString("Filter"));
// int maxAnisotropy = config.getInt("FilterMaxAnisotropy");
//
// Texture2D *texture = GraphicsInterface::getInstance().getFactory()->newTexture2D();
// texture->setForceCompressionDisabled(true);
// texture->setMipmap(false);
// Pixmap2D *pixmapScreenShot = texture->getPixmap();
// pixmapScreenShot->init(width, height, 3);
// texture->init(textureFilter,maxAnisotropy);
//
// if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
// //glFinish();
//
// if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
// glReadPixels(x, y, pixmapScreenShot->getW(), pixmapScreenShot->getH(),
// GL_RGB, GL_UNSIGNED_BYTE, pixmapScreenShot->getPixels());
//
// if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
//
// return texture;
//}
2010-11-01 17:44:05 +01:00
2012-03-17 12:26:39 +01:00
void Renderer : : saveScreen ( const string & path , int w , int h ) {
2010-03-13 22:10:45 +01:00
const Metrics & sm = Metrics : : getInstance ( ) ;
2012-03-29 20:14:25 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-09-17 06:59:32 +02:00
2012-03-17 12:26:39 +01:00
Pixmap2D * pixmapScreenShot = new Pixmap2D ( sm . getScreenW ( ) , sm . getScreenH ( ) , 3 ) ;
2010-09-17 06:59:32 +02:00
2012-03-29 20:14:25 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2012-01-04 22:43:34 +01:00
//glFinish();
2010-09-17 06:59:32 +02:00
2011-04-18 22:20:16 +02:00
glPixelStorei ( GL_PACK_ALIGNMENT , 1 ) ;
2012-03-29 20:14:25 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-09-17 06:59:32 +02:00
glReadPixels ( 0 , 0 , pixmapScreenShot - > getW ( ) , pixmapScreenShot - > getH ( ) ,
GL_RGB , GL_UNSIGNED_BYTE , pixmapScreenShot - > getPixels ( ) ) ;
2012-03-17 12:26:39 +01:00
if ( w = = 0 | | h = = 0 ) {
h = sm . getScreenH ( ) ;
w = sm . getScreenW ( ) ;
}
else {
pixmapScreenShot - > Scale ( GL_RGB , w , h ) ;
}
2012-03-29 20:14:25 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-10-30 04:21:47 +02:00
2011-04-18 22:20:16 +02:00
glPixelStorei ( GL_UNPACK_ALIGNMENT , 1 ) ;
2010-10-30 04:21:47 +02:00
// Signal the threads queue to add a screenshot save request
2013-12-25 07:27:44 +01:00
MutexSafeWrapper safeMutex ( saveScreenShotThreadAccessor , string ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) ) + " _ " + intToStr ( __LINE__ ) ) ;
2010-10-30 04:21:47 +02:00
saveScreenQueue . push_back ( make_pair ( path , pixmapScreenShot ) ) ;
safeMutex . ReleaseLock ( ) ;
2010-09-17 06:59:32 +02:00
2012-03-29 20:14:25 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
}
2010-10-30 04:21:47 +02:00
unsigned int Renderer : : getSaveScreenQueueSize ( ) {
2013-12-25 07:27:44 +01:00
MutexSafeWrapper safeMutex ( saveScreenShotThreadAccessor , string ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) ) + " _ " + intToStr ( __LINE__ ) ) ;
2013-11-03 02:51:20 +01:00
int queueSize = ( int ) saveScreenQueue . size ( ) ;
2010-10-30 04:21:47 +02:00
safeMutex . ReleaseLock ( ) ;
return queueSize ;
}
2010-03-13 22:10:45 +01:00
// ==================== PRIVATE ====================
2010-09-10 10:51:32 +02:00
float Renderer : : computeSunAngle ( float time ) {
2010-03-13 22:10:45 +01:00
float dayTime = TimeFlow : : dusk - TimeFlow : : dawn ;
float fTime = ( time - TimeFlow : : dawn ) / dayTime ;
return clamp ( fTime * pi , pi / 8.f , 7.f * pi / 8.f ) ;
}
2010-09-10 10:51:32 +02:00
float Renderer : : computeMoonAngle ( float time ) {
2010-03-13 22:10:45 +01:00
float nightTime = 24 - ( TimeFlow : : dusk - TimeFlow : : dawn ) ;
if ( time < TimeFlow : : dawn ) {
time + = 24.f ;
}
float fTime = ( time - TimeFlow : : dusk ) / nightTime ;
return clamp ( ( 1.0f - fTime ) * pi , pi / 8.f , 7.f * pi / 8.f ) ;
}
2010-09-10 10:51:32 +02:00
Vec4f Renderer : : computeSunPos ( float time ) {
2010-03-13 22:10:45 +01:00
float ang = computeSunAngle ( time ) ;
2013-06-12 03:07:53 +02:00
return Vec4f ( - std : : cos ( ang ) * sunDist , std : : sin ( ang ) * sunDist , 0.f , 0.f ) ;
2010-03-13 22:10:45 +01:00
}
2010-09-10 10:51:32 +02:00
Vec4f Renderer : : computeMoonPos ( float time ) {
2010-03-13 22:10:45 +01:00
float ang = computeMoonAngle ( time ) ;
2013-06-12 03:07:53 +02:00
return Vec4f ( - std : : cos ( ang ) * moonDist , std : : sin ( ang ) * moonDist , 0.f , 0.f ) ;
2010-03-13 22:10:45 +01:00
}
// ==================== fast render ====================
//render units for selection purposes
2011-12-13 02:30:52 +01:00
vector < Unit * > Renderer : : renderUnitsFast ( bool renderingShadows , bool colorPickingSelection ) {
vector < Unit * > unitsList ;
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
2011-12-13 02:30:52 +01:00
return unitsList ;
2011-12-03 01:39:03 +01:00
}
2010-05-03 08:25:54 +02:00
assert ( game ! = NULL ) ;
2013-11-19 07:14:06 +01:00
//const World *world= game->getWorld();
2013-11-19 07:42:32 +01:00
//assert(world != NULL);
2010-03-13 22:10:45 +01:00
2011-01-15 09:45:17 +01:00
VisibleQuadContainerCache & qCache = getQuadCache ( ) ;
2011-09-01 01:10:43 +02:00
if ( qCache . visibleQuadUnitList . empty ( ) = = false ) {
2013-01-15 04:34:01 +01:00
if ( colorPickingSelection = = true ) {
unitsList . reserve ( qCache . visibleQuadUnitList . size ( ) ) ;
}
2012-10-06 09:06:40 +02:00
bool modelRenderStarted = false ;
2013-04-28 12:26:25 +02:00
bool renderOnlyBuildings = true ;
for ( int k = 0 ; k < 2 ; k + + ) {
if ( k = = 0 ) {
//glDisable(GL_DEPTH_TEST);
renderOnlyBuildings = true ;
}
else {
2015-01-12 00:23:08 +01:00
if ( colorPickingSelection = = true ) {
// clear depth buffer to get units behind buildings rendered in front of them
glClear ( GL_DEPTH_BUFFER_BIT ) ;
}
2013-04-28 12:26:25 +02:00
//glEnable(GL_DEPTH_TEST);
renderOnlyBuildings = false ;
}
for ( int visibleUnitIndex = 0 ;
2013-11-19 07:14:06 +01:00
visibleUnitIndex < ( int ) qCache . visibleQuadUnitList . size ( ) ; + + visibleUnitIndex ) {
2013-04-28 12:26:25 +02:00
Unit * unit = qCache . visibleQuadUnitList [ visibleUnitIndex ] ;
2013-01-24 16:52:11 +01:00
2015-01-03 22:24:21 +01:00
if ( renderingShadows = = false & & unit - > isAlive ( ) = = false ) {
// no need to render dead units for selection
continue ;
}
2013-04-30 01:05:56 +02:00
if ( renderOnlyBuildings = = true & & unit - > getType ( ) - > hasSkillClass ( scMove ) ) {
2013-04-28 12:26:25 +02:00
continue ;
}
2013-01-24 16:52:11 +01:00
2013-04-30 01:05:56 +02:00
if ( renderOnlyBuildings = = false & & ! unit - > getType ( ) - > hasSkillClass ( scMove ) ) {
2013-04-28 12:26:25 +02:00
continue ;
}
2011-12-13 02:30:52 +01:00
2013-04-28 12:26:25 +02:00
if ( modelRenderStarted = = false ) {
modelRenderStarted = true ;
2010-05-10 19:50:57 +02:00
2013-04-28 12:26:25 +02:00
if ( colorPickingSelection = = false ) {
//glPushAttrib(GL_ENABLE_BIT| GL_TEXTURE_BIT);
glDisable ( GL_LIGHTING ) ;
if ( renderingShadows = = false ) {
glPushAttrib ( GL_ENABLE_BIT ) ;
glDisable ( GL_TEXTURE_2D ) ;
}
else {
glPushAttrib ( GL_ENABLE_BIT | GL_TEXTURE_BIT ) ;
glEnable ( GL_TEXTURE_2D ) ;
glAlphaFunc ( GL_GREATER , 0.4f ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_TEXTURE_ENV_MODE , GL_COMBINE ) ;
//set color to the texture alpha
glTexEnvi ( GL_TEXTURE_ENV , GL_COMBINE_RGB , GL_REPLACE ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_SOURCE0_RGB , GL_PRIMARY_COLOR ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_OPERAND0_RGB , GL_SRC_COLOR ) ;
//set alpha to the texture alpha
glTexEnvi ( GL_TEXTURE_ENV , GL_COMBINE_ALPHA , GL_REPLACE ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_SOURCE0_ALPHA , GL_TEXTURE ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_OPERAND0_ALPHA , GL_SRC_ALPHA ) ;
}
}
2013-01-24 16:52:11 +01:00
2013-04-28 12:26:25 +02:00
modelRenderer - > begin ( false , renderingShadows , false , colorPickingSelection ) ;
if ( colorPickingSelection = = false ) {
glInitNames ( ) ;
2011-12-13 02:30:52 +01:00
}
2011-01-15 09:45:17 +01:00
}
2010-09-10 10:51:32 +02:00
2013-01-15 04:18:26 +01:00
if ( colorPickingSelection = = false ) {
2013-04-28 12:26:25 +02:00
glPushName ( visibleUnitIndex ) ;
2011-12-13 02:30:52 +01:00
}
2010-05-10 19:50:57 +02:00
2013-04-28 12:26:25 +02:00
//assertGl();
2010-09-10 10:51:32 +02:00
2013-04-28 12:26:25 +02:00
glMatrixMode ( GL_MODELVIEW ) ;
//debuxar modelo
glPushMatrix ( ) ;
2013-01-24 16:52:11 +01:00
2013-04-28 12:26:25 +02:00
//translate
2013-10-03 02:17:51 +02:00
Vec3f currVec = unit - > getCurrVectorFlat ( ) ;
2013-04-28 12:26:25 +02:00
glTranslatef ( currVec . x , currVec . y , currVec . z ) ;
2010-09-10 10:51:32 +02:00
2013-04-28 12:26:25 +02:00
//rotate
glRotatef ( unit - > getRotation ( ) , 0.f , 1.f , 0.f ) ;
2010-09-10 10:51:32 +02:00
2013-04-28 12:26:25 +02:00
//render
Model * model = unit - > getCurrentModelPtr ( ) ;
//if(this->gameCamera->getPos().dist(unit->getCurrVector()) <= SKIP_INTERPOLATION_DISTANCE) {
2013-01-12 08:36:14 +01:00
2013-04-28 12:26:25 +02:00
// ***MV don't think this is needed below 2013/01/11
2013-06-12 02:53:52 +02:00
model - > updateInterpolationVertices ( unit - > getAnimProgressAsFloat ( ) , unit - > isAlive ( ) & & ! unit - > isAnimProgressBound ( ) ) ;
2013-01-12 08:36:14 +01:00
2013-04-28 12:26:25 +02:00
//}
2011-12-13 02:30:52 +01:00
2013-04-28 12:26:25 +02:00
if ( colorPickingSelection = = true ) {
unit - > setUniquePickingColor ( ) ;
unitsList . push_back ( unit ) ;
}
2011-12-13 02:30:52 +01:00
2013-04-28 12:26:25 +02:00
modelRenderer - > render ( model , rmSelection ) ;
2010-09-10 10:51:32 +02:00
2013-04-28 12:26:25 +02:00
glPopMatrix ( ) ;
2011-12-13 02:30:52 +01:00
2013-04-28 12:26:25 +02:00
if ( colorPickingSelection = = false ) {
glPopName ( ) ;
}
2011-12-13 02:30:52 +01:00
}
2010-09-10 10:51:32 +02:00
}
2011-01-15 09:45:17 +01:00
2010-09-10 10:51:32 +02:00
if ( modelRenderStarted = = true ) {
modelRenderer - > end ( ) ;
2013-01-15 04:18:26 +01:00
if ( colorPickingSelection = = false ) {
2011-12-13 02:30:52 +01:00
glPopAttrib ( ) ;
}
2010-06-22 01:38:53 +02:00
}
2010-05-10 19:50:57 +02:00
}
2013-04-28 12:26:25 +02:00
//glDisable(GL_DEPTH_TEST);
2011-12-13 02:30:52 +01:00
return unitsList ;
2010-05-10 19:50:57 +02:00
}
2010-03-13 22:10:45 +01:00
//render objects for selection purposes
2013-01-15 04:18:26 +01:00
vector < Object * > Renderer : : renderObjectsFast ( bool renderingShadows , bool resourceOnly ,
bool colorPickingSelection ) {
2011-12-13 02:30:52 +01:00
vector < Object * > objectList ;
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
2011-12-13 02:30:52 +01:00
return objectList ;
2011-12-03 01:39:03 +01:00
}
2011-01-15 09:45:17 +01:00
VisibleQuadContainerCache & qCache = getQuadCache ( ) ;
2011-09-01 01:10:43 +02:00
if ( qCache . visibleObjectList . empty ( ) = = false ) {
2013-01-15 04:34:01 +01:00
if ( colorPickingSelection = = true ) {
objectList . reserve ( qCache . visibleObjectList . size ( ) ) ;
}
2012-10-06 09:06:40 +02:00
bool modelRenderStarted = false ;
2011-01-15 09:45:17 +01:00
for ( int visibleIndex = 0 ;
2013-11-19 07:14:06 +01:00
visibleIndex < ( int ) qCache . visibleObjectList . size ( ) ; + + visibleIndex ) {
2011-01-15 09:45:17 +01:00
Object * o = qCache . visibleObjectList [ visibleIndex ] ;
2010-08-21 21:15:39 +02:00
2011-01-15 09:45:17 +01:00
if ( modelRenderStarted = = false ) {
modelRenderStarted = true ;
2010-08-21 21:15:39 +02:00
2011-12-13 02:30:52 +01:00
if ( colorPickingSelection = = false ) {
glDisable ( GL_LIGHTING ) ;
2010-03-13 22:10:45 +01:00
2011-12-13 02:30:52 +01:00
if ( renderingShadows = = false ) {
glPushAttrib ( GL_ENABLE_BIT ) ;
glDisable ( GL_TEXTURE_2D ) ;
}
else {
glPushAttrib ( GL_ENABLE_BIT | GL_TEXTURE_BIT ) ;
glAlphaFunc ( GL_GREATER , 0.5f ) ;
2010-03-13 22:10:45 +01:00
2011-12-13 02:30:52 +01:00
glTexEnvi ( GL_TEXTURE_ENV , GL_TEXTURE_ENV_MODE , GL_COMBINE ) ;
2010-03-13 22:10:45 +01:00
2011-12-13 02:30:52 +01:00
//set color to the texture alpha
glTexEnvi ( GL_TEXTURE_ENV , GL_COMBINE_RGB , GL_REPLACE ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_SOURCE0_RGB , GL_PRIMARY_COLOR ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_OPERAND0_RGB , GL_SRC_COLOR ) ;
2010-03-13 22:10:45 +01:00
2011-12-13 02:30:52 +01:00
//set alpha to the texture alpha
glTexEnvi ( GL_TEXTURE_ENV , GL_COMBINE_ALPHA , GL_REPLACE ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_SOURCE0_ALPHA , GL_TEXTURE ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_OPERAND0_ALPHA , GL_SRC_ALPHA ) ;
}
2011-02-13 15:35:17 +01:00
}
2011-12-13 02:30:52 +01:00
2013-01-15 04:18:26 +01:00
modelRenderer - > begin ( false , renderingShadows , false , colorPickingSelection ) ;
2011-12-13 02:30:52 +01:00
2013-01-15 04:18:26 +01:00
if ( colorPickingSelection = = false ) {
2011-12-13 02:30:52 +01:00
glInitNames ( ) ;
}
2010-09-10 10:51:32 +02:00
}
2011-12-13 02:30:52 +01:00
if ( resourceOnly = = false | | o - > getResource ( ) ! = NULL ) {
2011-02-13 15:35:17 +01:00
Model * objModel = o - > getModelPtr ( ) ;
2012-10-06 04:10:23 +02:00
//if(this->gameCamera->getPos().dist(o->getPos()) <= SKIP_INTERPOLATION_DISTANCE) {
2013-01-12 08:36:14 +01:00
// ***MV don't think this is needed below 2013/01/11
//objModel->updateInterpolationData(o->getAnimProgress(), true);
2012-10-06 04:10:23 +02:00
//}
2013-10-03 02:17:51 +02:00
const Vec3f v = o - > getConstPos ( ) ;
2011-12-13 02:30:52 +01:00
if ( colorPickingSelection = = false ) {
glPushName ( OBJECT_SELECT_OFFSET + visibleIndex ) ;
}
2011-02-13 15:35:17 +01:00
glMatrixMode ( GL_MODELVIEW ) ;
glPushMatrix ( ) ;
glTranslatef ( v . x , v . y , v . z ) ;
glRotatef ( o - > getRotation ( ) , 0.f , 1.f , 0.f ) ;
2010-05-10 19:50:57 +02:00
2011-12-13 02:30:52 +01:00
if ( colorPickingSelection = = true ) {
o - > setUniquePickingColor ( ) ;
objectList . push_back ( o ) ;
}
2012-09-01 20:38:01 +02:00
modelRenderer - > render ( objModel , resourceOnly ? rmSelection : rmNormal ) ;
2010-05-10 19:50:57 +02:00
2011-02-13 15:35:17 +01:00
glPopMatrix ( ) ;
2011-12-13 02:30:52 +01:00
if ( colorPickingSelection = = false ) {
glPopName ( ) ;
}
2011-02-13 15:35:17 +01:00
}
2010-09-10 10:51:32 +02:00
}
2010-05-10 19:50:57 +02:00
2010-09-10 10:51:32 +02:00
if ( modelRenderStarted = = true ) {
modelRenderer - > end ( ) ;
2011-12-13 02:30:52 +01:00
2013-01-15 04:18:26 +01:00
if ( colorPickingSelection = = false ) {
2011-12-13 02:30:52 +01:00
glPopAttrib ( ) ;
}
2010-09-10 10:51:32 +02:00
}
2010-05-10 19:50:57 +02:00
}
2010-09-10 10:51:32 +02:00
2011-12-13 02:30:52 +01:00
return objectList ;
2010-05-10 19:50:57 +02:00
}
2010-03-13 22:10:45 +01:00
// ==================== gl caps ====================
2010-09-10 10:51:32 +02:00
void Renderer : : checkGlCaps ( ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2012-08-10 08:19:35 +02:00
if ( glActiveTexture = = NULL ) {
string message ;
2013-10-28 19:27:51 +01:00
message + = " Your system supports OpenGL version [ " ;
message + = getGlVersion ( ) + string ( " ] \n " ) ;
2012-08-10 08:19:35 +02:00
message + = " MegaGlest needs a version that supports \n " ;
message + = " glActiveTexture (OpenGL 1.3) or the ARB_multitexture extension. " ;
2013-10-28 19:27:51 +01:00
throw megaglest_runtime_error ( message . c_str ( ) , true ) ;
2012-08-10 08:19:35 +02:00
}
2017-09-23 02:17:49 +02:00
//opengl 2.1
if ( glewIsSupported ( " GL_VERSION_2_1 " ) = = false ) {
2010-03-13 22:10:45 +01:00
string message ;
2013-10-28 19:27:51 +01:00
message + = " Your system supports OpenGL version [ " ;
message + = getGlVersion ( ) + string ( " ] \n " ) ;
2017-09-23 02:17:49 +02:00
message + = " MegaGlest needs at least version 2.1 to work \n " ;
2010-03-13 22:10:45 +01:00
message + = " You may solve this problem by installing your latest video card drivers " ;
2013-10-28 19:27:51 +01:00
throw megaglest_runtime_error ( message . c_str ( ) , true ) ;
2010-03-13 22:10:45 +01:00
}
//opengl 1.4 or extension
2011-12-06 02:34:51 +01:00
//if(!isGlVersionSupported(1, 4, 0)){
if ( glewIsSupported ( " GL_VERSION_1_4 " ) = = false ) {
2010-12-13 01:32:59 +01:00
checkExtension ( " GL_ARB_texture_env_crossbar " , " MegaGlest " ) ;
2010-03-13 22:10:45 +01:00
}
}
2010-09-10 10:51:32 +02:00
void Renderer : : checkGlOptionalCaps ( ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2010-03-13 22:10:45 +01:00
2012-08-10 08:19:35 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
//shadows
2010-09-10 10:51:32 +02:00
if ( shadows = = sProjected | | shadows = = sShadowMapping ) {
if ( getGlMaxTextureUnits ( ) < 3 ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " Your system doesn't support 3 texture units, required for shadows " ) ;
2010-03-13 22:10:45 +01:00
}
}
2012-08-10 08:19:35 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
//shadow mapping
2010-09-10 10:51:32 +02:00
if ( shadows = = sShadowMapping ) {
2010-03-13 22:10:45 +01:00
checkExtension ( " GL_ARB_shadow " , " Shadow Mapping " ) ;
2010-10-27 17:04:47 +02:00
//checkExtension("GL_ARB_shadow_ambient", "Shadow Mapping");
2010-10-26 23:52:00 +02:00
//checkExtension("GL_ARB_depth_texture", "Shadow Mapping");
2010-03-13 22:10:45 +01:00
}
2012-08-10 08:19:35 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
}
2010-09-10 10:51:32 +02:00
void Renderer : : checkExtension ( const string & extension , const string & msg ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2012-08-10 08:19:35 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-09-10 10:51:32 +02:00
if ( ! isGlExtensionSupported ( extension . c_str ( ) ) ) {
2010-03-13 22:10:45 +01:00
string str = " OpenGL extension not supported: " + extension + " , required for " + msg ;
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( str ) ;
2010-03-13 22:10:45 +01:00
}
2012-08-10 08:19:35 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
}
// ==================== init 3d lists ====================
2010-09-10 10:51:32 +02:00
void Renderer : : init3dList ( ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2012-08-10 08:19:35 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2012-03-29 20:14:25 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-04-04 06:14:27 +02:00
2012-05-24 08:16:54 +02:00
render3dSetup ( ) ;
2012-08-10 08:19:35 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2012-05-24 08:16:54 +02:00
//const Metrics &metrics= Metrics::getInstance();
2010-03-13 22:10:45 +01:00
2012-05-24 08:16:54 +02:00
//assertGl();
2010-03-13 22:10:45 +01:00
2012-05-24 08:16:54 +02:00
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2010-04-04 06:14:27 +02:00
2012-05-24 08:16:54 +02:00
//list3d= glGenLists(1);
//assertGl();
//list3dValid=true;
2010-04-04 06:14:27 +02:00
2012-05-24 08:16:54 +02:00
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2010-04-04 06:14:27 +02:00
2012-05-24 08:16:54 +02:00
//glNewList(list3d, GL_COMPILE_AND_EXECUTE);
2010-03-13 22:10:45 +01:00
//need to execute, because if not gluPerspective takes no effect and gluLoadMatrix is wrong
2012-05-24 08:16:54 +02:00
//render3dSetup();
//glEndList();
2010-03-13 22:10:45 +01:00
2012-05-24 08:16:54 +02:00
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2010-03-13 22:10:45 +01:00
2012-05-24 08:16:54 +02:00
//assert
//assertGl();
}
2010-04-04 06:14:27 +02:00
2012-05-24 08:16:54 +02:00
void Renderer : : render3dSetup ( ) {
2012-11-10 07:37:23 +01:00
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2012-05-24 08:16:54 +02:00
const Metrics & metrics = Metrics : : getInstance ( ) ;
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2010-03-13 22:10:45 +01:00
2012-05-24 08:16:54 +02:00
//misc
glViewport ( 0 , 0 , metrics . getScreenW ( ) , metrics . getScreenH ( ) ) ;
glClearColor ( fowColor . x , fowColor . y , fowColor . z , fowColor . w ) ;
glFrontFace ( GL_CW ) ;
glEnable ( GL_CULL_FACE ) ;
loadProjectionMatrix ( ) ;
2010-03-13 22:10:45 +01:00
2012-05-24 08:16:54 +02:00
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2010-03-13 22:10:45 +01:00
2012-11-10 07:37:23 +01:00
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2012-08-10 08:19:35 +02:00
2012-05-24 08:16:54 +02:00
//texture state
glActiveTexture ( shadowTexUnit ) ;
glDisable ( GL_TEXTURE_2D ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_TEXTURE_ENV_MODE , GL_MODULATE ) ;
2010-04-04 06:14:27 +02:00
2012-05-24 08:16:54 +02:00
glActiveTexture ( fowTexUnit ) ;
glDisable ( GL_TEXTURE_2D ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_TEXTURE_ENV_MODE , GL_MODULATE ) ;
2010-03-13 22:10:45 +01:00
2012-05-24 08:16:54 +02:00
glActiveTexture ( baseTexUnit ) ;
glEnable ( GL_TEXTURE_2D ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_TEXTURE_ENV_MODE , GL_MODULATE ) ;
2010-03-13 22:10:45 +01:00
2012-05-24 08:16:54 +02:00
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2010-03-13 22:10:45 +01:00
2012-11-10 07:37:23 +01:00
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2012-08-10 08:19:35 +02:00
2012-05-24 08:16:54 +02:00
//material state
glMaterialfv ( GL_FRONT_AND_BACK , GL_SPECULAR , defSpecularColor . ptr ( ) ) ;
glMaterialfv ( GL_FRONT_AND_BACK , GL_AMBIENT , defAmbientColor . ptr ( ) ) ;
glMaterialfv ( GL_FRONT_AND_BACK , GL_DIFFUSE , defDiffuseColor . ptr ( ) ) ;
glColorMaterial ( GL_FRONT_AND_BACK , GL_DIFFUSE ) ;
glColor4fv ( defColor . ptr ( ) ) ;
2010-03-13 22:10:45 +01:00
2012-05-24 08:16:54 +02:00
//blend state
glDisable ( GL_BLEND ) ;
glBlendFunc ( GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA ) ;
2010-04-04 06:14:27 +02:00
2012-11-10 07:37:23 +01:00
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2012-08-10 08:19:35 +02:00
2012-05-24 08:16:54 +02:00
//alpha test state
glEnable ( GL_ALPHA_TEST ) ;
glAlphaFunc ( GL_GREATER , 0.f ) ;
2010-03-13 22:10:45 +01:00
2012-05-24 08:16:54 +02:00
//depth test state
glEnable ( GL_DEPTH_TEST ) ;
glDepthMask ( GL_TRUE ) ;
glDepthFunc ( GL_LESS ) ;
2010-03-13 22:10:45 +01:00
2012-05-24 08:16:54 +02:00
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2010-03-13 22:10:45 +01:00
2012-05-24 08:16:54 +02:00
//lighting state
glEnable ( GL_LIGHTING ) ;
glEnable ( GL_LIGHT0 ) ;
2010-04-04 06:14:27 +02:00
2012-05-24 08:16:54 +02:00
//matrix mode
glMatrixMode ( GL_MODELVIEW ) ;
2010-04-04 06:14:27 +02:00
2012-05-24 08:16:54 +02:00
//stencil test
glDisable ( GL_STENCIL_TEST ) ;
2010-04-04 06:14:27 +02:00
2012-05-24 08:16:54 +02:00
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2012-11-10 07:37:23 +01:00
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2010-04-04 06:14:27 +02:00
2012-05-24 08:16:54 +02:00
//fog
const Tileset * tileset = NULL ;
if ( game ! = NULL & & game - > getWorld ( ) ! = NULL ) {
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
tileset = game - > getWorld ( ) - > getTileset ( ) ;
}
2010-03-13 22:10:45 +01:00
2012-05-24 08:16:54 +02:00
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2010-03-13 22:10:45 +01:00
2012-05-24 08:16:54 +02:00
if ( tileset ! = NULL & & tileset - > getFog ( ) ) {
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2010-04-04 06:14:27 +02:00
2012-05-24 08:16:54 +02:00
glEnable ( GL_FOG ) ;
if ( tileset - > getFogMode ( ) = = fmExp ) {
glFogi ( GL_FOG_MODE , GL_EXP ) ;
}
else {
glFogi ( GL_FOG_MODE , GL_EXP2 ) ;
}
2010-03-13 22:10:45 +01:00
2012-05-24 08:16:54 +02:00
glFogf ( GL_FOG_DENSITY , tileset - > getFogDensity ( ) ) ;
glFogfv ( GL_FOG_COLOR , tileset - > getFogColor ( ) . ptr ( ) ) ;
}
2010-04-04 06:14:27 +02:00
2012-05-24 08:16:54 +02:00
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2010-03-13 22:10:45 +01:00
}
2010-09-10 10:51:32 +02:00
void Renderer : : init2dList ( ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2012-05-24 08:16:54 +02:00
// //this list sets the state for the 2d rendering
// list2d= glGenLists(1);
// assertGl();
// list2dValid=true;
//
// glNewList(list2d, GL_COMPILE);
// render2dMenuSetup();
// glEndList();
//
// assertGl();
}
2010-03-13 22:10:45 +01:00
2012-05-24 08:16:54 +02:00
void Renderer : : render2dMenuSetup ( ) {
2012-11-09 19:09:32 +01:00
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2012-08-10 08:19:35 +02:00
2012-05-24 08:16:54 +02:00
const Metrics & metrics = Metrics : : getInstance ( ) ;
//projection
glViewport ( 0 , 0 , metrics . getScreenW ( ) , metrics . getScreenH ( ) ) ;
glMatrixMode ( GL_PROJECTION ) ;
glLoadIdentity ( ) ;
glOrtho ( 0 , metrics . getVirtualW ( ) , 0 , metrics . getVirtualH ( ) , 0 , 1 ) ;
2010-03-13 22:10:45 +01:00
2012-11-09 19:09:32 +01:00
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2012-08-10 08:19:35 +02:00
2012-05-24 08:16:54 +02:00
//modelview
glMatrixMode ( GL_MODELVIEW ) ;
glLoadIdentity ( ) ;
2010-03-13 22:10:45 +01:00
2012-11-09 19:09:32 +01:00
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2012-08-10 08:19:35 +02:00
2012-05-24 08:16:54 +02:00
//disable everything
glDisable ( GL_BLEND ) ;
glDisable ( GL_LIGHTING ) ;
glDisable ( GL_ALPHA_TEST ) ;
glDisable ( GL_DEPTH_TEST ) ;
glDisable ( GL_STENCIL_TEST ) ;
glDisable ( GL_FOG ) ;
glDisable ( GL_CULL_FACE ) ;
glFrontFace ( GL_CCW ) ;
2012-08-10 08:19:35 +02:00
2012-11-09 19:09:32 +01:00
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2012-08-10 08:19:35 +02:00
if ( glActiveTexture ! = NULL ) {
glActiveTexture ( baseTexUnit ) ;
}
else {
char szBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " In [%s::%s] Line: %d \n glActiveTexture == NULL \n glActiveTexture is only supported if the GL version is 1.3 or greater, \n or if the ARB_multitexture extension is supported! " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2012-08-10 08:19:35 +02:00
throw megaglest_runtime_error ( szBuf ) ;
}
2012-11-09 19:09:32 +01:00
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2012-08-10 08:19:35 +02:00
2012-05-24 08:16:54 +02:00
glTexEnvi ( GL_TEXTURE_ENV , GL_TEXTURE_ENV_MODE , GL_MODULATE ) ;
glDisable ( GL_TEXTURE_2D ) ;
2010-03-13 22:10:45 +01:00
2012-11-09 19:09:32 +01:00
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2012-08-10 08:19:35 +02:00
2012-05-24 08:16:54 +02:00
//blend func
glBlendFunc ( GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA ) ;
2010-03-13 22:10:45 +01:00
2012-05-24 08:16:54 +02:00
//color
glColor4f ( 1.f , 1.f , 1.f , 1.f ) ;
2012-08-10 08:19:35 +02:00
2012-11-09 19:09:32 +01:00
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2010-03-13 22:10:45 +01:00
}
2017-10-10 05:21:14 +02:00
//void Renderer::init3dListMenu(const MainMenu *mm) {
// if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
// return;
// }
//
// //this->mm3d = mm;
// //printf("In [%s::%s Line: %d] this->custom_mm3d [%p] this->mm3d [%p]\n",__FILE__,__FUNCTION__,__LINE__,this->custom_mm3d,this->mm3d);
//
///*
// assertGl();
//
// if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
//
// const Metrics &metrics= Metrics::getInstance();
// //const MenuBackground *mb= mm->getConstMenuBackground();
// const MenuBackground *mb = NULL;
// if(mm != NULL) {
// mb = mm->getConstMenuBackground();
// }
//
// if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
//
// if(this->customlist3dMenu != NULL) {
// *this->customlist3dMenu = glGenLists(1);
// assertGl();
// }
// else {
// list3dMenu= glGenLists(1);
// assertGl();
// list3dMenuValid=true;
// }
//
// if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
//
// if(this->customlist3dMenu != NULL) {
// glNewList(*this->customlist3dMenu, GL_COMPILE);
// }
// else {
// glNewList(list3dMenu, GL_COMPILE);
// }
//
// if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
// //misc
// glViewport(0, 0, metrics.getScreenW(), metrics.getScreenH());
// glClearColor(0.4f, 0.4f, 0.4f, 1.f);
// glFrontFace(GL_CW);
// glEnable(GL_CULL_FACE);
// glMatrixMode(GL_PROJECTION);
// glLoadIdentity();
// gluPerspective(perspFov, metrics.getAspectRatio(), perspNearPlane, 1000000);
//
// //texture state
// glEnable(GL_TEXTURE_2D);
// glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
//
// //material state
// glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, defSpecularColor.ptr());
// glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, defAmbientColor.ptr());
// glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, defDiffuseColor.ptr());
// glColor4fv(defColor.ptr());
// glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
//
// //blend state
// glDisable(GL_BLEND);
// glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//
// //alpha test state
// glEnable(GL_ALPHA_TEST);
// glAlphaFunc(GL_GREATER, 0.f);
//
// //depth test state
// glEnable(GL_DEPTH_TEST);
// glDepthMask(GL_TRUE);
// glDepthFunc(GL_LESS);
//
// //lighting state
// glEnable(GL_LIGHTING);
//
// //matrix mode
// glMatrixMode(GL_MODELVIEW);
//
// //stencil test
// glDisable(GL_STENCIL_TEST);
//
// if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
//
// //fog
// if(mb != NULL && mb->getFog()){
// if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
//
// glEnable(GL_FOG);
// glFogi(GL_FOG_MODE, GL_EXP2);
// glFogf(GL_FOG_DENSITY, mb->getFogDensity());
// }
//
// if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
//
// glEndList();
//
// if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
//
// //assert
// assertGl();
//*/
//}
2010-03-13 22:10:45 +01:00
2012-05-24 08:16:54 +02:00
void Renderer : : render3dMenuSetup ( const MainMenu * mm ) {
2012-11-09 19:09:32 +01:00
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2012-08-10 08:19:35 +02:00
2012-05-24 08:16:54 +02:00
const Metrics & metrics = Metrics : : getInstance ( ) ;
const MenuBackground * mb = NULL ;
if ( mm ! = NULL ) {
mb = mm - > getConstMenuBackground ( ) ;
}
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
//misc
glViewport ( 0 , 0 , metrics . getScreenW ( ) , metrics . getScreenH ( ) ) ;
glClearColor ( 0.4f , 0.4f , 0.4f , 1.f ) ;
glFrontFace ( GL_CW ) ;
glEnable ( GL_CULL_FACE ) ;
glMatrixMode ( GL_PROJECTION ) ;
glLoadIdentity ( ) ;
gluPerspective ( perspFov , metrics . getAspectRatio ( ) , perspNearPlane , 1000000 ) ;
//texture state
glEnable ( GL_TEXTURE_2D ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_TEXTURE_ENV_MODE , GL_MODULATE ) ;
//material state
glMaterialfv ( GL_FRONT_AND_BACK , GL_SPECULAR , defSpecularColor . ptr ( ) ) ;
glMaterialfv ( GL_FRONT_AND_BACK , GL_AMBIENT , defAmbientColor . ptr ( ) ) ;
glMaterialfv ( GL_FRONT_AND_BACK , GL_DIFFUSE , defDiffuseColor . ptr ( ) ) ;
glColor4fv ( defColor . ptr ( ) ) ;
glColorMaterial ( GL_FRONT_AND_BACK , GL_DIFFUSE ) ;
//blend state
glDisable ( GL_BLEND ) ;
glBlendFunc ( GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA ) ;
//alpha test state
glEnable ( GL_ALPHA_TEST ) ;
glAlphaFunc ( GL_GREATER , 0.f ) ;
//depth test state
glEnable ( GL_DEPTH_TEST ) ;
glDepthMask ( GL_TRUE ) ;
glDepthFunc ( GL_LESS ) ;
//lighting state
glEnable ( GL_LIGHTING ) ;
//matrix mode
glMatrixMode ( GL_MODELVIEW ) ;
2010-03-13 22:10:45 +01:00
2012-05-24 08:16:54 +02:00
//stencil test
glDisable ( GL_STENCIL_TEST ) ;
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
//fog
if ( mb ! = NULL & & mb - > getFog ( ) ) {
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
glEnable ( GL_FOG ) ;
glFogi ( GL_FOG_MODE , GL_EXP2 ) ;
glFogf ( GL_FOG_DENSITY , mb - > getFogDensity ( ) ) ;
}
//assert
assertGl ( ) ;
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
}
2010-03-13 22:10:45 +01:00
// ==================== misc ====================
2010-09-10 10:51:32 +02:00
void Renderer : : loadProjectionMatrix ( ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2010-03-13 22:10:45 +01:00
GLdouble clipping ;
const Metrics & metrics = Metrics : : getInstance ( ) ;
assertGl ( ) ;
clipping = photoMode ? perspFarPlane * 100 : perspFarPlane ;
glMatrixMode ( GL_PROJECTION ) ;
glLoadIdentity ( ) ;
gluPerspective ( perspFov , metrics . getAspectRatio ( ) , perspNearPlane , clipping ) ;
assertGl ( ) ;
}
2010-09-10 10:51:32 +02:00
void Renderer : : enableProjectiveTexturing ( ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2010-03-13 22:10:45 +01:00
glTexGenfv ( GL_S , GL_EYE_PLANE , & shadowMapMatrix [ 0 ] ) ;
glTexGenfv ( GL_T , GL_EYE_PLANE , & shadowMapMatrix [ 4 ] ) ;
glTexGenfv ( GL_R , GL_EYE_PLANE , & shadowMapMatrix [ 8 ] ) ;
glTexGenfv ( GL_Q , GL_EYE_PLANE , & shadowMapMatrix [ 12 ] ) ;
glEnable ( GL_TEXTURE_GEN_S ) ;
glEnable ( GL_TEXTURE_GEN_T ) ;
glEnable ( GL_TEXTURE_GEN_R ) ;
glEnable ( GL_TEXTURE_GEN_Q ) ;
}
// ==================== private aux drawing ====================
2014-11-22 23:15:19 +01:00
void Renderer : : renderHealthBar ( Vec3f v , Unit * unit , float height , bool lineBorder , const Texture2D * texture , const Texture2D * backgroundTexture ) {
2014-10-30 00:55:18 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2014-11-22 23:15:19 +01:00
int numberOfBars = 1 ;
int barCount = 0 ;
float hp = unit - > getHpRatio ( ) ;
float ep = - 1.f ;
2014-12-22 06:07:24 +01:00
if ( unit - > getType ( ) - > getTotalMaxEp ( unit - > getTotalUpgrade ( ) ) ! = 0 ) {
2014-11-22 23:15:19 +01:00
ep = unit - > getEpRatio ( ) ;
numberOfBars + + ;
}
int productionPercent = unit - > getProductionPercent ( ) ;
if ( productionPercent ! = - 1 ) {
numberOfBars + + ;
}
int size = unit - > getType ( ) - > getSize ( ) ;
2014-10-26 21:34:14 +01:00
Vec3f rightVector ;
Vec3f upVector ;
2014-11-02 18:18:20 +01:00
Vec3f rightVectorTexture ;
Vec3f upVectorTexture ;
2014-10-29 00:50:45 +01:00
v . y + = 1 ;
2014-10-26 21:34:14 +01:00
float modelview [ 16 ] ;
2014-10-29 00:50:45 +01:00
float width = ( float ) size / 6 + 0.25f ;
2014-10-26 21:34:14 +01:00
float red ;
float green ;
2014-11-22 23:15:19 +01:00
float brightness = 0.8f ;
2014-10-26 21:34:14 +01:00
glMatrixMode ( GL_MODELVIEW ) ;
glPushMatrix ( ) ;
// get the current modelview state
glGetFloatv ( GL_MODELVIEW_MATRIX , modelview ) ;
rightVector = Vec3f ( modelview [ 0 ] , modelview [ 4 ] , modelview [ 8 ] ) ;
upVector = Vec3f ( modelview [ 1 ] , modelview [ 5 ] , modelview [ 9 ] ) ;
2014-11-02 18:18:20 +01:00
rightVectorTexture = rightVector * 2 ;
upVectorTexture = upVector * 4 ;
2014-10-26 21:34:14 +01:00
2014-10-29 22:23:46 +01:00
//from green to yellow to red
2014-11-22 23:15:19 +01:00
if ( hp > = 0.75f ) {
green = 1 ;
red = 1 - ( ( 2 * hp - 1 ) - 0.5f ) ;
2014-10-26 21:34:14 +01:00
} else {
2014-11-22 23:15:19 +01:00
red = 1 ;
green = 0.5f + ( 2 * hp - 1 ) ;
2014-10-26 21:34:14 +01:00
}
2014-11-22 23:15:19 +01:00
if ( red > 1.0f ) red = 1.0f ;
if ( green > 1.0f ) green = 1.0f ;
float yOffset = ( float ) numberOfBars / 2.f ;
2014-11-05 02:05:47 +01:00
if ( backgroundTexture ! = NULL ) {
//backgroundTexture
glEnable ( GL_TEXTURE_2D ) ;
glBindTexture ( GL_TEXTURE_2D , static_cast < const Texture2DGl * > ( backgroundTexture ) - > getHandle ( ) ) ;
glColor4f ( 1.f , 1.f , 1.f , 1.f ) ;
//glColor4f(red+0.1f,green+0.1f,0.1f,0.5f);
glBegin ( GL_QUADS ) ;
glTexCoord2i ( 0 , 1 ) ;
2014-11-22 23:15:19 +01:00
glVertex3fv ( ( v - ( rightVectorTexture * width - upVectorTexture * height * yOffset ) ) . ptr ( ) ) ;
2014-11-05 02:05:47 +01:00
glTexCoord2i ( 0 , 0 ) ;
2014-11-22 23:15:19 +01:00
glVertex3fv ( ( v - ( rightVectorTexture * width + upVectorTexture * height * yOffset ) ) . ptr ( ) ) ;
2014-11-05 02:05:47 +01:00
glTexCoord2i ( 1 , 0 ) ;
2014-11-22 23:15:19 +01:00
glVertex3fv ( ( v + ( rightVectorTexture * width - upVectorTexture * height * yOffset ) ) . ptr ( ) ) ;
2014-11-05 02:05:47 +01:00
glTexCoord2i ( 1 , 1 ) ;
2014-11-22 23:15:19 +01:00
glVertex3fv ( ( v + ( rightVectorTexture * width + upVectorTexture * height * yOffset ) ) . ptr ( ) ) ;
2014-11-05 02:05:47 +01:00
glEnd ( ) ;
glDisable ( GL_TEXTURE_2D ) ;
}
2014-11-02 18:18:20 +01:00
//healthbar
2014-11-22 23:15:19 +01:00
glColor4f ( red * brightness , green * brightness , 0.0f , 0.4f ) ;
//hpbar
barCount + + ;
internalRenderHp ( numberOfBars , barCount , hp , v , width , height , rightVector , upVector ) ;
if ( ep > - 1.0f ) {
//epbar
barCount + + ;
//glColor4f(brightness,0,brightness,0.5f);
glColor4f ( .15f * brightness , 0.3f * brightness , 0.8f * brightness , 0.7f ) ;
internalRenderHp ( numberOfBars , barCount , ep , v , width , height , rightVector , upVector ) ;
}
if ( productionPercent ! = - 1 ) {
barCount + + ;
glColor4f ( brightness , 0 , brightness , 0.6f ) ;
//glColor4f(0.0f*brightness,0.4f*brightness,0.2f*brightness,0.8f);
internalRenderHp ( numberOfBars , barCount , ( float ) productionPercent / 100 , v , width , height , rightVector , upVector ) ;
}
// glBegin(GL_QUADS);
// if(ep < -2.0f) {
// //hpbar
// glVertex3fv((v - (rightVector*width - upVector*height)).ptr());
// glVertex3fv((v - (rightVector*width + upVector*height)).ptr());
// glVertex3fv((v + (rightVector*hp*width - upVector*height)).ptr());
// glVertex3fv((v + (rightVector*hp*width + upVector*height)).ptr());
//
// } else {
// //hpbar
// glVertex3fv((v - (rightVector*width - upVector*height)).ptr());
// glVertex3fv((v - (rightVector*width + upVector*height*0.0f)).ptr());
// glVertex3fv((v + (rightVector*hp*width - upVector*height*0.0f)).ptr());
// glVertex3fv((v + (rightVector*hp*width + upVector*height)).ptr());
// //epbar
// glColor4f(brightness,0,brightness,0.4f);
// glVertex3fv((v - (rightVector*width + upVector*height*0.0f)).ptr());
// glVertex3fv((v - (rightVector*width + upVector*height)).ptr());
// glVertex3fv((v + (rightVector*ep*width - upVector*height)).ptr());
// glVertex3fv((v + (rightVector*ep*width - upVector*height*0.0f)).ptr());
// }
// glEnd();
2014-10-26 21:34:14 +01:00
2014-11-05 02:05:47 +01:00
if ( lineBorder ) {
//border
2014-11-22 23:15:19 +01:00
glColor4f ( red * brightness , green * brightness , 0.1f * brightness , 0.5f ) ;
2014-11-05 02:05:47 +01:00
glBegin ( GL_LINE_LOOP ) ;
2014-11-22 23:15:19 +01:00
glVertex3fv ( ( v - ( rightVector * width - upVector * height * yOffset ) ) . ptr ( ) ) ;
glVertex3fv ( ( v - ( rightVector * width + upVector * height * yOffset ) ) . ptr ( ) ) ;
glVertex3fv ( ( v + ( rightVector * width - upVector * height * yOffset ) ) . ptr ( ) ) ;
glVertex3fv ( ( v + ( rightVector * width + upVector * height * yOffset ) ) . ptr ( ) ) ;
2014-11-05 02:05:47 +01:00
glEnd ( ) ;
}
2014-10-26 21:34:14 +01:00
2014-11-05 02:05:47 +01:00
if ( texture ! = NULL ) {
//BorderTexture
glEnable ( GL_TEXTURE_2D ) ;
glBindTexture ( GL_TEXTURE_2D , static_cast < const Texture2DGl * > ( texture ) - > getHandle ( ) ) ;
glColor4f ( 1.f , 1.f , 1.f , 1.f ) ;
//glColor4f(red+0.1f,green+0.1f,0.1f,0.5f);
glBegin ( GL_QUADS ) ;
glTexCoord2i ( 0 , 1 ) ;
2014-11-22 23:15:19 +01:00
glVertex3fv ( ( v - ( rightVectorTexture * width - upVectorTexture * height * yOffset ) ) . ptr ( ) ) ;
2014-11-05 02:05:47 +01:00
glTexCoord2i ( 0 , 0 ) ;
2014-11-22 23:15:19 +01:00
glVertex3fv ( ( v - ( rightVectorTexture * width + upVectorTexture * height * yOffset ) ) . ptr ( ) ) ;
2014-11-05 02:05:47 +01:00
glTexCoord2i ( 1 , 0 ) ;
2014-11-22 23:15:19 +01:00
glVertex3fv ( ( v + ( rightVectorTexture * width - upVectorTexture * height * yOffset ) ) . ptr ( ) ) ;
2014-11-05 02:05:47 +01:00
glTexCoord2i ( 1 , 1 ) ;
2014-11-22 23:15:19 +01:00
glVertex3fv ( ( v + ( rightVectorTexture * width + upVectorTexture * height * yOffset ) ) . ptr ( ) ) ;
2014-11-05 02:05:47 +01:00
glEnd ( ) ;
glDisable ( GL_TEXTURE_2D ) ;
}
2014-10-26 21:34:14 +01:00
glPopMatrix ( ) ;
}
2010-03-13 22:10:45 +01:00
2014-11-22 23:15:19 +01:00
void Renderer : : internalRenderHp ( int numberOfBars , int barNumber , float hp ,
Vec3f posVector , float width , float singleHPheight , Vec3f rightVector , Vec3f upVector ) {
float yOffset = ( float ) numberOfBars * singleHPheight / 2 ;
float offsetTop = yOffset - singleHPheight * ( barNumber - 1 ) ;
float offsetBottom = yOffset - singleHPheight * barNumber ;
offsetBottom = offsetBottom * - 1 ;
hp = hp * 2 - 1 ;
glBegin ( GL_QUADS ) ;
glVertex3fv ( ( posVector - ( rightVector * width - upVector * offsetTop ) ) . ptr ( ) ) ;
glVertex3fv ( ( posVector - ( rightVector * width + upVector * offsetBottom ) ) . ptr ( ) ) ;
glVertex3fv ( ( posVector + ( rightVector * hp * width - upVector * offsetBottom ) ) . ptr ( ) ) ;
glVertex3fv ( ( posVector + ( rightVector * hp * width + upVector * offsetTop ) ) . ptr ( ) ) ;
glEnd ( ) ;
}
2011-07-07 00:02:38 +02:00
void Renderer : : renderSelectionCircle ( Vec3f v , int size , float radius , float thickness ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2010-03-13 22:10:45 +01:00
GLUquadricObj * disc ;
glMatrixMode ( GL_MODELVIEW ) ;
glPushMatrix ( ) ;
glTranslatef ( v . x , v . y , v . z ) ;
glRotatef ( 90.f , 1.f , 0.f , 0.f ) ;
disc = gluNewQuadric ( ) ;
gluQuadricDrawStyle ( disc , GLU_FILL ) ;
2011-07-07 00:02:38 +02:00
gluCylinder ( disc , radius * ( size - thickness ) , radius * size , thickness , 30 , 1 ) ;
2010-03-13 22:10:45 +01:00
gluDeleteQuadric ( disc ) ;
glPopMatrix ( ) ;
2014-10-31 01:08:12 +01:00
// glBegin (GL_QUAD_STRIP);
// for (float k = 0; k <= 180; k=k+1) {
// float j=degToRad(k);
// glVertex3f(v.x+std::cos(j)*.9*radius*size, v.y+thickness, v.z+std::sin(j)*.9*radius*size);
// glVertex3f(v.x+std::cos(j)*radius*size, v.y, v.z+std::sin(j)*radius*size);
// }
// glEnd();
2010-03-13 22:10:45 +01:00
}
2010-09-10 10:51:32 +02:00
void Renderer : : renderArrow ( const Vec3f & pos1 , const Vec3f & pos2 ,
const Vec3f & color , float width ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2012-02-03 07:16:50 +01:00
Config & config = Config : : getInstance ( ) ;
if ( config . getBool ( " RecordMode " , " false " ) = = true ) {
return ;
}
2010-03-13 22:10:45 +01:00
const int tesselation = 3 ;
const float arrowEndSize = 0.4f ;
const float maxlen = 25 ;
const float blendDelay = 5.f ;
Vec3f dir = Vec3f ( pos2 - pos1 ) ;
2013-06-12 08:14:55 +02:00
float len = dir . length ( ) ;
2010-03-13 22:10:45 +01:00
2010-09-10 10:51:32 +02:00
if ( len > maxlen ) {
2010-03-13 22:10:45 +01:00
return ;
}
float alphaFactor = clamp ( ( maxlen - len ) / blendDelay , 0.f , 1.f ) ;
2013-06-12 08:14:55 +02:00
dir . normalize ( ) ;
2010-03-13 22:10:45 +01:00
Vec3f normal = dir . cross ( Vec3f ( 0 , 1 , 0 ) ) ;
Vec3f pos2Left = pos2 + normal * ( width - 0.05f ) - dir * arrowEndSize * width ;
Vec3f pos2Right = pos2 - normal * ( width - 0.05f ) - dir * arrowEndSize * width ;
Vec3f pos1Left = pos1 + normal * ( width + 0.05f ) ;
Vec3f pos1Right = pos1 - normal * ( width + 0.05f ) ;
//arrow body
2010-09-10 17:57:07 +02:00
glBegin ( GL_TRIANGLE_STRIP ) ;
2010-09-10 10:51:32 +02:00
for ( int i = 0 ; i < = tesselation ; + + i ) {
2010-03-13 22:10:45 +01:00
float t = static_cast < float > ( i ) / tesselation ;
Vec3f a = pos1Left . lerp ( t , pos2Left ) ;
Vec3f b = pos1Right . lerp ( t , pos2Right ) ;
Vec4f c = Vec4f ( color , t * 0.25f * alphaFactor ) ;
glColor4fv ( c . ptr ( ) ) ;
2010-09-10 10:51:32 +02:00
2010-03-13 22:10:45 +01:00
glVertex3fv ( a . ptr ( ) ) ;
glVertex3fv ( b . ptr ( ) ) ;
2010-09-10 17:57:07 +02:00
2010-03-13 22:10:45 +01:00
}
2010-09-10 17:57:07 +02:00
glEnd ( ) ;
2010-03-13 22:10:45 +01:00
//arrow end
glBegin ( GL_TRIANGLES ) ;
glVertex3fv ( ( pos2Left + normal * ( arrowEndSize - 0.1f ) ) . ptr ( ) ) ;
glVertex3fv ( ( pos2Right - normal * ( arrowEndSize - 0.1f ) ) . ptr ( ) ) ;
glVertex3fv ( ( pos2 + dir * ( arrowEndSize - 0.1f ) ) . ptr ( ) ) ;
glEnd ( ) ;
}
2011-06-08 09:18:06 +02:00
void Renderer : : renderProgressBar3D ( int size , int x , int y , Font3D * font , int customWidth ,
2012-09-27 08:12:53 +02:00
string prefixLabel , bool centeredText , int customHeight ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2011-06-08 09:18:06 +02:00
2012-09-27 08:12:53 +02:00
// Makiong this smaller than 14 is a bad idea (since the font size is never smaller than that)
int progressbarHeight = ( customHeight > 0 ? customHeight : 14 ) ;
2011-06-11 10:52:49 +02:00
int currentSize = size ;
int maxSize = maxProgressBar ;
string renderText = intToStr ( static_cast < int > ( size ) ) + " % " ;
2011-06-08 09:18:06 +02:00
if ( customWidth > 0 ) {
if ( size > 0 ) {
currentSize = ( int ) ( ( double ) customWidth * ( ( double ) size / 100.0 ) ) ;
}
maxSize = customWidth ;
2012-10-06 09:06:40 +02:00
//if(maxSize <= 0) {
// maxSize = maxProgressBar;
//}
2011-06-08 09:18:06 +02:00
}
if ( prefixLabel ! = " " ) {
renderText = prefixLabel + renderText ;
}
//bar
glBegin ( GL_QUADS ) ;
glColor4fv ( progressBarFront2 . ptr ( ) ) ;
glVertex2i ( x , y ) ;
2011-06-11 10:52:49 +02:00
glVertex2i ( x , y + progressbarHeight ) ;
2011-06-08 09:18:06 +02:00
glColor4fv ( progressBarFront1 . ptr ( ) ) ;
2011-06-11 10:52:49 +02:00
glVertex2i ( x + currentSize , y + progressbarHeight ) ;
2011-06-08 09:18:06 +02:00
glVertex2i ( x + currentSize , y ) ;
glEnd ( ) ;
//transp bar
glEnable ( GL_BLEND ) ;
glBegin ( GL_QUADS ) ;
glColor4fv ( progressBarBack2 . ptr ( ) ) ;
glVertex2i ( x + currentSize , y ) ;
2011-06-11 10:52:49 +02:00
glVertex2i ( x + currentSize , y + progressbarHeight ) ;
2011-06-08 09:18:06 +02:00
glColor4fv ( progressBarBack1 . ptr ( ) ) ;
2011-06-11 10:52:49 +02:00
glVertex2i ( x + maxSize , y + progressbarHeight ) ;
2011-06-08 09:18:06 +02:00
glVertex2i ( x + maxSize , y ) ;
glEnd ( ) ;
glDisable ( GL_BLEND ) ;
//text
2011-06-11 10:52:49 +02:00
//glColor3fv(defColor.ptr());
//printf("Render progress bar3d renderText [%s] y = %d, centeredText = %d\n",renderText.c_str(),y, centeredText);
2011-06-08 09:18:06 +02:00
2012-07-26 08:27:00 +02:00
renderTextBoundingBox3D ( renderText , font , defColor , x , y , maxSize ,
2012-07-26 17:26:59 +02:00
progressbarHeight , true , true , false , - 1 , - 1 ) ;
2011-06-08 09:18:06 +02:00
}
2011-04-20 07:24:11 +02:00
void Renderer : : renderProgressBar ( int size , int x , int y , Font2D * font , int customWidth ,
string prefixLabel , bool centeredText ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2011-01-04 09:44:00 +01:00
int currentSize = size ;
int maxSize = maxProgressBar ;
string renderText = intToStr ( static_cast < int > ( size ) ) + " % " ;
if ( customWidth > 0 ) {
if ( size > 0 ) {
2011-01-09 10:32:32 +01:00
currentSize = ( int ) ( ( double ) customWidth * ( ( double ) size / 100.0 ) ) ;
2011-01-04 09:44:00 +01:00
}
maxSize = customWidth ;
2012-10-06 09:06:40 +02:00
//if(maxSize <= 0) {
// maxSize = maxProgressBar;
//}
2011-01-04 09:44:00 +01:00
}
if ( prefixLabel ! = " " ) {
renderText = prefixLabel + renderText ;
}
2010-03-13 22:10:45 +01:00
//bar
glBegin ( GL_QUADS ) ;
glColor4fv ( progressBarFront2 . ptr ( ) ) ;
glVertex2i ( x , y ) ;
glVertex2i ( x , y + 10 ) ;
glColor4fv ( progressBarFront1 . ptr ( ) ) ;
2011-01-04 09:44:00 +01:00
glVertex2i ( x + currentSize , y + 10 ) ;
glVertex2i ( x + currentSize , y ) ;
2010-03-13 22:10:45 +01:00
glEnd ( ) ;
//transp bar
glEnable ( GL_BLEND ) ;
glBegin ( GL_QUADS ) ;
glColor4fv ( progressBarBack2 . ptr ( ) ) ;
2011-01-04 09:44:00 +01:00
glVertex2i ( x + currentSize , y ) ;
glVertex2i ( x + currentSize , y + 10 ) ;
2010-03-13 22:10:45 +01:00
glColor4fv ( progressBarBack1 . ptr ( ) ) ;
2011-01-04 09:44:00 +01:00
glVertex2i ( x + maxSize , y + 10 ) ;
glVertex2i ( x + maxSize , y ) ;
2010-03-13 22:10:45 +01:00
glEnd ( ) ;
glDisable ( GL_BLEND ) ;
//text
glColor3fv ( defColor . ptr ( ) ) ;
2011-06-08 09:18:06 +02:00
2011-10-02 04:14:05 +02:00
//textRenderer->begin(font);
TextRendererSafeWrapper safeTextRender ( textRenderer , font ) ;
2011-04-20 07:24:11 +02:00
if ( centeredText = = true ) {
textRenderer - > render ( renderText . c_str ( ) , x + maxSize / 2 , y , centeredText ) ;
}
else {
textRenderer - > render ( renderText . c_str ( ) , x , y , centeredText ) ;
}
2011-10-02 04:14:05 +02:00
//textRenderer->end();
safeTextRender . end ( ) ;
2010-03-13 22:10:45 +01:00
}
2017-10-10 05:21:14 +02:00
//void Renderer::renderTile(const Vec2i &pos) {
// if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
// return;
// }
//
// const Map *map= game->getWorld()->getMap();
// Vec2i scaledPos= pos * Map::cellScale;
//
// glMatrixMode(GL_MODELVIEW);
// glPushMatrix();
// glTranslatef(-0.5f, 0.f, -0.5f);
//
// glInitNames();
// for(int i=0; i < Map::cellScale; ++i) {
// for(int j=0; j < Map::cellScale; ++j) {
//
// Vec2i renderPos= scaledPos + Vec2i(i, j);
//
// glPushName(renderPos.y);
// glPushName(renderPos.x);
//
// glDisable(GL_CULL_FACE);
//
// float h1 = map->getCell(renderPos.x, renderPos.y)->getHeight();
// float h2 = map->getCell(renderPos.x, renderPos.y+1)->getHeight();
// float h3 = map->getCell(renderPos.x+1, renderPos.y)->getHeight();
// float h4 = map->getCell(renderPos.x+1, renderPos.y+1)->getHeight();
//
// glBegin(GL_TRIANGLE_STRIP);
// glVertex3f(
// static_cast<float>(renderPos.x),
// h1,
// static_cast<float>(renderPos.y));
// glVertex3f(
// static_cast<float>(renderPos.x),
// h2,
// static_cast<float>(renderPos.y+1));
// glVertex3f(
// static_cast<float>(renderPos.x+1),
// h3,
// static_cast<float>(renderPos.y));
// glVertex3f(
// static_cast<float>(renderPos.x+1),
// h4,
// static_cast<float>(renderPos.y+1));
// glEnd();
//
// glPopName();
// glPopName();
// }
// }
//
// glPopMatrix();
//}
2010-03-13 22:10:45 +01:00
2010-09-10 10:51:32 +02:00
void Renderer : : renderQuad ( int x , int y , int w , int h , const Texture2D * texture ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2013-08-02 00:22:21 +02:00
if ( texture = = NULL ) {
printf ( " \n **WARNING** detected a null texture to render in renderQuad! \n " ) ;
return ;
2011-03-25 11:11:16 +01:00
}
2011-02-09 09:04:21 +01:00
2011-04-30 01:48:46 +02:00
if ( w < 0 ) {
w = texture - > getPixmapConst ( ) - > getW ( ) ;
}
if ( h < 0 ) {
h = texture - > getPixmapConst ( ) - > getH ( ) ;
}
glBindTexture ( GL_TEXTURE_2D , static_cast < const Texture2DGl * > ( texture ) - > getHandle ( ) ) ;
2010-03-13 22:10:45 +01:00
glBegin ( GL_TRIANGLE_STRIP ) ;
glTexCoord2i ( 0 , 1 ) ;
glVertex2i ( x , y + h ) ;
glTexCoord2i ( 0 , 0 ) ;
glVertex2i ( x , y ) ;
glTexCoord2i ( 1 , 1 ) ;
glVertex2i ( x + w , y + h ) ;
glTexCoord2i ( 1 , 0 ) ;
glVertex2i ( x + w , y ) ;
glEnd ( ) ;
}
Renderer : : Shadows Renderer : : strToShadows ( const string & s ) {
if ( s = = " Projected " ) {
return sProjected ;
}
else if ( s = = " ShadowMapping " ) {
return sShadowMapping ;
}
return sDisabled ;
}
string Renderer : : shadowsToStr ( Shadows shadows ) {
switch ( shadows ) {
case sDisabled :
2015-02-06 01:02:34 +01:00
return " Disabled2 " ;
2010-03-13 22:10:45 +01:00
case sProjected :
return " Projected " ;
case sShadowMapping :
return " ShadowMapping " ;
default :
assert ( false ) ;
return " " ;
}
}
Texture2D : : Filter Renderer : : strToTextureFilter ( const string & s ) {
if ( s = = " Bilinear " ) {
return Texture2D : : fBilinear ;
}
else if ( s = = " Trilinear " ) {
return Texture2D : : fTrilinear ;
}
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " Error converting from string to FilterType, found: " + s ) ;
2010-03-13 22:10:45 +01:00
}
2010-05-29 09:07:46 +02:00
void Renderer : : setAllowRenderUnitTitles ( bool value ) {
allowRenderUnitTitles = value ;
}
2011-07-01 09:46:18 +02:00
// This method renders titles for units
void Renderer : : renderUnitTitles3D ( Font3D * font , Vec3f color ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2012-10-06 09:06:40 +02:00
//std::map<int,bool> unitRenderedList;
2011-07-01 09:46:18 +02:00
2011-09-01 01:10:43 +02:00
if ( visibleFrameUnitList . empty ( ) = = false ) {
2011-07-01 09:46:18 +02:00
//printf("Render Unit titles ON\n");
2013-11-19 07:14:06 +01:00
for ( int idx = 0 ; idx < ( int ) visibleFrameUnitList . size ( ) ; idx + + ) {
2011-07-01 09:46:18 +02:00
const Unit * unit = visibleFrameUnitList [ idx ] ;
2011-08-31 22:04:50 +02:00
if ( unit ! = NULL ) {
if ( unit - > getVisible ( ) = = true ) {
2011-09-01 20:08:56 +02:00
if ( unit - > getCurrentUnitTitle ( ) ! = " " ) {
2011-08-31 22:04:50 +02:00
//get the screen coordinates
Vec3f screenPos = unit - > getScreenPos ( ) ;
2013-06-12 03:07:53 +02:00
renderText3D ( unit - > getCurrentUnitTitle ( ) , font , color , std : : fabs ( screenPos . x ) + 5 , std : : fabs ( screenPos . y ) + 5 , false ) ;
2012-10-06 09:06:40 +02:00
//unitRenderedList[unit->getId()] = true;
2011-08-31 22:04:50 +02:00
}
else {
2013-06-13 10:55:48 +02:00
string str = unit - > getFullName ( unit - > showTranslatedTechTree ( ) ) + " - " + intToStr ( unit - > getId ( ) ) + " [ " + unit - > getPosNotThreadSafe ( ) . getString ( ) + " ] " ;
2011-08-31 22:04:50 +02:00
Vec3f screenPos = unit - > getScreenPos ( ) ;
2013-06-12 03:07:53 +02:00
renderText3D ( str , font , color , std : : fabs ( screenPos . x ) + 5 , std : : fabs ( screenPos . y ) + 5 , false ) ;
2011-08-31 22:04:50 +02:00
}
2011-07-01 09:46:18 +02:00
}
}
}
visibleFrameUnitList . clear ( ) ;
}
/*
2011-09-01 01:10:43 +02:00
if ( renderUnitTitleList . empty ( ) = = false ) {
2011-07-01 09:46:18 +02:00
for ( int idx = 0 ; idx < renderUnitTitleList . size ( ) ; idx + + ) {
std : : pair < Unit * , Vec3f > & unitInfo = renderUnitTitleList [ idx ] ;
Unit * unit = unitInfo . first ;
const World * world = game - > getWorld ( ) ;
Unit * validUnit = world - > findUnitById ( unit - > getId ( ) ) ;
if ( validUnit ! = NULL & & unitRenderedList . find ( validUnit - > getId ( ) ) = = unitRenderedList . end ( ) ) {
string str = validUnit - > getFullName ( ) + " - " + intToStr ( validUnit - > getId ( ) ) ;
//get the screen coordinates
Vec3f & screenPos = unitInfo . second ;
renderText ( str , font , color , fabs ( screenPos . x ) + 5 , fabs ( screenPos . y ) + 5 , false ) ;
2012-03-29 20:14:25 +02:00
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] screenPos.x = %f, screenPos.y = %f, screenPos.z = %f\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,screenPos.x,screenPos.y,screenPos.z);
2011-07-01 09:46:18 +02:00
}
}
renderUnitTitleList . clear ( ) ;
}
*/
}
2010-05-29 07:41:40 +02:00
// This method renders titles for units
void Renderer : : renderUnitTitles ( Font2D * font , Vec3f color ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2012-10-06 09:06:40 +02:00
//std::map<int,bool> unitRenderedList;
2010-09-01 01:14:15 +02:00
2011-09-01 01:10:43 +02:00
if ( visibleFrameUnitList . empty ( ) = = false ) {
2011-07-01 09:46:18 +02:00
//printf("Render Unit titles ON\n");
2013-11-19 07:14:06 +01:00
for ( int idx = 0 ; idx < ( int ) visibleFrameUnitList . size ( ) ; idx + + ) {
2010-09-01 01:14:15 +02:00
const Unit * unit = visibleFrameUnitList [ idx ] ;
2011-08-31 21:44:19 +02:00
if ( unit ! = NULL ) {
if ( unit - > getCurrentUnitTitle ( ) ! = " " ) {
//get the screen coordinates
Vec3f screenPos = unit - > getScreenPos ( ) ;
2013-06-12 03:07:53 +02:00
renderText ( unit - > getCurrentUnitTitle ( ) , font , color , std : : fabs ( screenPos . x ) + 5 , std : : fabs ( screenPos . y ) + 5 , false ) ;
2010-09-01 01:14:15 +02:00
2012-10-06 09:06:40 +02:00
//unitRenderedList[unit->getId()] = true;
2011-08-31 21:44:19 +02:00
}
else {
2013-06-13 10:55:48 +02:00
string str = unit - > getFullName ( unit - > showTranslatedTechTree ( ) ) + " - " + intToStr ( unit - > getId ( ) ) + " [ " + unit - > getPosNotThreadSafe ( ) . getString ( ) + " ] " ;
2011-08-31 21:44:19 +02:00
Vec3f screenPos = unit - > getScreenPos ( ) ;
2013-06-12 03:07:53 +02:00
renderText ( str , font , color , std : : fabs ( screenPos . x ) + 5 , std : : fabs ( screenPos . y ) + 5 , false ) ;
2011-08-31 21:44:19 +02:00
}
2010-11-02 20:52:20 +01:00
}
2010-09-01 01:14:15 +02:00
}
visibleFrameUnitList . clear ( ) ;
}
2010-11-02 20:52:20 +01:00
/*
2011-09-01 01:10:43 +02:00
if ( renderUnitTitleList . empty ( ) = = false ) {
2010-05-29 07:41:40 +02:00
for ( int idx = 0 ; idx < renderUnitTitleList . size ( ) ; idx + + ) {
std : : pair < Unit * , Vec3f > & unitInfo = renderUnitTitleList [ idx ] ;
Unit * unit = unitInfo . first ;
2010-10-19 06:38:55 +02:00
const World * world = game - > getWorld ( ) ;
Unit * validUnit = world - > findUnitById ( unit - > getId ( ) ) ;
if ( validUnit ! = NULL & & unitRenderedList . find ( validUnit - > getId ( ) ) = = unitRenderedList . end ( ) ) {
string str = validUnit - > getFullName ( ) + " - " + intToStr ( validUnit - > getId ( ) ) ;
2010-05-29 07:41:40 +02:00
//get the screen coordinates
Vec3f & screenPos = unitInfo . second ;
renderText ( str , font , color , fabs ( screenPos . x ) + 5 , fabs ( screenPos . y ) + 5 , false ) ;
2012-03-29 20:14:25 +02:00
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] screenPos.x = %f, screenPos.y = %f, screenPos.z = %f\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,screenPos.x,screenPos.y,screenPos.z);
2010-05-29 07:41:40 +02:00
}
}
renderUnitTitleList . clear ( ) ;
}
2010-11-02 20:52:20 +01:00
*/
2010-05-29 07:41:40 +02:00
}
2010-09-10 21:44:00 +02:00
void Renderer : : removeObjectFromQuadCache ( const Object * o ) {
VisibleQuadContainerCache & qCache = getQuadCache ( ) ;
for ( int visibleIndex = 0 ;
2013-11-19 07:14:06 +01:00
visibleIndex < ( int ) qCache . visibleObjectList . size ( ) ; + + visibleIndex ) {
2010-09-10 21:44:00 +02:00
Object * currentObj = qCache . visibleObjectList [ visibleIndex ] ;
if ( currentObj = = o ) {
qCache . visibleObjectList . erase ( qCache . visibleObjectList . begin ( ) + visibleIndex ) ;
break ;
}
}
}
void Renderer : : removeUnitFromQuadCache ( const Unit * unit ) {
VisibleQuadContainerCache & qCache = getQuadCache ( ) ;
for ( int visibleIndex = 0 ;
2013-11-19 07:14:06 +01:00
visibleIndex < ( int ) qCache . visibleQuadUnitList . size ( ) ; + + visibleIndex ) {
2010-09-10 21:44:00 +02:00
Unit * currentUnit = qCache . visibleQuadUnitList [ visibleIndex ] ;
if ( currentUnit = = unit ) {
qCache . visibleQuadUnitList . erase ( qCache . visibleQuadUnitList . begin ( ) + visibleIndex ) ;
break ;
}
}
for ( int visibleIndex = 0 ;
2013-11-19 07:14:06 +01:00
visibleIndex < ( int ) qCache . visibleUnitList . size ( ) ; + + visibleIndex ) {
2010-09-10 21:44:00 +02:00
Unit * currentUnit = qCache . visibleUnitList [ visibleIndex ] ;
if ( currentUnit = = unit ) {
qCache . visibleUnitList . erase ( qCache . visibleUnitList . begin ( ) + visibleIndex ) ;
break ;
}
}
}
2010-09-10 10:51:32 +02:00
VisibleQuadContainerCache & Renderer : : getQuadCache ( bool updateOnDirtyFrame ,
bool forceNew ) {
//forceNew = true;
2010-09-10 02:28:14 +02:00
if ( game ! = NULL & & game - > getWorld ( ) ! = NULL ) {
const World * world = game - > getWorld ( ) ;
2010-09-10 10:51:32 +02:00
if ( forceNew = = true | |
( updateOnDirtyFrame = = true & &
2010-09-10 02:41:51 +02:00
( world - > getFrameCount ( ) ! = quadCache . cacheFrame | |
2010-09-10 10:51:32 +02:00
visibleQuad ! = quadCache . lastVisibleQuad ) ) ) {
2010-09-10 02:41:51 +02:00
2010-09-10 02:28:14 +02:00
// Dump cached info
2010-09-10 10:51:32 +02:00
//if(forceNew == true || visibleQuad != quadCache.lastVisibleQuad) {
//quadCache.clearCacheData();
//}
//else {
quadCache . clearVolatileCacheData ( ) ;
2012-06-22 15:30:15 +02:00
worldToScreenPosCache . clear ( ) ;
2010-09-10 10:51:32 +02:00
//}
2010-09-10 02:28:14 +02:00
// Unit calculations
for ( int i = 0 ; i < world - > getFactionCount ( ) ; + + i ) {
2010-09-10 10:51:32 +02:00
const Faction * faction = world - > getFaction ( i ) ;
for ( int j = 0 ; j < faction - > getUnitCount ( ) ; + + j ) {
Unit * unit = faction - > getUnit ( j ) ;
2010-09-10 11:09:12 +02:00
2012-06-22 06:58:44 +02:00
bool unitCheckedForRender = false ;
2011-12-13 21:29:32 +01:00
if ( VisibleQuadContainerCache : : enableFrustumCalcs = = true ) {
2011-11-30 06:57:14 +01:00
//bool insideQuad = PointInFrustum(quadCache.frustumData, unit->getCurrVector().x, unit->getCurrVector().y, unit->getCurrVector().z );
2014-11-25 23:40:47 +01:00
bool insideQuad = CubeInFrustum ( quadCache . frustumData , unit - > getCurrMidHeightVector ( ) . x , unit - > getCurrMidHeightVector ( ) . y , unit - > getCurrMidHeightVector ( ) . z , unit - > getType ( ) - > getRenderSize ( ) ) ;
2011-11-30 06:57:14 +01:00
bool renderInMap = world - > toRenderUnit ( unit ) ;
2011-12-13 21:29:32 +01:00
if ( insideQuad = = false | | renderInMap = = false ) {
2011-11-30 06:57:14 +01:00
unit - > setVisible ( false ) ;
2011-12-13 21:29:32 +01:00
if ( renderInMap = = true ) {
quadCache . visibleUnitList . push_back ( unit ) ;
}
2012-06-22 06:58:44 +02:00
unitCheckedForRender = true ; // no more need to check any further;
2011-11-30 06:57:14 +01:00
// Currently don't need this list
//quadCache.inVisibleUnitList.push_back(unit);
}
2011-12-13 21:29:32 +01:00
}
2012-06-22 06:58:44 +02:00
if ( unitCheckedForRender = = false ) {
bool insideQuad = visibleQuad . isInside ( unit - > getPos ( ) ) ;
bool renderInMap = world - > toRenderUnit ( unit ) ;
if ( insideQuad = = true & & renderInMap = = true ) {
quadCache . visibleQuadUnitList . push_back ( unit ) ;
}
else {
unit - > setVisible ( false ) ;
// Currently don't need this list
//quadCache.inVisibleUnitList.push_back(unit);
}
2010-09-10 10:51:32 +02:00
2012-06-22 06:58:44 +02:00
if ( renderInMap = = true ) {
quadCache . visibleUnitList . push_back ( unit ) ;
}
2011-12-13 21:29:32 +01:00
}
2012-06-22 06:58:44 +02:00
bool unitBuildPending = unit - > isBuildCommandPending ( ) ;
if ( unitBuildPending = = true ) {
2012-06-22 15:30:15 +02:00
const UnitBuildInfo & pendingUnit = unit - > getBuildCommandPendingInfo ( ) ;
const Vec2i & pos = pendingUnit . pos ;
2012-06-22 06:58:44 +02:00
const Map * map = world - > getMap ( ) ;
bool unitBuildCheckedForRender = false ;
//printf("#1 Unit is about to build another unit\n");
if ( VisibleQuadContainerCache : : enableFrustumCalcs = = true ) {
Vec3f pos3f = Vec3f ( pos . x , map - > getCell ( pos ) - > getHeight ( ) , pos . y ) ;
//bool insideQuad = PointInFrustum(quadCache.frustumData, unit->getCurrVector().x, unit->getCurrVector().y, unit->getCurrVector().z );
2013-12-30 16:19:08 +01:00
bool insideQuad = CubeInFrustum ( quadCache . frustumData , pos3f . x , pos3f . y , pos3f . z , pendingUnit . buildUnit - > getRenderSize ( ) ) ;
2012-06-22 15:30:15 +02:00
bool renderInMap = world - > toRenderUnit ( pendingUnit ) ;
2012-06-22 06:58:44 +02:00
if ( insideQuad = = false | | renderInMap = = false ) {
if ( renderInMap = = true ) {
quadCache . visibleQuadUnitBuildList . push_back ( pendingUnit ) ;
}
unitBuildCheckedForRender = true ; // no more need to check any further;
// Currently don't need this list
//quadCache.inVisibleUnitList.push_back(unit);
}
//printf("#2 Unit build added? insideQuad = %d, renderInMap = %d\n",insideQuad,renderInMap);
}
if ( unitBuildCheckedForRender = = false ) {
bool insideQuad = visibleQuad . isInside ( pos ) ;
2012-06-22 15:30:15 +02:00
bool renderInMap = world - > toRenderUnit ( pendingUnit ) ;
2012-06-22 06:58:44 +02:00
if ( insideQuad = = true & & renderInMap = = true ) {
quadCache . visibleQuadUnitBuildList . push_back ( pendingUnit ) ;
}
else {
//unit->setVisible(false);
// Currently don't need this list
//quadCache.inVisibleUnitList.push_back(unit);
}
//printf("#3 Unit build added? insideQuad = %d, renderInMap = %d\n",insideQuad,renderInMap);
}
//printf("#4 quadCache.visibleQuadUnitBuildList.size() = %d\n",quadCache.visibleQuadUnitBuildList.size());
2010-09-10 02:28:14 +02:00
}
}
}
2010-09-10 10:51:32 +02:00
if ( forceNew = = true | | visibleQuad ! = quadCache . lastVisibleQuad ) {
2010-09-10 02:41:51 +02:00
// Object calculations
const Map * map = world - > getMap ( ) ;
2011-03-05 15:34:36 +01:00
// clear visibility of old objects
for ( int visibleIndex = 0 ;
2013-11-19 07:14:06 +01:00
visibleIndex < ( int ) quadCache . visibleObjectList . size ( ) ; + + visibleIndex ) {
2011-03-05 15:34:36 +01:00
quadCache . visibleObjectList [ visibleIndex ] - > setVisible ( false ) ;
}
2010-09-10 10:51:32 +02:00
quadCache . clearNonVolatileCacheData ( ) ;
2011-11-23 09:00:09 +01:00
//int loops1=0;
2011-02-25 23:13:11 +01:00
PosQuadIterator pqi ( map , visibleQuad , Map : : cellScale ) ;
2010-09-10 10:51:32 +02:00
while ( pqi . next ( ) ) {
2010-09-10 02:41:51 +02:00
const Vec2i & pos = pqi . getPos ( ) ;
if ( map - > isInside ( pos ) ) {
2011-11-23 09:00:09 +01:00
//loops1++;
2010-09-10 02:41:51 +02:00
const Vec2i & mapPos = Map : : toSurfCoords ( pos ) ;
//quadCache.visibleCellList.push_back(mapPos);
SurfaceCell * sc = map - > getSurfaceCell ( mapPos ) ;
Object * o = sc - > getObject ( ) ;
2010-12-25 09:14:35 +01:00
2011-11-30 06:57:14 +01:00
if ( VisibleQuadContainerCache : : enableFrustumCalcs = = true ) {
if ( o ! = NULL ) {
//bool insideQuad = PointInFrustum(quadCache.frustumData, o->getPos().x, o->getPos().y, o->getPos().z );
bool insideQuad = CubeInFrustum ( quadCache . frustumData , o - > getPos ( ) . x , o - > getPos ( ) . y , o - > getPos ( ) . z , 1 ) ;
if ( insideQuad = = false ) {
2012-03-27 08:09:30 +02:00
o - > setVisible ( false ) ;
2011-11-30 06:57:14 +01:00
continue ;
}
}
}
2010-12-25 09:14:35 +01:00
bool cellExplored = world - > showWorldForPlayer ( world - > getThisFactionIndex ( ) ) ;
if ( cellExplored = = false ) {
cellExplored = sc - > isExplored ( world - > getThisTeamIndex ( ) ) ;
}
bool isExplored = ( cellExplored = = true & & o ! = NULL ) ;
2010-09-10 11:09:12 +02:00
//bool isVisible = (sc->isVisible(world->getThisTeamIndex()) && o != NULL);
2010-09-10 02:41:51 +02:00
bool isVisible = true ;
if ( isExplored = = true & & isVisible = = true ) {
quadCache . visibleObjectList . push_back ( o ) ;
2011-03-05 15:34:36 +01:00
o - > setVisible ( true ) ;
2010-09-10 02:41:51 +02:00
}
2010-09-10 02:28:14 +02:00
}
}
2011-11-23 09:00:09 +01:00
//printf("Frame # = %d loops1 = %d\n",world->getFrameCount(),loops1);
//int loops2=0;
2011-11-30 06:57:14 +01:00
2012-06-12 22:37:00 +02:00
std : : map < Vec2i , MarkedCell > markedCells = game - > getMapMarkedCellList ( ) ;
2010-09-10 10:51:32 +02:00
const Rect2i mapBounds ( 0 , 0 , map - > getSurfaceW ( ) - 1 , map - > getSurfaceH ( ) - 1 ) ;
2010-09-10 02:41:51 +02:00
Quad2i scaledQuad = visibleQuad / Map : : cellScale ;
2011-02-25 23:13:11 +01:00
PosQuadIterator pqis ( map , scaledQuad ) ;
2010-09-10 02:41:51 +02:00
while ( pqis . next ( ) ) {
const Vec2i & pos = pqis . getPos ( ) ;
2010-09-10 10:51:32 +02:00
if ( mapBounds . isInside ( pos ) ) {
2011-11-23 09:00:09 +01:00
//loops2++;
2011-11-30 06:57:14 +01:00
if ( VisibleQuadContainerCache : : enableFrustumCalcs = = false ) {
quadCache . visibleScaledCellList . push_back ( pos ) ;
2012-06-12 22:37:00 +02:00
if ( markedCells . empty ( ) = = false ) {
if ( markedCells . find ( pos ) ! = markedCells . end ( ) ) {
2012-11-10 07:37:23 +01:00
//printf("#1 ******** VISIBLE SCALED CELL FOUND in marked list pos [%s] markedCells.size() = " MG_SIZE_T_SPECIFIER "\n",pos.getString().c_str(),markedCells.size());
2012-06-12 22:37:00 +02:00
//if(markedCells.empty() == false) {
//SurfaceCell *sc = map->getSurfaceCell(pos);
//quadCache.visibleScaledCellToScreenPosList[pos]=computeScreenPosition(sc->getVertex());
updateMarkedCellScreenPosQuadCache ( pos ) ;
}
else {
2012-11-10 07:37:23 +01:00
//printf("#1 VISIBLE SCALED CELL NOT FOUND in marked list pos [%s] markedCells.size() = " MG_SIZE_T_SPECIFIER "\n",pos.getString().c_str(),markedCells.size());
2012-06-12 22:37:00 +02:00
}
}
2011-11-30 06:57:14 +01:00
}
else {
2017-10-10 04:09:36 +02:00
//bool insideQuad = false;
2011-12-14 23:38:02 +01:00
2017-10-10 04:09:36 +02:00
//if( !insideQuad) {
2016-01-29 18:36:48 +01:00
SurfaceCell * sc = map - > getSurfaceCell ( pos . x , pos . y ) ;
2017-10-10 04:09:36 +02:00
bool insideQuad = CubeInFrustum ( quadCache . frustumData , sc - > getVertex ( ) . x , sc - > getVertex ( ) . y , sc - > getVertex ( ) . z , 0 ) ;
//}
2016-01-29 18:36:48 +01:00
if ( ! insideQuad ) {
SurfaceCell * sc = map - > getSurfaceCell ( pos . x + 1 , pos . y ) ;
insideQuad = CubeInFrustum ( quadCache . frustumData , sc - > getVertex ( ) . x , sc - > getVertex ( ) . y , sc - > getVertex ( ) . z , 0 ) ;
}
if ( ! insideQuad ) {
SurfaceCell * sc = map - > getSurfaceCell ( pos . x , pos . y + 1 ) ;
insideQuad = CubeInFrustum ( quadCache . frustumData , sc - > getVertex ( ) . x , sc - > getVertex ( ) . y , sc - > getVertex ( ) . z , 0 ) ;
}
if ( ! insideQuad ) {
SurfaceCell * sc = map - > getSurfaceCell ( pos . x + 1 , pos . y + 1 ) ;
insideQuad = CubeInFrustum ( quadCache . frustumData , sc - > getVertex ( ) . x , sc - > getVertex ( ) . y , sc - > getVertex ( ) . z , 0 ) ;
}
2011-12-14 23:38:02 +01:00
2011-11-30 06:57:14 +01:00
if ( insideQuad = = true ) {
quadCache . visibleScaledCellList . push_back ( pos ) ;
2012-06-12 22:37:00 +02:00
if ( markedCells . empty ( ) = = false ) {
if ( markedCells . find ( pos ) ! = markedCells . end ( ) ) {
2012-11-10 07:37:23 +01:00
//printf("#2 ******** VISIBLE SCALED CELL FOUND in marked list pos [%s] markedCells.size() = " MG_SIZE_T_SPECIFIER "\n",pos.getString().c_str(),markedCells.size());
2012-06-12 22:37:00 +02:00
//if(markedCells.empty() == false) {
//quadCache.visibleScaledCellToScreenPosList[pos]=computeScreenPosition(sc->getVertex());
updateMarkedCellScreenPosQuadCache ( pos ) ;
}
else {
2012-11-10 07:37:23 +01:00
//printf("#2 VISIBLE SCALED CELL NOT FOUND in marked list pos [%s] markedCells.size() = " MG_SIZE_T_SPECIFIER "\n",pos.getString().c_str(),markedCells.size());
2012-06-12 22:37:00 +02:00
}
}
2011-11-30 06:57:14 +01:00
}
}
2010-09-10 02:41:51 +02:00
}
2010-09-10 02:28:14 +02:00
}
2011-11-23 09:00:09 +01:00
//printf("Frame # = %d loops2 = %d\n",world->getFrameCount(),loops2);
2010-09-10 02:41:51 +02:00
}
2010-09-10 02:28:14 +02:00
quadCache . cacheFrame = world - > getFrameCount ( ) ;
2010-09-10 10:51:32 +02:00
quadCache . lastVisibleQuad = visibleQuad ;
2010-09-10 02:28:14 +02:00
}
}
return quadCache ;
}
2012-06-12 22:37:00 +02:00
void Renderer : : updateMarkedCellScreenPosQuadCache ( Vec2i pos ) {
const World * world = game - > getWorld ( ) ;
const Map * map = world - > getMap ( ) ;
SurfaceCell * sc = map - > getSurfaceCell ( pos ) ;
quadCache . visibleScaledCellToScreenPosList [ pos ] = computeScreenPosition ( sc - > getVertex ( ) ) ;
}
void Renderer : : forceQuadCacheUpdate ( ) {
quadCache . cacheFrame = - 1 ;
Vec2i clearPos ( - 1 , - 1 ) ;
quadCache . lastVisibleQuad . p [ 0 ] = clearPos ;
quadCache . lastVisibleQuad . p [ 1 ] = clearPos ;
quadCache . lastVisibleQuad . p [ 2 ] = clearPos ;
quadCache . lastVisibleQuad . p [ 3 ] = clearPos ;
}
std : : pair < bool , Vec3f > Renderer : : posInCellQuadCache ( Vec2i pos ) {
std : : pair < bool , Vec3f > result = make_pair ( false , Vec3f ( ) ) ;
if ( std : : find (
quadCache . visibleScaledCellList . begin ( ) ,
quadCache . visibleScaledCellList . end ( ) ,
pos ) ! = quadCache . visibleScaledCellList . end ( ) ) {
result . first = true ;
result . second = quadCache . visibleScaledCellToScreenPosList [ pos ] ;
}
return result ;
}
2017-10-10 05:21:14 +02:00
//Vec3f Renderer::getMarkedCellScreenPosQuadCache(Vec2i pos) {
// Vec3f result(-1,-1,-1);
// if(std::find(
// quadCache.visibleScaledCellList.begin(),
// quadCache.visibleScaledCellList.end(),
// pos) != quadCache.visibleScaledCellList.end()) {
// result = quadCache.visibleScaledCellToScreenPosList[pos];
// }
// return result;
//}
2012-06-12 22:37:00 +02:00
2011-06-12 07:54:54 +02:00
void Renderer : : beginRenderToTexture ( Texture2D * * renderToTexture ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2011-06-12 07:54:54 +02:00
static bool supportFBOs = Texture2DGl ( ) . supports_FBO_RBO ( ) ;
if ( supportFBOs = = true & & renderToTexture ! = NULL ) {
Config & config = Config : : getInstance ( ) ;
Texture2D : : Filter textureFilter = strToTextureFilter ( config . getString ( " Filter " ) ) ;
int maxAnisotropy = config . getInt ( " FilterMaxAnisotropy " ) ;
const Metrics & metrics = Metrics : : getInstance ( ) ;
* renderToTexture = GraphicsInterface : : getInstance ( ) . getFactory ( ) - > newTexture2D ( ) ;
Texture2DGl * texture = static_cast < Texture2DGl * > ( * renderToTexture ) ;
texture - > setMipmap ( false ) ;
Pixmap2D * pixmapScreenShot = texture - > getPixmap ( ) ;
pixmapScreenShot - > init ( metrics . getScreenW ( ) , metrics . getScreenH ( ) , 4 ) ;
texture - > setForceCompressionDisabled ( true ) ;
texture - > init ( textureFilter , maxAnisotropy ) ;
texture - > setup_FBO_RBO ( ) ;
assertGl ( ) ;
if ( texture - > checkFrameBufferStatus ( ) = = false ) {
//printf("******************** WARNING CANNOT Attach to FBO!\n");
texture - > end ( ) ;
delete texture ;
* renderToTexture = NULL ;
}
}
}
void Renderer : : endRenderToTexture ( Texture2D * * renderToTexture ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2011-06-12 07:54:54 +02:00
static bool supportFBOs = Texture2DGl ( ) . supports_FBO_RBO ( ) ;
2011-06-29 01:49:45 +02:00
if ( supportFBOs = = true & & renderToTexture ! = NULL & & * renderToTexture ! = NULL ) {
2011-06-12 07:54:54 +02:00
Texture2DGl * texture = static_cast < Texture2DGl * > ( * renderToTexture ) ;
if ( texture ! = NULL ) {
texture - > dettachFrameBufferFromTexture ( ) ;
}
assertGl ( ) ;
}
}
2010-12-05 02:33:28 +01:00
void Renderer : : renderMapPreview ( const MapPreview * map , bool renderAll ,
2010-11-01 17:44:05 +01:00
int screenPosX , int screenPosY ,
Texture2D * * renderToTexture ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2010-12-05 02:33:28 +01:00
2011-02-08 06:54:05 +01:00
static bool supportFBOs = Texture2DGl ( ) . supports_FBO_RBO ( ) ;
2011-11-08 17:41:10 +01:00
if ( Config : : getInstance ( ) . getBool ( " LegacyMapPreviewRendering " , " false " ) = = true ) {
supportFBOs = false ;
}
2011-02-08 06:54:05 +01:00
//static bool supportFBOs = false;
2010-09-16 01:49:26 +02:00
const Metrics & metrics = Metrics : : getInstance ( ) ;
2011-02-08 06:54:05 +01:00
float alt = 0 ;
float showWater = 0 ;
int renderMapHeight = 64 ;
int renderMapWidth = 64 ;
float cellSize = 2 ;
float playerCrossSize = 2 ;
float clientW = renderMapWidth * cellSize ;
float clientH = renderMapHeight * cellSize ; ;
2011-02-08 21:17:16 +01:00
float minDimension = std : : min ( metrics . getVirtualW ( ) , metrics . getVirtualH ( ) ) ;
2011-02-08 06:54:05 +01:00
2010-09-16 01:49:26 +02:00
// stretch small maps to 128x128
if ( map - > getW ( ) < map - > getH ( ) ) {
cellSize = cellSize * renderMapHeight / map - > getH ( ) ;
}
else {
cellSize = cellSize * renderMapWidth / map - > getW ( ) ;
}
assertGl ( ) ;
2011-02-08 06:54:05 +01:00
if ( supportFBOs = = true & & renderToTexture ! = NULL ) {
2010-11-01 17:44:05 +01:00
Config & config = Config : : getInstance ( ) ;
Texture2D : : Filter textureFilter = strToTextureFilter ( config . getString ( " Filter " ) ) ;
int maxAnisotropy = config . getInt ( " FilterMaxAnisotropy " ) ;
* renderToTexture = GraphicsInterface : : getInstance ( ) . getFactory ( ) - > newTexture2D ( ) ;
Texture2DGl * texture = static_cast < Texture2DGl * > ( * renderToTexture ) ;
texture - > setMipmap ( false ) ;
Pixmap2D * pixmapScreenShot = texture - > getPixmap ( ) ;
2011-02-08 21:17:16 +01:00
pixmapScreenShot - > init ( minDimension , minDimension , 4 ) ;
2010-11-01 17:44:05 +01:00
texture - > setForceCompressionDisabled ( true ) ;
texture - > init ( textureFilter , maxAnisotropy ) ;
texture - > setup_FBO_RBO ( ) ;
2011-03-20 01:11:00 +01:00
assertGl ( ) ;
2010-11-01 17:44:05 +01:00
if ( texture - > checkFrameBufferStatus ( ) = = false ) {
//printf("******************** WARNING CANNOT Attach to FBO!\n");
texture - > end ( ) ;
delete texture ;
* renderToTexture = NULL ;
}
}
2011-02-08 06:54:05 +01:00
2011-06-29 01:49:45 +02:00
if ( supportFBOs = = true & & renderToTexture ! = NULL & & * renderToTexture ! = NULL ) {
2011-02-08 06:54:05 +01:00
cellSize = 1 ;
2011-02-08 21:17:16 +01:00
clientW = minDimension ;
clientH = minDimension ;
2011-02-08 06:54:05 +01:00
int mapMaxDimensionSize = std : : max ( map - > getW ( ) , map - > getH ( ) ) ;
switch ( mapMaxDimensionSize ) {
case 8 :
cellSize = 96 ;
break ;
case 16 :
cellSize = 48 ;
break ;
case 32 :
cellSize = 24 ;
break ;
case 64 :
cellSize = 12 ;
break ;
case 128 :
cellSize = 6 ;
break ;
case 256 :
cellSize = 3 ;
break ;
case 512 :
cellSize = 2 ;
break ;
}
}
2010-11-01 17:44:05 +01:00
2010-09-16 01:49:26 +02:00
glFrontFace ( GL_CW ) ;
glEnable ( GL_CULL_FACE ) ;
glMatrixMode ( GL_PROJECTION ) ;
glPushMatrix ( ) ;
glLoadIdentity ( ) ;
2010-11-01 17:44:05 +01:00
2011-03-20 01:11:00 +01:00
assertGl ( ) ;
2011-02-08 06:54:05 +01:00
GLint viewport [ 4 ] ; // Where The original Viewport Values Will Be Stored
2010-11-01 17:44:05 +01:00
2011-06-29 01:49:45 +02:00
if ( supportFBOs = = true & & renderToTexture ! = NULL & & * renderToTexture ! = NULL ) {
2011-02-08 06:54:05 +01:00
glGetIntegerv ( GL_VIEWPORT , viewport ) ;
glOrtho ( 0 , clientW , 0 , clientH , 0 , 1 ) ;
glViewport ( 0 , 0 , clientW , clientH ) ;
}
else {
glOrtho ( 0 , metrics . getVirtualW ( ) , 0 , metrics . getVirtualH ( ) , 0 , 1 ) ;
}
2010-11-01 17:44:05 +01:00
2010-09-16 01:49:26 +02:00
glMatrixMode ( GL_MODELVIEW ) ;
glPushMatrix ( ) ;
glLoadIdentity ( ) ;
2010-11-01 17:44:05 +01:00
2011-06-29 01:49:45 +02:00
if ( supportFBOs = = false | | renderToTexture = = NULL | | * renderToTexture = = NULL ) {
2011-02-08 06:54:05 +01:00
glTranslatef ( static_cast < float > ( screenPosX ) , static_cast < float > ( screenPosY ) - clientH , 0.0f ) ;
}
2010-11-01 17:44:05 +01:00
2011-03-20 01:11:00 +01:00
assertGl ( ) ;
2010-09-16 01:49:26 +02:00
glPushAttrib ( GL_CURRENT_BIT ) ;
glLineWidth ( 1 ) ;
glColor3f ( 0 , 0 , 0 ) ;
for ( int j = 0 ; j < map - > getH ( ) ; j + + ) {
for ( int i = 0 ; i < map - > getW ( ) ; i + + ) {
2011-02-08 06:54:05 +01:00
//surface
alt = map - > getHeight ( i , j ) / 20.f ;
showWater = map - > getWaterLevel ( ) / 20.f - alt ;
showWater = ( showWater > 0 ) ? showWater : 0 ;
Vec3f surfColor ;
switch ( map - > getSurface ( i , j ) ) {
case st_Grass :
surfColor = Vec3f ( 0.0 , 0.8f * alt , 0.f + showWater ) ;
2010-11-01 17:44:05 +01:00
break ;
2011-02-08 06:54:05 +01:00
case st_Secondary_Grass :
surfColor = Vec3f ( 0.4f * alt , 0.6f * alt , 0.f + showWater ) ;
2010-11-01 17:44:05 +01:00
break ;
2011-02-08 06:54:05 +01:00
case st_Road :
surfColor = Vec3f ( 0.6f * alt , 0.3f * alt , 0.f + showWater ) ;
2010-11-01 17:44:05 +01:00
break ;
2011-02-08 06:54:05 +01:00
case st_Stone :
surfColor = Vec3f ( 0.7f * alt , 0.7f * alt , 0.7f * alt + showWater ) ;
2010-11-01 17:44:05 +01:00
break ;
2011-02-08 06:54:05 +01:00
case st_Ground :
surfColor = Vec3f ( 0.7f * alt , 0.5f * alt , 0.3f * alt + showWater ) ;
2010-11-01 17:44:05 +01:00
break ;
2010-09-16 01:49:26 +02:00
}
2011-02-08 06:54:05 +01:00
glColor3fv ( surfColor . ptr ( ) ) ;
2010-09-16 01:49:26 +02:00
2011-02-08 06:54:05 +01:00
glBegin ( GL_TRIANGLE_STRIP ) ;
glVertex2f ( i * cellSize , clientH - j * cellSize - cellSize ) ;
glVertex2f ( i * cellSize , clientH - j * cellSize ) ;
glVertex2f ( i * cellSize + cellSize , clientH - j * cellSize - cellSize ) ;
glVertex2f ( i * cellSize + cellSize , clientH - j * cellSize ) ;
glEnd ( ) ;
2010-09-16 01:49:26 +02:00
2011-02-08 06:54:05 +01:00
//objects
if ( renderAll = = true ) {
switch ( map - > getObject ( i , j ) ) {
case 0 :
glColor3f ( 0.f , 0.f , 0.f ) ;
break ;
case 1 :
glColor3f ( 1.f , 0.f , 0.f ) ;
break ;
case 2 :
glColor3f ( 1.f , 1.f , 1.f ) ;
break ;
case 3 :
glColor3f ( 0.5f , 0.5f , 1.f ) ;
break ;
case 4 :
glColor3f ( 0.f , 0.f , 1.f ) ;
break ;
case 5 :
glColor3f ( 0.5f , 0.5f , 0.5f ) ;
break ;
case 6 :
glColor3f ( 1.f , 0.8f , 0.5f ) ;
break ;
case 7 :
glColor3f ( 0.f , 1.f , 1.f ) ;
break ;
case 8 :
glColor3f ( 0.7f , 0.1f , 0.3f ) ;
break ;
case 9 :
glColor3f ( 0.5f , 1.f , 0.1f ) ;
break ;
case 10 :
glColor3f ( 1.f , 0.2f , 0.8f ) ;
break ; // we don't render unvisible blocking objects
}
2010-09-16 01:49:26 +02:00
2011-02-08 06:54:05 +01:00
if ( renderAll & & ( map - > getObject ( i , j ) ! = 0 ) & & ( map - > getObject ( i , j ) ! = 10 ) ) {
glPointSize ( cellSize / 2.f ) ;
glBegin ( GL_POINTS ) ;
glVertex2f ( i * cellSize + cellSize / 2.f , clientH - j * cellSize - cellSize / 2.f ) ;
glEnd ( ) ;
}
2010-09-16 01:49:26 +02:00
}
2011-02-08 06:54:05 +01:00
// bool found = false;
2010-09-16 01:49:26 +02:00
2011-02-08 06:54:05 +01:00
//height lines
// if (!found) {
2010-09-16 01:49:26 +02:00
2011-02-08 06:54:05 +01:00
//left
if ( i > 0 & & map - > getHeight ( i - 1 , j ) > map - > getHeight ( i , j ) ) {
glColor3fv ( ( surfColor * 0.5f ) . ptr ( ) ) ;
glBegin ( GL_LINES ) ;
glVertex2f ( i * cellSize , clientH - ( j + 1 ) * cellSize ) ;
glVertex2f ( i * cellSize , clientH - j * cellSize ) ;
glEnd ( ) ;
}
//down
if ( j > 0 & & map - > getHeight ( i , j - 1 ) > map - > getHeight ( i , j ) ) {
glColor3fv ( ( surfColor * 0.5f ) . ptr ( ) ) ;
glBegin ( GL_LINES ) ;
glVertex2f ( i * cellSize , clientH - j * cellSize ) ;
glVertex2f ( ( i + 1 ) * cellSize , clientH - j * cellSize ) ;
glEnd ( ) ;
2010-09-16 01:49:26 +02:00
}
2011-02-08 06:54:05 +01:00
//left
if ( i > 0 & & map - > getHeight ( i - 1 , j ) < map - > getHeight ( i , j ) ) {
glColor3fv ( ( surfColor * 2.f ) . ptr ( ) ) ;
2010-09-16 01:49:26 +02:00
glBegin ( GL_LINES ) ;
2011-02-08 06:54:05 +01:00
glVertex2f ( i * cellSize , clientH - ( j + 1 ) * cellSize ) ;
2010-09-16 01:49:26 +02:00
glVertex2f ( i * cellSize , clientH - j * cellSize ) ;
glEnd ( ) ;
}
2011-02-08 06:54:05 +01:00
if ( j > 0 & & map - > getHeight ( i , j - 1 ) < map - > getHeight ( i , j ) ) {
glColor3fv ( ( surfColor * 2.f ) . ptr ( ) ) ;
glBegin ( GL_LINES ) ;
glVertex2f ( i * cellSize , clientH - j * cellSize ) ;
glVertex2f ( ( i + 1 ) * cellSize , clientH - j * cellSize ) ;
glEnd ( ) ;
}
// }
//resources
if ( renderAll = = true ) {
switch ( map - > getResource ( i , j ) ) {
case 1 : glColor3f ( 1.f , 1.f , 0.f ) ; break ;
case 2 : glColor3f ( 0.5f , 0.5f , 0.5f ) ; break ;
case 3 : glColor3f ( 1.f , 0.f , 0.f ) ; break ;
case 4 : glColor3f ( 0.f , 0.f , 1.f ) ; break ;
case 5 : glColor3f ( 0.5f , 0.5f , 1.f ) ; break ;
}
2010-09-16 01:49:26 +02:00
2011-02-08 06:54:05 +01:00
if ( renderAll & & map - > getResource ( i , j ) ! = 0 ) {
glBegin ( GL_LINES ) ;
glVertex2f ( i * cellSize , clientH - j * cellSize - cellSize ) ;
glVertex2f ( i * cellSize + cellSize , clientH - j * cellSize ) ;
glVertex2f ( i * cellSize , clientH - j * cellSize ) ;
glVertex2f ( i * cellSize + cellSize , clientH - j * cellSize - cellSize ) ;
glEnd ( ) ;
}
}
}
2010-09-16 01:49:26 +02:00
}
//start locations
glLineWidth ( 3 ) ;
2011-03-20 01:11:00 +01:00
assertGl ( ) ;
2011-06-29 01:49:45 +02:00
if ( supportFBOs = = true & & renderToTexture ! = NULL & & * renderToTexture ! = NULL ) {
2011-02-08 06:54:05 +01:00
glLineWidth ( 14 ) ;
playerCrossSize = 24 ;
2010-11-01 17:44:05 +01:00
}
else {
2011-02-08 06:54:05 +01:00
// force playerCrossSize to be at least of size 4
if ( cellSize < 4 ) {
playerCrossSize = 4 ;
}
else {
playerCrossSize = cellSize ;
}
2010-11-01 17:44:05 +01:00
}
2010-09-16 01:49:26 +02:00
2011-03-20 01:11:00 +01:00
assertGl ( ) ;
2013-05-17 05:59:34 +02:00
Vec2f * vertices = new Vec2f [ map - > getMaxFactions ( ) * 4 ] ;
Vec3f * colors = new Vec3f [ map - > getMaxFactions ( ) * 4 ] ;
2013-02-12 21:47:46 +01:00
2010-09-16 01:49:26 +02:00
for ( int i = 0 ; i < map - > getMaxFactions ( ) ; i + + ) {
2013-02-12 21:47:46 +01:00
Vec3f color ;
switch ( i ) {
case 0 :
color = Vec3f ( 1.f , 0.f , 0.f ) ;
break ;
case 1 :
color = Vec3f ( 0.f , 0.f , 1.f ) ;
break ;
case 2 :
color = Vec3f ( 0.f , 1.f , 0.f ) ;
break ;
case 3 :
color = Vec3f ( 1.f , 1.f , 0.f ) ;
break ;
case 4 :
color = Vec3f ( 1.f , 1.f , 1.f ) ;
break ;
case 5 :
color = Vec3f ( 0.f , 1.f , 0.8f ) ;
break ;
case 6 :
color = Vec3f ( 1.f , 0.5f , 0.f ) ;
break ;
case 7 :
color = Vec3f ( 1.f , 0.5f , 1.f ) ;
break ;
}
2013-05-17 05:59:34 +02:00
colors [ i * 4 ] = color ;
colors [ ( i * 4 ) + 1 ] = color ;
colors [ ( i * 4 ) + 2 ] = color ;
colors [ ( i * 4 ) + 3 ] = color ;
2013-02-12 21:47:46 +01:00
2013-05-17 05:59:34 +02:00
vertices [ i * 4 ] = Vec2f ( ( map - > getStartLocationX ( i ) - 1 ) * cellSize , clientH - ( map - > getStartLocationY ( i ) - 1 ) * cellSize ) ;
vertices [ ( i * 4 ) + 1 ] = Vec2f ( ( map - > getStartLocationX ( i ) + 1 ) * cellSize + playerCrossSize , clientH - ( map - > getStartLocationY ( i ) + 1 ) * cellSize - playerCrossSize ) ;
vertices [ ( i * 4 ) + 2 ] = Vec2f ( ( map - > getStartLocationX ( i ) - 1 ) * cellSize , clientH - ( map - > getStartLocationY ( i ) + 1 ) * cellSize - playerCrossSize ) ;
vertices [ ( i * 4 ) + 3 ] = Vec2f ( ( map - > getStartLocationX ( i ) + 1 ) * cellSize + playerCrossSize , clientH - ( map - > getStartLocationY ( i ) - 1 ) * cellSize ) ;
2010-09-16 01:49:26 +02:00
}
2013-02-12 21:47:46 +01:00
glEnableClientState ( GL_COLOR_ARRAY ) ;
2013-05-17 05:59:34 +02:00
glColorPointer ( 3 , GL_FLOAT , 0 , & colors [ 0 ] ) ;
2013-02-12 21:47:46 +01:00
glEnableClientState ( GL_VERTEX_ARRAY ) ;
2013-05-17 05:59:34 +02:00
glVertexPointer ( 2 , GL_FLOAT , 0 , & vertices [ 0 ] ) ;
2013-02-12 21:47:46 +01:00
glDrawArrays ( GL_LINES , 0 , 4 * map - > getMaxFactions ( ) ) ;
glDisableClientState ( GL_COLOR_ARRAY ) ;
glDisableClientState ( GL_VERTEX_ARRAY ) ;
2011-03-20 01:11:00 +01:00
assertGl ( ) ;
2011-04-24 07:39:13 +02:00
glLineWidth ( 1 ) ;
2010-09-16 01:49:26 +02:00
glPopMatrix ( ) ;
glPopAttrib ( ) ;
glMatrixMode ( GL_PROJECTION ) ;
glPopMatrix ( ) ;
2011-06-29 01:49:45 +02:00
if ( supportFBOs = = true & & renderToTexture ! = NULL & & * renderToTexture ! = NULL ) {
2010-11-01 17:44:05 +01:00
Texture2DGl * texture = static_cast < Texture2DGl * > ( * renderToTexture ) ;
if ( texture ! = NULL ) {
texture - > dettachFrameBufferFromTexture ( ) ;
}
2011-02-08 06:54:05 +01:00
glViewport ( viewport [ 0 ] , viewport [ 1 ] , viewport [ 2 ] , viewport [ 3 ] ) ;
2011-03-20 01:11:00 +01:00
assertGl ( ) ;
2010-11-01 17:44:05 +01:00
}
2011-02-08 06:54:05 +01:00
2013-05-17 05:59:34 +02:00
delete [ ] vertices ;
delete [ ] colors ;
2010-09-16 01:49:26 +02:00
assertGl ( ) ;
}
2010-10-04 18:43:00 +02:00
// setLastRenderFps and calculate shadowsOffDueToMinRender
void Renderer : : setLastRenderFps ( int value ) {
2010-12-05 02:33:28 +01:00
lastRenderFps = value ;
2010-10-04 18:43:00 +02:00
smoothedRenderFps = ( MIN_FPS_NORMAL_RENDERING * smoothedRenderFps + lastRenderFps ) / ( MIN_FPS_NORMAL_RENDERING + 1.0f ) ;
2010-12-05 02:33:28 +01:00
2010-10-04 18:43:00 +02:00
if ( smoothedRenderFps > = MIN_FPS_NORMAL_RENDERING_TOP_THRESHOLD ) {
shadowsOffDueToMinRender = false ;
}
if ( smoothedRenderFps < = MIN_FPS_NORMAL_RENDERING ) {
shadowsOffDueToMinRender = true ;
}
}
2013-12-23 07:53:26 +01:00
std : : size_t Renderer : : getCurrentPixelByteCount ( ResourceScope rs ) const {
std : : size_t result = 0 ;
2010-10-28 23:06:20 +02:00
for ( int i = ( rs = = rsCount ? 0 : rs ) ; i < rsCount ; + + i ) {
2011-11-30 06:57:14 +01:00
if ( textureManager [ i ] ! = NULL ) {
2013-11-19 22:57:28 +01:00
const : : Shared : : Graphics : : TextureContainer & textures = textureManager [ i ] - > getTextures ( ) ;
2013-11-19 07:14:06 +01:00
for ( int j = 0 ; j < ( int ) textures . size ( ) ; + + j ) {
2011-11-30 06:57:14 +01:00
const Texture * texture = textures [ j ] ;
result + = texture - > getPixelByteCount ( ) ;
}
if ( rs ! = rsCount ) {
break ;
}
2010-10-28 23:06:20 +02:00
}
}
return result ;
}
2010-09-16 01:49:26 +02:00
2011-03-22 03:02:54 +01:00
Texture2D * Renderer : : preloadTexture ( string logoFilename ) {
2012-03-29 20:14:25 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] logoFilename [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , logoFilename . c_str ( ) ) ;
2011-01-26 10:09:59 +01:00
Texture2D * result = NULL ;
if ( logoFilename ! = " " ) {
// Cache faction preview textures
string data_path = getGameReadWritePath ( GameConstants : : path_data_CacheLookupKey ) ;
std : : map < string , Texture2D * > & crcFactionPreviewTextureCache = CacheManager : : getCachedItem < std : : map < string , Texture2D * > > ( GameConstants : : factionPreviewTextureCacheLookupKey ) ;
if ( crcFactionPreviewTextureCache . find ( logoFilename ) ! = crcFactionPreviewTextureCache . end ( ) ) {
2012-03-29 20:14:25 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] logoFilename [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , logoFilename . c_str ( ) ) ;
2011-03-31 03:34:01 +02:00
2012-03-29 20:14:25 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] load texture from cache [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , logoFilename . c_str ( ) ) ;
2011-03-31 03:34:01 +02:00
2011-01-26 10:09:59 +01:00
result = crcFactionPreviewTextureCache [ logoFilename ] ;
}
else {
2012-03-29 20:14:25 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] logoFilename [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , logoFilename . c_str ( ) ) ;
2011-01-26 10:09:59 +01:00
Renderer & renderer = Renderer : : getInstance ( ) ;
result = renderer . newTexture2D ( rsGlobal ) ;
2011-09-27 07:29:57 +02:00
if ( result ) {
result - > setMipmap ( true ) ;
result - > load ( logoFilename ) ;
//renderer.initTexture(rsGlobal,result);
}
2011-03-31 03:34:01 +02:00
2012-03-29 20:14:25 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] add texture to manager and cache [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , logoFilename . c_str ( ) ) ;
2011-03-31 03:34:01 +02:00
2011-01-26 10:09:59 +01:00
crcFactionPreviewTextureCache [ logoFilename ] = result ;
}
}
return result ;
}
2012-09-25 09:05:52 +02:00
Texture2D * Renderer : : findTexture ( string logoFilename ) {
2012-03-29 20:14:25 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] logoFilename [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , logoFilename . c_str ( ) ) ;
2011-03-22 03:02:54 +01:00
Texture2D * result = preloadTexture ( logoFilename ) ;
if ( result ! = NULL & & result - > getInited ( ) = = false ) {
Renderer & renderer = Renderer : : getInstance ( ) ;
renderer . initTexture ( rsGlobal , result ) ;
}
return result ;
}
2011-02-06 08:01:54 +01:00
void Renderer : : cycleShowDebugUILevel ( ) {
2011-11-15 05:48:57 +01:00
//printf("#1 showDebugUILevel = %d, debugui_fps = %d, debugui_unit_titles = %d\n",showDebugUILevel,debugui_fps,debugui_unit_titles);
2014-12-20 23:25:42 +01:00
//if(showDebugUI == false) {
// showDebugUI = true;
//}
2011-02-06 08:01:54 +01:00
if ( ( showDebugUILevel & debugui_fps ) ! = debugui_fps | |
( showDebugUILevel & debugui_unit_titles ) ! = debugui_unit_titles ) {
showDebugUILevel | = debugui_fps ;
showDebugUILevel | = debugui_unit_titles ;
}
else {
showDebugUILevel = debugui_fps ;
}
2011-11-15 05:48:57 +01:00
//printf("#2 showDebugUILevel = %d, debugui_fps = %d, debugui_unit_titles = %d\n",showDebugUILevel,debugui_fps,debugui_unit_titles);
2011-02-06 08:01:54 +01:00
}
2011-01-26 10:09:59 +01:00
2011-07-01 04:50:20 +02:00
void Renderer : : renderFPSWhenEnabled ( int lastFps ) {
if ( getShowDebugUI ( ) = = true ) {
CoreData & coreData = CoreData : : getInstance ( ) ;
if ( Renderer : : renderText3DEnabled ) {
renderText3D (
" FPS: " + intToStr ( lastFps ) ,
coreData . getMenuFontNormal3D ( ) , Vec3f ( 1.f ) , 10 , 10 , false ) ;
}
else {
renderText (
" FPS: " + intToStr ( lastFps ) ,
coreData . getMenuFontNormal ( ) , Vec3f ( 1.f ) , 10 , 10 , false ) ;
}
}
}
2011-09-21 08:51:28 +02:00
void Renderer : : renderPopupMenu ( PopupMenu * menu ) {
2011-12-03 01:39:03 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
return ;
}
2011-09-21 08:51:28 +02:00
if ( menu - > getVisible ( ) = = false | | menu - > getEnabled ( ) = = false ) {
return ;
}
//background
glPushAttrib ( GL_ENABLE_BIT | GL_CURRENT_BIT ) ;
glEnable ( GL_BLEND ) ;
glColor4f ( 0.0f , 0.0f , 0.0f , 0.8f ) ;
glBegin ( GL_TRIANGLE_STRIP ) ;
glVertex2i ( menu - > getX ( ) , menu - > getY ( ) + 9 * menu - > getH ( ) / 10 ) ;
glVertex2i ( menu - > getX ( ) , menu - > getY ( ) ) ;
glVertex2i ( menu - > getX ( ) + menu - > getW ( ) , menu - > getY ( ) + 9 * menu - > getH ( ) / 10 ) ;
glVertex2i ( menu - > getX ( ) + menu - > getW ( ) , menu - > getY ( ) ) ;
glEnd ( ) ;
glColor4f ( 0.0f , 0.0f , 0.0f , 0.8f ) ;
glBegin ( GL_TRIANGLE_STRIP ) ;
glVertex2i ( menu - > getX ( ) , menu - > getY ( ) + menu - > getH ( ) ) ;
glVertex2i ( menu - > getX ( ) , menu - > getY ( ) + 9 * menu - > getH ( ) / 10 ) ;
glVertex2i ( menu - > getX ( ) + menu - > getW ( ) , menu - > getY ( ) + menu - > getH ( ) ) ;
glVertex2i ( menu - > getX ( ) + menu - > getW ( ) , menu - > getY ( ) + 9 * menu - > getH ( ) / 10 ) ;
glEnd ( ) ;
glBegin ( GL_LINE_LOOP ) ;
glColor4f ( 0.5f , 0.5f , 0.5f , 0.25f ) ;
glVertex2i ( menu - > getX ( ) , menu - > getY ( ) ) ;
glColor4f ( 0.0f , 0.0f , 0.0f , 0.25f ) ;
glVertex2i ( menu - > getX ( ) + menu - > getW ( ) , menu - > getY ( ) ) ;
glColor4f ( 0.5f , 0.5f , 0.5f , 0.25f ) ;
glVertex2i ( menu - > getX ( ) + menu - > getW ( ) , menu - > getY ( ) + menu - > getH ( ) ) ;
glColor4f ( 0.25f , 0.25f , 0.25f , 0.25f ) ;
glVertex2i ( menu - > getX ( ) , menu - > getY ( ) + menu - > getH ( ) ) ;
glEnd ( ) ;
glBegin ( GL_LINE_STRIP ) ;
glColor4f ( 1.0f , 1.0f , 1.0f , 0.25f ) ;
glVertex2i ( menu - > getX ( ) , menu - > getY ( ) + 90 * menu - > getH ( ) / 100 ) ;
glColor4f ( 0.5f , 0.5f , 0.5f , 0.25f ) ;
glVertex2i ( menu - > getX ( ) + menu - > getW ( ) , menu - > getY ( ) + 90 * menu - > getH ( ) / 100 ) ;
glEnd ( ) ;
glPopAttrib ( ) ;
Vec4f fontColor ;
//if(game!=NULL){
// fontColor=game->getGui()->getDisplay()->getColor();
//}
//else {
// white shadowed is default ( in the menu for example )
fontColor = Vec4f ( 1.f , 1.f , 1.f , 1.0f ) ;
//}
if ( renderText3DEnabled = = true ) {
//text
renderTextBoundingBox3D (
menu - > getHeader ( ) , menu - > getFont3D ( ) , fontColor ,
menu - > getX ( ) , menu - > getY ( ) + 93 * menu - > getH ( ) / 100 , menu - > getW ( ) , 0 ,
2012-07-26 17:26:59 +02:00
true , false , false , - 1 , - 1 ) ;
2011-09-21 08:51:28 +02:00
}
else {
//text
2011-10-05 04:12:53 +02:00
int renderX = ( menu - > getX ( ) + ( menu - > getW ( ) / 2 ) ) ;
//int renderY = (menu->getY() + (menu->getH() / 2));
FontMetrics * fontMetrics = menu - > getFont ( ) - > getMetrics ( ) ;
2011-11-28 06:54:31 +01:00
int renderY = menu - > getY ( ) + menu - > getH ( ) - fontMetrics - > getHeight ( menu - > getHeader ( ) ) ;
2011-09-21 08:51:28 +02:00
renderTextShadow (
menu - > getHeader ( ) , menu - > getFont ( ) , fontColor ,
2011-10-05 04:12:53 +02:00
renderX , renderY ,
2011-09-21 08:51:28 +02:00
true ) ;
2011-10-05 04:12:53 +02:00
//renderText(button->getText(), button->getFont(), color,x + (w / 2), y + (h / 2), true);
2011-09-21 08:51:28 +02:00
}
//buttons
// int maxButtonWidth = -1;
std : : vector < GraphicButton > & menuItems = menu - > getMenuItems ( ) ;
// for(unsigned int i = 0; i < menuItems.size(); ++i) {
// GraphicButton *button = &menuItems[i];
// int currentButtonWidth = -1;
// if(renderText3DEnabled == true) {
// FontMetrics *fontMetrics= menu->getFont3D()->getMetrics();
// currentButtonWidth = fontMetrics->getTextWidth(button->getText());
// }
// else {
// FontMetrics *fontMetrics= menu->getFont()->getMetrics();
// currentButtonWidth = fontMetrics->getTextWidth(button->getText());
// }
//
// if(maxButtonWidth < 0 || currentButtonWidth > maxButtonWidth) {
// maxButtonWidth = currentButtonWidth + 5;
// }
// }
for ( unsigned int i = 0 ; i < menuItems . size ( ) ; + + i ) {
GraphicButton * button = & menuItems [ i ] ;
//button->setW(maxButtonWidth);
renderButton ( button ) ;
}
}
2012-05-23 21:59:52 +02:00
void Renderer : : setupRenderForVideo ( ) {
clearBuffers ( ) ;
//3d
reset3dMenu ( ) ;
clearZBuffer ( ) ;
//2d
reset2d ( ) ;
glClearColor ( 0.f , 0.f , 0.f , 1.f ) ;
}
void Renderer : : renderVideoLoading ( int progressPercent ) {
//printf("Rendering progress progressPercent = %d\n",progressPercent);
setupRenderForVideo ( ) ;
Lang & lang = Lang : : getInstance ( ) ;
2013-10-29 07:13:38 +01:00
string textToRender = lang . getString ( " PleaseWait " ) ;
2012-05-23 21:59:52 +02:00
const Metrics & metrics = Metrics : : getInstance ( ) ;
2012-05-24 09:37:43 +02:00
static Chrono cycle ( true ) ;
static float anim = 0.0f ;
2012-05-24 09:15:15 +02:00
2012-05-23 21:59:52 +02:00
if ( CoreData : : getInstance ( ) . getMenuFontBig3D ( ) ! = NULL ) {
int w = metrics . getVirtualW ( ) ;
2012-10-06 09:06:40 +02:00
int renderX = ( w / 2 ) - ( CoreData : : getInstance ( ) . getMenuFontBig3D ( ) - > getMetrics ( ) - > getTextWidth ( textToRender ) / 2 ) ;
2012-05-23 21:59:52 +02:00
int h = metrics . getVirtualH ( ) ;
2012-10-06 09:06:40 +02:00
int renderY = ( h / 2 ) + ( CoreData : : getInstance ( ) . getMenuFontBig3D ( ) - > getMetrics ( ) - > getHeight ( textToRender ) / 2 ) ;
2012-05-23 21:59:52 +02:00
renderText3D (
textToRender ,
CoreData : : getInstance ( ) . getMenuFontBig3D ( ) ,
2012-05-24 09:15:15 +02:00
Vec4f ( 1.f , 1.f , 0.f , anim ) ,
2012-05-23 21:59:52 +02:00
renderX , renderY , false ) ;
}
else {
renderText (
textToRender ,
CoreData : : getInstance ( ) . getMenuFontBig ( ) ,
2012-05-24 09:15:15 +02:00
Vec4f ( 1.f , 1.f , 0.f , anim ) , ( metrics . getScreenW ( ) / 2 ) ,
2012-05-23 21:59:52 +02:00
( metrics . getScreenH ( ) / 2 ) , true ) ;
}
swapBuffers ( ) ;
2012-05-24 09:37:43 +02:00
if ( cycle . getCurMillis ( ) % 50 = = 0 ) {
2012-10-06 09:06:40 +02:00
static bool animCycleUp = true ;
2012-05-24 09:37:43 +02:00
if ( animCycleUp = = true ) {
2013-01-23 07:53:55 +01:00
anim + = 0.1f ;
2012-05-24 09:37:43 +02:00
if ( anim > 1.f ) {
anim = 1.f ;
cycle . reset ( ) ;
animCycleUp = false ;
}
}
else {
2013-02-01 06:26:07 +01:00
anim - = 0.1f ;
2012-05-24 09:37:43 +02:00
if ( anim < 0.f ) {
anim = 0.f ;
cycle . reset ( ) ;
animCycleUp = true ;
}
}
}
2012-05-23 21:59:52 +02:00
}
2010-03-13 22:10:45 +01:00
} } //end namespace