2010-03-13 22:10:45 +01:00
// This file is part of Glest (www.glest.org)
//
2010-04-04 06:14:27 +02:00
// Copyright (C) 2001-2008 Martio 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
// ==============================================================
# 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-06-15 18:27:52 +02:00
# include <algorithm>
2010-10-22 09:28:55 +02:00
# include "cache_manager.h"
2010-10-22 23:54:47 +02:00
# include "network_manager.h"
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 ;
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-09 02:27:41 +01:00
const float Renderer : : perspNearPlane = 2.f ;
2010-07-15 16:54:19 +02:00
//const float Renderer::perspFarPlane= 50.f;
const float Renderer : : perspFarPlane = 1000.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;
const float Renderer : : maxLightDist = 1000.f ;
2010-03-13 22:10:45 +01:00
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
2010-03-13 22:10:45 +01:00
// ==================== constructor and destructor ====================
2010-09-10 10:51:32 +02:00
Renderer : : Renderer ( ) {
2010-07-30 09:51:39 +02:00
this - > allowRenderUnitTitles = false ;
this - > menu = NULL ;
this - > game = NULL ;
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 ;
particleRenderer = NULL ;
2010-10-30 04:21:47 +02:00
saveScreenShotThread = NULL ;
2011-02-05 06:50:42 +01:00
mapSurfaceData . clear ( ) ;
2010-07-30 09:51:39 +02:00
2010-09-03 03:50:16 +02:00
lastRenderFps = MIN_FPS_NORMAL_RENDERING ;
shadowsOffDueToMinRender = false ;
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
GraphicsInterface & gi = GraphicsInterface : : getInstance ( ) ;
FactoryRepository & fr = FactoryRepository : : getInstance ( ) ;
Config & config = Config : : getInstance ( ) ;
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
2010-03-13 22:10:45 +01:00
gi . setFactory ( fr . getGraphicsFactory ( config . getString ( " FactoryGraphics " ) ) ) ;
GraphicsFactory * graphicsFactory = GraphicsInterface : : getInstance ( ) . getFactory ( ) ;
modelRenderer = graphicsFactory - > newModelRenderer ( ) ;
textRenderer = graphicsFactory - > newTextRenderer2D ( ) ;
particleRenderer = graphicsFactory - > newParticleRenderer ( ) ;
//resources
2010-09-10 10:51:32 +02:00
for ( int i = 0 ; i < rsCount ; + + i ) {
2010-03-13 22:10:45 +01:00
modelManager [ i ] = graphicsFactory - > newModelManager ( ) ;
textureManager [ i ] = graphicsFactory - > newTextureManager ( ) ;
modelManager [ i ] - > setTextureManager ( textureManager [ i ] ) ;
particleManager [ i ] = graphicsFactory - > newParticleManager ( ) ;
fontManager [ i ] = graphicsFactory - > newFontManager ( ) ;
}
2010-12-24 03:10:31 +01:00
2010-10-30 04:21:47 +02:00
saveScreenShotThread = new SimpleTaskThread ( this , 0 , 25 ) ;
saveScreenShotThread - > setUniqueID ( __FILE__ ) ;
saveScreenShotThread - > start ( ) ;
2010-03-13 22:10:45 +01:00
}
2010-10-30 04:21:47 +02:00
Renderer : : ~ Renderer ( ) {
2010-03-13 22:10:45 +01:00
delete modelRenderer ;
2010-08-21 20:50:56 +02:00
modelRenderer = NULL ;
2010-03-13 22:10:45 +01:00
delete textRenderer ;
2010-08-21 20:50:56 +02:00
textRenderer = NULL ;
2010-03-13 22:10:45 +01:00
delete particleRenderer ;
2010-08-21 20:50:56 +02:00
particleRenderer = NULL ;
2010-03-13 22:10:45 +01:00
//resources
for ( int i = 0 ; i < rsCount ; + + i ) {
delete modelManager [ i ] ;
2010-08-21 20:50:56 +02:00
modelManager [ i ] = NULL ;
2010-03-13 22:10:45 +01:00
delete textureManager [ i ] ;
2010-08-21 20:50:56 +02:00
textureManager [ i ] = NULL ;
2010-03-13 22:10:45 +01:00
delete particleManager [ i ] ;
2010-08-21 20:50:56 +02:00
particleManager [ i ] = NULL ;
2010-03-13 22:10:45 +01:00
delete fontManager [ i ] ;
2010-08-21 20:50:56 +02:00
fontManager [ i ] = NULL ;
2010-03-13 22:10:45 +01:00
}
2010-04-15 07:06:15 +02:00
2010-10-30 04:21:47 +02:00
// Wait for the queue to become empty or timeout the thread at 7 seconds
for ( time_t elapsed = time ( NULL ) ;
getSaveScreenQueueSize ( ) > 0 & & difftime ( time ( NULL ) , elapsed ) < = 7 ; ) {
sleep ( 10 ) ;
}
delete saveScreenShotThread ;
saveScreenShotThread = NULL ;
if ( getSaveScreenQueueSize ( ) > 0 ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] FORCING MEMORY CLEANUP and NOT SAVING screenshots, saveScreenQueue.size() = %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , saveScreenQueue . size ( ) ) ;
for ( std : : list < std : : pair < string , Pixmap2D * > > : : iterator iter = saveScreenQueue . begin ( ) ;
iter ! = saveScreenQueue . end ( ) ; + + iter ) {
delete iter - > second ;
}
}
2010-09-17 06:59:32 +02:00
2011-02-05 06:50:42 +01:00
mapSurfaceData . clear ( ) ;
2010-04-15 07:06:15 +02:00
this - > menu = NULL ;
this - > game = NULL ;
2010-03-13 22:10:45 +01:00
}
2011-01-02 07:46:48 +01:00
void Renderer : : simpleTask ( BaseThread * callingThread ) {
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 = " " ;
2011-02-01 00:01:39 +01:00
MutexSafeWrapper safeMutex ( & saveScreenShotThreadAccessor , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2010-10-30 04:21:47 +02:00
if ( saveScreenQueue . size ( ) > 0 ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] saveScreenQueue.size() = %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , saveScreenQueue . size ( ) ) ;
savePixMapBuffer = saveScreenQueue . front ( ) . second ;
path = saveScreenQueue . front ( ) . first ;
saveScreenQueue . pop_front ( ) ;
}
safeMutex . ReleaseLock ( ) ;
if ( savePixMapBuffer ! = NULL ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] about to save [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , path . c_str ( ) ) ;
savePixMapBuffer - > save ( path ) ;
delete savePixMapBuffer ;
}
}
2010-03-13 22:10:45 +01:00
Renderer & Renderer : : getInstance ( ) {
static Renderer renderer ;
return renderer ;
}
2010-04-04 06:14:27 +02:00
void Renderer : : reinitAll ( ) {
2010-04-05 22:42:05 +02:00
//resources
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 ( ) {
2010-03-13 22:10:45 +01:00
Config & config = Config : : getInstance ( ) ;
loadConfig ( ) ;
if ( config . getBool ( " CheckGlCaps " ) ) {
checkGlCaps ( ) ;
}
if ( config . getBool ( " FirstTime " ) ) {
config . setBool ( " FirstTime " , false ) ;
autoConfig ( ) ;
config . save ( ) ;
}
modelManager [ rsGlobal ] - > init ( ) ;
textureManager [ rsGlobal ] - > init ( ) ;
fontManager [ rsGlobal ] - > init ( ) ;
init2dList ( ) ;
2010-07-16 02:42:13 +02:00
glHint ( GL_FOG_HINT , GL_FASTEST ) ;
//glHint(GL_GENERATE_MIPMAP_HINT, GL_FASTEST);
glHint ( GL_LINE_SMOOTH_HINT , GL_FASTEST ) ;
//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 ) ;
2010-03-13 22:10:45 +01:00
}
2010-04-04 06:14:27 +02:00
void Renderer : : initGame ( const Game * game ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
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 ;
2010-11-02 20:52:20 +01:00
worldToScreenPosCache . clear ( ) ;
2010-03-13 22:10:45 +01:00
//check gl caps
checkGlOptionalCaps ( ) ;
//vars
shadowMapFrame = 0 ;
waterAnim = 0 ;
2010-04-04 06:14:27 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
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 ) ;
glGenTextures ( 1 , & shadowMapHandle ) ;
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 ) {
2010-04-04 06:14:27 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
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 {
2010-04-04 06:14:27 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
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 ;
}
2010-04-04 06:14:27 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
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 ( ) ;
2010-04-04 06:14:27 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
init3dList ( ) ;
}
2011-01-15 09:45:17 +01:00
void Renderer : : initMenu ( const MainMenu * mm ) {
2010-04-04 06:14:27 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
this - > menu = mm ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
modelManager [ rsMenu ] - > init ( ) ;
textureManager [ rsMenu ] - > init ( ) ;
fontManager [ rsMenu ] - > init ( ) ;
//modelRenderer->setCustomTexture(CoreData::getInstance().getCustomTexture());
2010-04-04 06:14:27 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
init3dListMenu ( mm ) ;
2010-04-04 06:14:27 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __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 ) ;
glCallList ( list3d ) ;
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 ) ;
glCallList ( list2d ) ;
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 ) ;
glCallList ( list3dMenu ) ;
assertGl ( ) ;
}
// ==================== end ====================
2011-01-15 09:45:17 +01:00
void Renderer : : end ( ) {
2011-01-26 10:09:59 +01:00
std : : map < string , Texture2D * > & crcFactionPreviewTextureCache = CacheManager : : getCachedItem < std : : map < string , Texture2D * > > ( GameConstants : : factionPreviewTextureCacheLookupKey ) ;
crcFactionPreviewTextureCache . clear ( ) ;
2010-03-13 22:10:45 +01:00
//delete resources
modelManager [ rsGlobal ] - > end ( ) ;
textureManager [ rsGlobal ] - > end ( ) ;
fontManager [ rsGlobal ] - > end ( ) ;
particleManager [ rsGlobal ] - > end ( ) ;
//delete 2d list
glDeleteLists ( list2d , 1 ) ;
2011-02-05 06:50:42 +01:00
mapSurfaceData . clear ( ) ;
2010-03-13 22:10:45 +01:00
}
2010-11-02 20:52:20 +01:00
void Renderer : : endGame ( ) {
2010-03-13 22:10:45 +01:00
game = NULL ;
//delete resources
modelManager [ rsGame ] - > end ( ) ;
textureManager [ rsGame ] - > end ( ) ;
fontManager [ rsGame ] - > end ( ) ;
particleManager [ rsGame ] - > end ( ) ;
2011-01-15 09:45:17 +01:00
if ( shadows = = sProjected | | shadows = = sShadowMapping ) {
2010-03-13 22:10:45 +01:00
glDeleteTextures ( 1 , & shadowMapHandle ) ;
}
glDeleteLists ( list3d , 1 ) ;
2010-11-02 20:52:20 +01: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 ;
2010-03-13 22:10:45 +01:00
//delete resources
modelManager [ rsMenu ] - > end ( ) ;
textureManager [ rsMenu ] - > end ( ) ;
fontManager [ rsMenu ] - > end ( ) ;
particleManager [ rsMenu ] - > end ( ) ;
glDeleteLists ( list3dMenu , 1 ) ;
}
2011-01-15 09:45:17 +01:00
void Renderer : : reloadResources ( ) {
for ( int i = 0 ; i < rsCount ; + + i ) {
2010-03-13 22:10:45 +01:00
modelManager [ i ] - > end ( ) ;
textureManager [ i ] - > end ( ) ;
fontManager [ i ] - > end ( ) ;
}
2011-01-15 09:45:17 +01:00
for ( int i = 0 ; i < rsCount ; + + i ) {
2010-03-13 22:10:45 +01:00
modelManager [ i ] - > init ( ) ;
textureManager [ i ] - > init ( ) ;
fontManager [ i ] - > init ( ) ;
}
}
// ==================== engine interface ====================
2010-04-05 21:38:50 +02:00
void Renderer : : initTexture ( ResourceScope rs , Texture * texture ) {
textureManager [ rs ] - > initTexture ( texture ) ;
}
2010-06-24 12:52:58 +02:00
void Renderer : : endTexture ( ResourceScope rs , Texture * texture , bool mustExistInList ) {
textureManager [ rs ] - > endTexture ( texture , mustExistInList ) ;
}
void Renderer : : endLastTexture ( ResourceScope rs , bool mustExistInList ) {
textureManager [ rs ] - > endLastTexture ( mustExistInList ) ;
2010-04-05 21:38:50 +02:00
}
2010-03-13 22:10:45 +01:00
Model * Renderer : : newModel ( ResourceScope rs ) {
return modelManager [ rs ] - > newModel ( ) ;
}
2010-06-24 12:52:58 +02:00
void Renderer : : endModel ( ResourceScope rs , Model * model , bool mustExistInList ) {
modelManager [ rs ] - > endModel ( model , mustExistInList ) ;
}
void Renderer : : endLastModel ( ResourceScope rs , bool mustExistInList ) {
modelManager [ rs ] - > endLastModel ( mustExistInList ) ;
}
2010-03-13 22:10:45 +01:00
Texture2D * Renderer : : newTexture2D ( ResourceScope rs ) {
return textureManager [ rs ] - > newTexture2D ( ) ;
}
Texture3D * Renderer : : newTexture3D ( ResourceScope rs ) {
return textureManager [ rs ] - > newTexture3D ( ) ;
}
Font2D * Renderer : : newFont ( ResourceScope rs ) {
return fontManager [ rs ] - > newFont2D ( ) ;
}
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
}
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 ) {
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 ( ) {
2010-06-25 07:41:50 +02:00
//glFlush(); // should not be required - http://www.opengl.org/wiki/Common_Mistakes
2010-08-26 03:25:27 +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 ( ) {
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
Vec3f lightColor = computeLightColor ( time ) ;
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)
2011-01-15 09:45:17 +01:00
if ( timeFlow - > isTotalNight ( ) ) {
2010-03-13 22:10:45 +01:00
for ( int i = 0 ; i < world - > getFactionCount ( ) & & lightCount < maxLights ; + + i ) {
for ( int j = 0 ; j < world - > getFaction ( i ) - > getUnitCount ( ) & & lightCount < maxLights ; + + j ) {
Unit * unit = world - > getFaction ( i ) - > getUnit ( j ) ;
if ( world - > toRenderUnit ( unit ) & &
unit - > getCurrVector ( ) . dist ( gameCamera - > getPos ( ) ) < maxLightDist & &
unit - > getType ( ) - > getLight ( ) & & unit - > isOperative ( ) ) {
Vec4f pos = Vec4f ( unit - > getCurrVector ( ) ) ;
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 ;
}
}
}
}
}
assertGl ( ) ;
}
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 ( ) ;
glRotatef ( gameCamera - > getVAng ( ) , - 1 , 0 , 0 ) ;
glRotatef ( gameCamera - > getHAng ( ) , 0 , 1 , 0 ) ;
glTranslatef ( - gameCamera - > getPos ( ) . x , - gameCamera - > getPos ( ) . y , - gameCamera - > getPos ( ) . z ) ;
}
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-01-15 09:45:17 +01:00
void Renderer : : computeVisibleQuad ( ) {
const GameCamera * gameCamera = game - > getGameCamera ( ) ;
visibleQuad = gameCamera - > computeVisibleQuad ( ) ;
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 ) {
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
//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 ( ) ;
2010-06-22 06:09:23 +02:00
//border
2010-03-13 22:10:45 +01:00
glLineWidth ( 2 ) ;
glBegin ( GL_LINE_LOOP ) ;
glColor4f ( 1.f , 0.2f , 0 , color1 ) ;
glVertex2i ( x , y ) ;
glColor4f ( 1.f , 0.4f , 0 , color2 ) ;
glVertex2i ( x + 20 , y - 10 ) ;
glColor4f ( 1.f , 0.4f , 0 , color2 ) ;
glVertex2i ( x + 10 , y - 20 ) ;
glEnd ( ) ;
glPopAttrib ( ) ;
}
2010-04-15 07:06:15 +02:00
void Renderer : : renderMouse3d ( ) {
if ( game = = NULL ) {
char szBuf [ 1024 ] = " " ;
sprintf ( szBuf , " In [%s::%s] Line: %d game == NULL " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
throw runtime_error ( szBuf ) ;
}
else if ( game - > getGui ( ) = = NULL ) {
char szBuf [ 1024 ] = " " ;
sprintf ( szBuf , " In [%s::%s] Line: %d game->getGui() == NULL " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
throw runtime_error ( szBuf ) ;
}
else if ( game - > getGui ( ) - > getMouse3d ( ) = = NULL ) {
char szBuf [ 1024 ] = " " ;
sprintf ( szBuf , " In [%s::%s] Line: %d game->getGui()->getMouse3d() == NULL " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
throw runtime_error ( szBuf ) ;
}
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 ) {
char szBuf [ 1024 ] = " " ;
sprintf ( szBuf , " In [%s::%s] Line: %d map == NULL " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
throw runtime_error ( szBuf ) ;
}
2010-03-13 22:10:45 +01:00
GLUquadricObj * cilQuadric ;
Vec4f color ;
assertGl ( ) ;
2011-01-15 09:45:17 +01:00
if ( ( mouse3d - > isEnabled ( ) | | gui - > isPlacingBuilding ( ) ) & & gui - > isValidPosObjWorld ( ) ) {
2010-03-13 22:10:45 +01:00
glMatrixMode ( GL_MODELVIEW ) ;
glPushMatrix ( ) ;
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 ) ;
2010-08-21 20:50:56 +02:00
const Vec2i & pos = gui - > getPosObjWorld ( ) ;
2010-04-15 07:06:15 +02:00
2010-05-01 22:14:25 +02:00
Vec3f pos3f = Vec3f ( pos . x , map - > getCell ( pos ) - > getHeight ( ) , pos . y ) ;
2010-03-13 22:10:45 +01:00
2011-01-15 09:45:17 +01:00
if ( gui - > isPlacingBuilding ( ) ) {
2010-03-13 22:10:45 +01:00
const UnitType * building = gui - > getBuilding ( ) ;
//selection building emplacement
float offset = building - > getSize ( ) / 2.f - 0.5f ;
glTranslatef ( pos3f . x + offset , pos3f . y , pos3f . z + offset ) ;
//choose color
if ( map - > isFreeCells ( pos , building - > getSize ( ) , fLand ) ) {
color = Vec4f ( 1.f , 1.f , 1.f , 0.5f ) ;
}
2011-01-15 09:45:17 +01:00
else {
2010-03-13 22:10:45 +01:00
color = Vec4f ( 1.f , 0.f , 0.f , 0.5f ) ;
}
modelRenderer - > begin ( true , true , false ) ;
glColor4fv ( color . ptr ( ) ) ;
glMaterialfv ( GL_FRONT_AND_BACK , GL_AMBIENT , color . ptr ( ) ) ;
2011-01-18 08:52:06 +01:00
Model * buildingModel = building - > getFirstStOfClass ( scStop ) - > getAnimation ( ) ;
2010-03-13 22:10:45 +01:00
2010-06-29 08:50:35 +02:00
if ( gui - > getSelectedFacing ( ) ! = CardinalDir : : NORTH ) {
float rotateAmount = gui - > getSelectedFacing ( ) * 90.f ;
if ( rotateAmount > 0 ) {
glRotatef ( rotateAmount , 0.f , 1.f , 0.f ) ;
}
2010-03-25 13:15:10 +01:00
}
2010-06-17 02:08:27 +02:00
2010-03-13 22:10:45 +01:00
buildingModel - > updateInterpolationData ( 0.f , false ) ;
modelRenderer - > render ( buildingModel ) ;
glDisable ( GL_COLOR_MATERIAL ) ;
modelRenderer - > end ( ) ;
}
2011-01-15 09:45:17 +01:00
else {
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 ) ;
}
glPopAttrib ( ) ;
glPopMatrix ( ) ;
}
}
2010-08-31 08:38:27 +02:00
void Renderer : : renderBackground ( const Texture2D * texture ) {
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 ) {
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 ( ) ;
}
2010-12-27 01:59:57 +01:00
void Renderer : : renderConsoleLine ( int lineIndex , int xPosition , int yPosition , int lineHeight ,
2011-01-15 09:45:17 +01:00
const Font2D * font , string stringToHightlight , const ConsoleLineInfo * lineInfo ) {
2010-04-11 02:45:09 +02:00
Vec4f fontColor ;
2010-12-27 01:59:57 +01:00
const Metrics & metrics = Metrics : : getInstance ( ) ;
const 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 )
fontColor = Vec4f ( 1.f , 1.f , 1.f , 0.0f ) ;
}
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 + ":";
2010-11-04 07:27:25 +01:00
string headerLine = playerName + " : " ;
if ( fontMetrics = = NULL ) {
throw runtime_error ( " fontMetrics == NULL " ) ;
}
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 ;
string headerLine = playerName + " : " ;
if ( fontMetrics = = NULL ) {
throw runtime_error ( " fontMetrics == NULL " ) ;
}
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
}
void Renderer : : renderConsole ( const Console * console , const bool showFullConsole , const bool showMenuConsole ) {
if ( console = = NULL ) {
throw runtime_error ( " console == NULL " ) ;
}
glPushAttrib ( GL_ENABLE_BIT ) ;
glEnable ( GL_BLEND ) ;
if ( showFullConsole ) {
for ( int i = 0 ; i < console - > getStoredLineCount ( ) ; + + i ) {
2010-10-23 06:00:39 +02:00
const ConsoleLineInfo & lineInfo = console - > getStoredLineItem ( i ) ;
2011-01-02 07:46:48 +01:00
renderConsoleLine ( i , console - > getXPos ( ) , console - > getYPos ( ) ,
2011-01-01 21:31:25 +01:00
console - > getLineHeight ( ) , console - > getFont ( ) , console - > getStringToHighlight ( ) , & lineInfo ) ;
2010-06-09 00:50:37 +02:00
}
}
2010-06-22 06:09:23 +02:00
else if ( showMenuConsole ) {
2010-10-22 09:28:55 +02:00
for ( int i = 0 ; i < console - > getStoredLineCount ( ) & & i < maxConsoleLines ; + + i ) {
2010-10-23 06:00:39 +02:00
const ConsoleLineInfo & lineInfo = console - > getStoredLineItem ( i ) ;
2011-01-02 07:46:48 +01:00
renderConsoleLine ( i , console - > getXPos ( ) , console - > getYPos ( ) ,
2011-01-01 21:31:25 +01:00
console - > getLineHeight ( ) , console - > getFont ( ) , console - > getStringToHighlight ( ) , & lineInfo ) ;
2010-04-14 22:49:14 +02:00
}
}
2010-06-22 06:09:23 +02:00
else {
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-01-02 07:46:48 +01:00
renderConsoleLine ( i , console - > getXPos ( ) , console - > getYPos ( ) ,
2011-01-01 21:31:25 +01:00
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 ) {
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 ( ) ) {
string text = " " ;
2010-03-13 22:10:45 +01:00
2011-01-01 21:31:25 +01:00
if ( chatManager - > getInMenu ( ) ) {
text + = lang . get ( " Chat " ) ;
}
else if ( chatManager - > getTeamMode ( ) ) {
2010-10-22 09:28:55 +02:00
text + = lang . get ( " Team " ) ;
2010-03-13 22:10:45 +01:00
}
2010-10-22 09:28:55 +02:00
else {
text + = lang . get ( " 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
2010-06-22 22:53:54 +02:00
renderTextShadow (
text ,
2010-12-27 01:59:57 +01:00
chatManager - > getFont ( ) ,
2010-06-22 22:53:54 +02:00
fontColor ,
2010-12-27 01:59:57 +01:00
chatManager - > getXPos ( ) , chatManager - > getYPos ( ) ) ;
2010-12-05 02:33:28 +01:00
2010-06-22 22:53:54 +02:00
//textRenderer->begin(CoreData::getInstance().getConsoleFont());
//textRenderer->render(text, 300, 150);
//textRenderer->end();
2010-03-13 22:10:45 +01:00
}
2011-01-01 21:31:25 +01:00
else
{
if ( chatManager - > getInMenu ( ) ) {
string text = " >> " + lang . get ( " PressEnterToChat " ) + " << " ;
fontColor = Vec4f ( 0.5f , 0.5f , 0.5f , 0.5f ) ;
renderTextShadow ( text , chatManager - > getFont ( ) , fontColor ,
chatManager - > getXPos ( ) , chatManager - > getYPos ( ) ) ;
}
}
2010-03-13 22:10:45 +01:00
}
2011-01-15 09:45:17 +01:00
void Renderer : : renderResourceStatus ( ) {
2010-03-13 22:10:45 +01:00
const Metrics & metrics = Metrics : : getInstance ( ) ;
const World * world = game - > getWorld ( ) ;
const Faction * thisFaction = world - > getFaction ( world - > getThisFactionIndex ( ) ) ;
2010-04-11 02:45:09 +02:00
const Vec4f fontColor = game - > getGui ( ) - > getDisplay ( ) - > getColor ( ) ;
2010-03-13 22:10:45 +01:00
assertGl ( ) ;
glPushAttrib ( GL_ENABLE_BIT ) ;
int j = 0 ;
for ( int i = 0 ; i < world - > getTechTree ( ) - > getResourceTypeCount ( ) ; + + i ) {
const ResourceType * rt = world - > getTechTree ( ) - > getResourceType ( i ) ;
const Resource * r = thisFaction - > getResource ( rt ) ;
//if any unit produces the resource
bool showResource = false ;
for ( int k = 0 ; k < thisFaction - > getType ( ) - > getUnitTypeCount ( ) ; + + k ) {
const UnitType * ut = thisFaction - > getType ( ) - > getUnitType ( k ) ;
if ( ut - > getCost ( rt ) ! = NULL ) {
showResource = true ;
break ;
}
}
//draw resource status
if ( showResource ) {
string str = intToStr ( r - > getAmount ( ) ) ;
glEnable ( GL_TEXTURE_2D ) ;
2010-03-25 05:47:04 +01:00
glColor3f ( 1.f , 1.f , 1.f ) ;
2010-03-13 22:10:45 +01:00
renderQuad ( j * 100 + 200 , metrics . getVirtualH ( ) - 30 , 16 , 16 , rt - > getImage ( ) ) ;
if ( rt - > getClass ( ) ! = rcStatic )
{
str + = " / " + intToStr ( thisFaction - > getStoreAmount ( rt ) ) ;
}
if ( rt - > getClass ( ) = = rcConsumable ) {
str + = " ( " ;
if ( r - > getBalance ( ) > 0 ) {
str + = " + " ;
}
str + = intToStr ( r - > getBalance ( ) ) + " ) " ;
}
glDisable ( GL_TEXTURE_2D ) ;
renderTextShadow (
2010-04-08 00:20:28 +02:00
str , CoreData : : getInstance ( ) . getDisplayFontSmall ( ) ,
2010-04-11 02:45:09 +02:00
fontColor ,
2010-03-13 22:10:45 +01:00
j * 100 + 220 , metrics . getVirtualH ( ) - 30 , false ) ;
+ + j ;
}
}
glPopAttrib ( ) ;
assertGl ( ) ;
}
2011-01-15 09:45:17 +01:00
void Renderer : : renderSelectionQuad ( ) {
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 ) ;
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 ( ) ;
glPopAttrib ( ) ;
}
}
2011-01-15 09:45:17 +01:00
Vec2i computeCenteredPos ( const string & text , const Font2D * font , int x , int y ) {
2010-08-05 02:09:45 +02:00
if ( font = = NULL ) {
throw runtime_error ( " font == NULL " ) ;
}
2010-03-13 22:10:45 +01:00
const Metrics & metrics = Metrics : : getInstance ( ) ;
const FontMetrics * fontMetrics = font - > getMetrics ( ) ;
2010-08-05 02:09:45 +02:00
if ( fontMetrics = = NULL ) {
throw runtime_error ( " fontMetrics == NULL " ) ;
}
int virtualX = ( fontMetrics - > getTextWidth ( text ) > 0 ? static_cast < int > ( fontMetrics - > getTextWidth ( text ) / 2.f ) : 5 ) ;
int virtualY = ( fontMetrics - > getHeight ( ) > 0 ? static_cast < int > ( fontMetrics - > getHeight ( ) / 2.f ) : 5 ) ;
Vec2i textPos (
x - metrics . toVirtualX ( virtualX ) ,
y - metrics . toVirtualY ( virtualY ) ) ;
2010-03-13 22:10:45 +01:00
return textPos ;
}
void Renderer : : renderText ( const string & text , const Font2D * font , float alpha , int x , int y , bool centered ) {
glPushAttrib ( GL_ENABLE_BIT | GL_CURRENT_BIT ) ;
glEnable ( GL_BLEND ) ;
glColor4fv ( Vec4f ( 1.f , 1.f , 1.f , alpha ) . ptr ( ) ) ;
Vec2i pos = centered ? computeCenteredPos ( text , font , x , y ) : Vec2i ( x , y ) ;
textRenderer - > begin ( font ) ;
textRenderer - > render ( text , pos . x , pos . y ) ;
textRenderer - > end ( ) ;
glPopAttrib ( ) ;
}
void Renderer : : renderText ( const string & text , const Font2D * font , const Vec3f & color , int x , int y , bool centered ) {
glPushAttrib ( GL_CURRENT_BIT ) ;
glColor3fv ( color . ptr ( ) ) ;
Vec2i pos = centered ? computeCenteredPos ( text , font , x , y ) : Vec2i ( x , y ) ;
textRenderer - > begin ( font ) ;
textRenderer - > render ( text , pos . x , pos . y ) ;
textRenderer - > end ( ) ;
glPopAttrib ( ) ;
}
2010-08-12 00:31:26 +02:00
void Renderer : : renderText ( const string & text , const Font2D * font , const Vec4f & color , int x , int y , bool centered ) {
glPushAttrib ( GL_ENABLE_BIT | GL_CURRENT_BIT ) ;
glEnable ( GL_BLEND ) ;
glColor4fv ( color . ptr ( ) ) ;
Vec2i pos = centered ? computeCenteredPos ( text , font , x , y ) : Vec2i ( x , y ) ;
textRenderer - > begin ( font ) ;
textRenderer - > render ( text , pos . x , pos . y ) ;
textRenderer - > end ( ) ;
glPopAttrib ( ) ;
}
2010-04-08 22:19:25 +02:00
void Renderer : : renderTextShadow ( const string & text , const Font2D * font , const Vec4f & color , int x , int y , bool centered ) {
2010-04-15 07:06:15 +02:00
if ( font = = NULL ) {
throw runtime_error ( " font == NULL " ) ;
}
2010-03-13 22:10:45 +01:00
glPushAttrib ( GL_CURRENT_BIT ) ;
Vec2i pos = centered ? computeCenteredPos ( text , font , x , y ) : Vec2i ( x , y ) ;
2010-06-22 22:53:54 +02:00
textRenderer - > begin ( font ) ;
2010-06-22 06:09:23 +02:00
if ( color . w < 0.5 ) {
2010-04-08 22:19:25 +02:00
glColor3f ( 0.0f , 0.0f , 0.0f ) ;
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 ) ;
2010-03-13 22:10:45 +01:00
textRenderer - > render ( text , pos . x , pos . y ) ;
textRenderer - > end ( ) ;
glPopAttrib ( ) ;
}
// ============= COMPONENTS =============================
2010-09-11 08:08:50 +02:00
void Renderer : : renderLabel ( const GraphicLabel * label ) {
2010-10-22 09:28:55 +02:00
Vec4f * colorWithAlpha = NULL ;
renderLabel ( label , colorWithAlpha ) ;
}
void Renderer : : renderLabel ( const GraphicLabel * label , const Vec3f * color ) {
if ( color ! = NULL ) {
Vec4f colorWithAlpha = Vec4f ( * color ) ;
colorWithAlpha . w = GraphicComponent : : getFade ( ) ;
renderLabel ( label , & colorWithAlpha ) ;
}
else {
Vec4f * colorWithAlpha = NULL ;
renderLabel ( label , colorWithAlpha ) ;
}
}
void Renderer : : renderLabel ( const GraphicLabel * label , const Vec4f * color ) {
2010-09-11 08:08:50 +02:00
if ( label - > getVisible ( ) = = false ) {
return ;
}
2010-03-13 22:10:45 +01:00
glPushAttrib ( GL_ENABLE_BIT ) ;
glEnable ( GL_BLEND ) ;
Vec2i textPos ;
int x = label - > getX ( ) ;
int y = label - > getY ( ) ;
int h = label - > getH ( ) ;
int w = label - > getW ( ) ;
if ( label - > getCentered ( ) ) {
textPos = Vec2i ( x + w / 2 , y + h / 2 ) ;
}
else {
textPos = Vec2i ( x , y + h / 4 ) ;
}
2010-10-22 09:28:55 +02:00
if ( color ! = NULL ) {
renderText ( label - > getText ( ) , label - > getFont ( ) , ( * color ) , textPos . x , textPos . y , label - > getCentered ( ) ) ;
}
else {
renderText ( label - > getText ( ) , label - > getFont ( ) , GraphicComponent : : getFade ( ) , textPos . x , textPos . y , label - > getCentered ( ) ) ;
}
2010-03-13 22:10:45 +01:00
glPopAttrib ( ) ;
}
2010-09-11 08:08:50 +02:00
void Renderer : : renderButton ( const GraphicButton * button ) {
if ( button - > getVisible ( ) = = false ) {
return ;
}
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 ( ) ;
Texture2D * backTexture = w > 3 * h / 2 ? coreData . getButtonBigTexture ( ) : coreData . getButtonSmallTexture ( ) ;
glEnable ( GL_TEXTURE_2D ) ;
glEnable ( GL_BLEND ) ;
glBindTexture ( GL_TEXTURE_2D , static_cast < Texture2DGl * > ( backTexture ) - > getHandle ( ) ) ;
//button
2010-08-12 00:31:26 +02:00
Vec4f fontColor ;
2010-08-12 01:07:18 +02:00
//if(game!=NULL){
// fontColor=game->getGui()->getDisplay()->getColor();
// fontColor.w = GraphicComponent::getFade();
//}
//else {
2010-08-12 00:31:26 +02:00
// white shadowed is default ( in the menu for example )
fontColor = Vec4f ( 1.f , 1.f , 1.f , GraphicComponent : : getFade ( ) ) ;
2010-08-12 01:07:18 +02: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 ;
2010-04-22 01:13:39 +02:00
if ( button - > getLighted ( ) & & button - > getEditable ( ) ) {
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 ( ) ;
}
Vec2i textPos = Vec2i ( x + w / 2 , y + h / 2 ) ;
2010-04-22 01:13:39 +02:00
if ( button - > getEditable ( ) ) {
2010-08-12 00:31:26 +02:00
2010-04-22 01:13:39 +02:00
renderText (
2010-08-12 00:31:26 +02:00
button - > getText ( ) , button - > getFont ( ) , color ,
2010-04-22 01:13:39 +02:00
x + w / 2 , y + h / 2 , true ) ;
}
else {
renderText (
button - > getText ( ) , button - > getFont ( ) , disabledTextColor ,
x + w / 2 , y + h / 2 , true ) ;
}
2010-03-13 22:10:45 +01:00
glPopAttrib ( ) ;
}
2010-12-27 01:59:57 +01:00
void Renderer : : renderCheckBox ( const GraphicCheckBox * box ) {
if ( box - > getVisible ( ) = = false ) {
return ;
}
int x = box - > getX ( ) ;
int y = box - > getY ( ) ;
int h = box - > getH ( ) ;
int w = box - > getW ( ) ;
const Vec3f disabledTextColor = Vec3f ( 0.25f , 0.25f , 0.25f ) ;
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 ( ) ;
if ( anim > 0.5f ) anim = 1.f - anim ;
if ( box - > getLighted ( ) & & box - > 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 ( ) ;
}
void Renderer : : renderLine ( const GraphicLine * line ) {
if ( line - > getVisible ( ) = = false ) {
return ;
}
int x = line - > getX ( ) ;
int y = line - > getY ( ) ;
int h = line - > getH ( ) ;
int w = line - > getW ( ) ;
const Vec3f disabledTextColor = Vec3f ( 0.25f , 0.25f , 0.25f ) ;
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 ) {
if ( sb - > getVisible ( ) = = false ) {
return ;
}
int x = sb - > getX ( ) ;
int y = sb - > getY ( ) ;
int h = sb - > getH ( ) ;
int w = sb - > getW ( ) ;
const Vec3f disabledTextColor = Vec3f ( 0.25f , 0.25f , 0.25f ) ;
glPushAttrib ( GL_CURRENT_BIT | GL_ENABLE_BIT ) ;
/////////////////////
//background
////////////////////
CoreData & coreData = CoreData : : getInstance ( ) ;
Texture2D * backTexture = coreData . getHorizontalLineTexture ( ) ;
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 ( ) ;
////////////////////
// selectBlock
////////////////////
x = sb - > getX ( ) ;
y = sb - > getY ( ) ;
h = sb - > getH ( ) ;
w = sb - > getW ( ) ;
if ( sb - > getHorizontal ( ) ) {
x = x + sb - > getVisibleCompPosStart ( ) ;
w = sb - > getVisibleCompPosEnd ( ) - sb - > getVisibleCompPosStart ( ) ;
}
else {
y = y + sb - > getVisibleCompPosStart ( ) ;
h = sb - > getVisibleCompPosEnd ( ) - sb - > getVisibleCompPosStart ( ) ;
}
Texture2D * selectTexture = coreData . getButtonBigTexture ( ) ;
glBindTexture ( GL_TEXTURE_2D , static_cast < Texture2DGl * > ( selectTexture ) - > getHandle ( ) ) ;
//button
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 ( ) ;
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 ( ) ;
}
2010-09-11 08:08:50 +02:00
void Renderer : : renderListBox ( const GraphicListBox * listBox ) {
if ( listBox - > getVisible ( ) = = false ) {
return ;
}
2010-03-13 22:10:45 +01:00
renderButton ( listBox - > getButton1 ( ) ) ;
renderButton ( listBox - > getButton2 ( ) ) ;
glPushAttrib ( GL_ENABLE_BIT ) ;
glEnable ( GL_BLEND ) ;
GraphicLabel label ;
label . init ( listBox - > getX ( ) , listBox - > getY ( ) , listBox - > getW ( ) , listBox - > getH ( ) , true ) ;
label . setText ( listBox - > getText ( ) ) ;
label . setFont ( listBox - > getFont ( ) ) ;
renderLabel ( & label ) ;
glPopAttrib ( ) ;
}
2010-09-11 08:08:50 +02:00
void Renderer : : renderMessageBox ( const GraphicMessageBox * messageBox ) {
if ( messageBox - > getVisible ( ) = = false ) {
return ;
}
2010-03-13 22:10:45 +01:00
//background
glPushAttrib ( GL_ENABLE_BIT | GL_CURRENT_BIT ) ;
glEnable ( GL_BLEND ) ;
glColor4f ( 0.0f , 0.0f , 0.0f , 0.5f ) ;
glBegin ( GL_TRIANGLE_STRIP ) ;
glVertex2i ( messageBox - > getX ( ) , messageBox - > getY ( ) + 9 * messageBox - > getH ( ) / 10 ) ;
glVertex2i ( messageBox - > getX ( ) , messageBox - > getY ( ) ) ;
glVertex2i ( messageBox - > getX ( ) + messageBox - > getW ( ) , messageBox - > getY ( ) + 9 * messageBox - > getH ( ) / 10 ) ;
glVertex2i ( messageBox - > getX ( ) + messageBox - > getW ( ) , messageBox - > getY ( ) ) ;
glEnd ( ) ;
glColor4f ( 0.0f , 0.0f , 0.0f , 0.8f ) ;
glBegin ( GL_TRIANGLE_STRIP ) ;
glVertex2i ( messageBox - > getX ( ) , messageBox - > getY ( ) + messageBox - > getH ( ) ) ;
glVertex2i ( messageBox - > getX ( ) , messageBox - > getY ( ) + 9 * messageBox - > getH ( ) / 10 ) ;
glVertex2i ( messageBox - > getX ( ) + messageBox - > getW ( ) , messageBox - > getY ( ) + messageBox - > getH ( ) ) ;
glVertex2i ( messageBox - > getX ( ) + messageBox - > getW ( ) , messageBox - > getY ( ) + 9 * messageBox - > getH ( ) / 10 ) ;
glEnd ( ) ;
glBegin ( GL_LINE_LOOP ) ;
glColor4f ( 0.5f , 0.5f , 0.5f , 0.25f ) ;
glVertex2i ( messageBox - > getX ( ) , messageBox - > getY ( ) ) ;
glColor4f ( 0.0f , 0.0f , 0.0f , 0.25f ) ;
glVertex2i ( messageBox - > getX ( ) + messageBox - > getW ( ) , messageBox - > getY ( ) ) ;
glColor4f ( 0.5f , 0.5f , 0.5f , 0.25f ) ;
glVertex2i ( messageBox - > getX ( ) + messageBox - > getW ( ) , messageBox - > getY ( ) + messageBox - > getH ( ) ) ;
glColor4f ( 0.25f , 0.25f , 0.25f , 0.25f ) ;
glVertex2i ( messageBox - > getX ( ) , messageBox - > getY ( ) + messageBox - > getH ( ) ) ;
glEnd ( ) ;
glBegin ( GL_LINE_STRIP ) ;
glColor4f ( 1.0f , 1.0f , 1.0f , 0.25f ) ;
glVertex2i ( messageBox - > getX ( ) , messageBox - > getY ( ) + 90 * messageBox - > getH ( ) / 100 ) ;
glColor4f ( 0.5f , 0.5f , 0.5f , 0.25f ) ;
glVertex2i ( messageBox - > getX ( ) + messageBox - > getW ( ) , messageBox - > getY ( ) + 90 * messageBox - > getH ( ) / 100 ) ;
glEnd ( ) ;
glPopAttrib ( ) ;
2011-01-09 10:05:34 +01:00
2010-03-13 22:10:45 +01:00
//buttons
renderButton ( messageBox - > getButton1 ( ) ) ;
if ( messageBox - > getButtonCount ( ) = = 2 ) {
renderButton ( messageBox - > getButton2 ( ) ) ;
}
2010-08-12 00:31:26 +02:00
Vec4f fontColor ;
2010-08-12 01:07:18 +02:00
//if(game!=NULL){
// fontColor=game->getGui()->getDisplay()->getColor();
//}
//else {
2010-08-12 00:31:26 +02:00
// white shadowed is default ( in the menu for example )
fontColor = Vec4f ( 1.f , 1.f , 1.f , 1.0f ) ;
2010-08-12 01:07:18 +02:00
//}
2010-08-12 00:31:26 +02:00
2010-03-13 22:10:45 +01:00
//text
2010-08-12 00:31:26 +02:00
renderTextShadow (
messageBox - > getText ( ) , messageBox - > getFont ( ) , fontColor ,
2010-03-13 22:10:45 +01:00
messageBox - > getX ( ) + 15 , messageBox - > getY ( ) + 7 * messageBox - > getH ( ) / 10 ,
false ) ;
2010-08-12 00:31:26 +02:00
renderTextShadow (
messageBox - > getHeader ( ) , messageBox - > getFont ( ) , fontColor ,
2010-03-13 22:10:45 +01:00
messageBox - > getX ( ) + 15 , messageBox - > getY ( ) + 93 * messageBox - > getH ( ) / 100 ,
false ) ;
}
// ==================== complex rendering ====================
2011-02-05 06:07:05 +01:00
VisibleQuadContainerVBOCache * Renderer : : GetSurfaceVBOs ( SurfaceData * cellData ) {
std : : map < uint32 , VisibleQuadContainerVBOCache > : : iterator iterFind = mapSurfaceVBOCache . find ( cellData - > uniqueId ) ;
2011-01-21 23:41:05 +01:00
if ( iterFind = = mapSurfaceVBOCache . end ( ) ) {
2011-02-05 06:07:05 +01:00
Vec2f * texCoords = & cellData - > texCoords [ 0 ] ;
Vec2f * texCoordsSurface = & cellData - > texCoordsSurface [ 0 ] ;
Vec3f * vertices = & cellData - > vertices [ 0 ] ;
Vec3f * normals = & cellData - > normals [ 0 ] ;
2011-01-21 23:41:05 +01:00
2011-02-05 06:07:05 +01:00
VisibleQuadContainerVBOCache vboCache ;
2011-01-21 23:41:05 +01:00
2011-02-05 06:07:05 +01:00
// Generate And Bind The Vertex Buffer
glGenBuffersARB ( 1 , & 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 ) ;
glBindBuffer ( GL_ARRAY_BUFFER_ARB , 0 ) ;
2011-01-21 23:41:05 +01:00
assertGl ( ) ;
2011-02-05 06:07:05 +01:00
// Generate And Bind The Texture Coordinate Buffer
glGenBuffersARB ( 1 , & 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 ) ;
glBindBuffer ( GL_ARRAY_BUFFER_ARB , 0 ) ;
2011-01-21 23:41:05 +01:00
assertGl ( ) ;
2011-02-05 06:07:05 +01:00
// Generate And Bind The Texture Coordinate Buffer
glGenBuffersARB ( 1 , & 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 ) ;
glBindBuffer ( GL_ARRAY_BUFFER_ARB , 0 ) ;
2011-01-21 23:41:05 +01:00
assertGl ( ) ;
2011-02-05 06:07:05 +01:00
// Generate And Bind The Normal Buffer
glGenBuffersARB ( 1 , & 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 ) ;
glBindBuffer ( GL_ARRAY_BUFFER_ARB , 0 ) ;
2011-01-21 23:41:05 +01:00
2011-02-05 06:07:05 +01:00
vboCache . hasBuiltVBOs = true ;
mapSurfaceVBOCache [ cellData - > uniqueId ] = vboCache ;
2011-01-21 23:41:05 +01:00
2011-02-05 06:07:05 +01:00
// 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 ( ) ;
2011-01-21 23:41:05 +01:00
}
2011-02-05 06:07:05 +01:00
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 ) {
glDeleteBuffersARB ( 1 , & item . m_nVBOVertices ) ; // Get A Valid Name
glDeleteBuffersARB ( 1 , & item . m_nVBOFowTexCoords ) ; // Get A Valid Name
glDeleteBuffersARB ( 1 , & item . m_nVBOSurfaceTexCoords ) ; // Get A Valid Name
glDeleteBuffersARB ( 1 , & item . m_nVBONormals ) ; // Get A Valid Name
//glDeleteBuffersARB( 1, &item.m_nVBOIndexes ); // Get A Valid Name
2011-01-21 23:41:05 +01:00
}
}
mapSurfaceVBOCache . clear ( ) ;
}
2010-10-04 20:31:17 +02:00
void Renderer : : renderSurface ( const int renderFps ) {
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
)
2010-03-13 22:10:45 +01:00
int lastTex = - 1 ;
2011-01-21 23:41:05 +01:00
int currTex = - 1 ;
2010-03-13 22:10:45 +01:00
const World * world = game - > getWorld ( ) ;
const Map * map = world - > getMap ( ) ;
const Rect2i mapBounds ( 0 , 0 , map - > getSurfaceW ( ) - 1 , map - > getSurfaceH ( ) - 1 ) ;
float coordStep = world - > getTileset ( ) - > getSurfaceAtlas ( ) - > getCoordStep ( ) ;
assertGl ( ) ;
const Texture2D * fowTex = world - > getMinimap ( ) - > getFowTexture ( ) ;
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
}
glActiveTexture ( baseTexUnit ) ;
2011-01-15 09:45:17 +01:00
VisibleQuadContainerCache & qCache = getQuadCache ( ) ;
if ( qCache . visibleScaledCellList . size ( ) > 0 ) {
2010-09-10 02:28:14 +02:00
2011-02-05 06:07:05 +01:00
Quad2i snapshotOfvisibleQuad = visibleQuad ;
2011-01-25 08:41:12 +01:00
2011-02-06 01:46:40 +01:00
//bool useVertexArrayRendering = getVBOSupported();
bool useVertexArrayRendering = false ;
2011-02-05 00:27:55 +01:00
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-01-20 16:56:30 +01:00
for ( int visibleIndex = 0 ;
visibleIndex < qCache . visibleScaledCellList . size ( ) ; + + visibleIndex ) {
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 ) {
throw runtime_error ( " tc00 == NULL " ) ;
}
if ( tc10 = = NULL ) {
throw runtime_error ( " tc10 == NULL " ) ;
}
if ( tc01 = = NULL ) {
throw runtime_error ( " tc01 == NULL " ) ;
}
if ( tc11 = = NULL ) {
throw runtime_error ( " tc11 == NULL " ) ;
}
triangleCount + = 2 ;
pointCount + = 4 ;
//set texture
if ( tc00 - > getSurfaceTexture ( ) = = NULL ) {
throw runtime_error ( " tc00->getSurfaceTexture() = = NULL " ) ;
}
currTex = static_cast < const Texture2DGl * > ( tc00 - > getSurfaceTexture ( ) ) - > getHandle ( ) ;
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 ) ;
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 ) ;
2011-01-20 16:56:30 +01:00
}
else {
2011-01-21 23:41:05 +01:00
int lastSurfaceDataIndex = - 1 ;
2011-02-05 00:27:55 +01:00
2011-02-05 06:07:05 +01:00
const bool useVBOs = false ;
2011-02-06 01:46:40 +01:00
const bool useSurfaceCache = false ;
2011-02-05 06:07:05 +01:00
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 ( ) ) ;
2011-02-05 00:27:55 +01:00
for ( int visibleIndex = 0 ;
visibleIndex < 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 runtime_error ( " tc00 == NULL " ) ;
}
if ( tc10 = = NULL ) {
throw runtime_error ( " tc10 == NULL " ) ;
}
if ( tc01 = = NULL ) {
throw runtime_error ( " tc01 == NULL " ) ;
}
if ( tc11 = = NULL ) {
throw runtime_error ( " tc11 == NULL " ) ;
}
2011-01-20 16:56:30 +01:00
2011-02-05 00:27:55 +01:00
triangleCount + = 2 ;
pointCount + = 4 ;
2011-01-20 16:56:30 +01:00
2011-02-05 00:27:55 +01:00
//set texture
if ( tc00 - > getSurfaceTexture ( ) = = NULL ) {
throw runtime_error ( " tc00->getSurfaceTexture() = = NULL " ) ;
}
2011-01-20 16:56:30 +01:00
2011-02-05 00:27:55 +01:00
int surfaceDataIndex = - 1 ;
currTex = static_cast < const Texture2DGl * > ( tc00 - > getSurfaceTexture ( ) ) - > getHandle ( ) ;
if ( currTex ! = lastTex ) {
lastTex = currTex ;
}
else {
surfaceDataIndex = lastSurfaceDataIndex ;
}
2010-03-13 22:10:45 +01:00
2011-02-05 00:27:55 +01:00
if ( surfaceDataIndex < 0 ) {
SurfaceData newData ;
2011-02-05 06:07:05 +01:00
newData . uniqueId = SurfaceData : : nextUniqueId ;
SurfaceData : : nextUniqueId + + ;
newData . bufferCount = 0 ;
2011-02-05 00:27:55 +01:00
newData . textureHandle = currTex ;
2011-02-05 06:07:05 +01:00
surface - > push_back ( newData ) ;
2011-01-21 23:41:05 +01:00
2011-02-05 06:07:05 +01:00
surfaceDataIndex = surface - > size ( ) - 1 ;
2011-02-05 00:27:55 +01:00
}
2010-03-13 22:10:45 +01:00
2011-02-05 00:27:55 +01:00
lastSurfaceDataIndex = surfaceDataIndex ;
2011-01-21 23:41:05 +01:00
2011-02-05 06:07:05 +01:00
SurfaceData * cellData = & ( * surface ) [ surfaceDataIndex ] ;
2011-02-05 00:27:55 +01:00
const Vec2f & surfCoord = tc00 - > getSurfTexCoord ( ) ;
2010-03-13 22:10:45 +01:00
2011-02-05 06:07:05 +01:00
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 + + ;
}
/*
if ( useSurfaceCache = = true ) {
std : : pair < Chrono , std : : vector < SurfaceData > > & surfaceCacheEntity = mapSurfaceData [ snapshotOfvisibleQuad . getString ( ) ] ;
surfaceCacheEntity . first . start ( ) ;
2011-02-05 00:27:55 +01:00
}
2011-02-05 06:07:05 +01:00
*/
2011-01-20 16:56:30 +01:00
}
2011-02-05 06:07:05 +01:00
//printf("\nsurface.size() = %d vs qCache.visibleScaledCellList.size() = %d snapshotOfvisibleQuad [%s]\n",surface.size(),qCache.visibleScaledCellList.size(),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 ;
2011-01-21 23:41:05 +01:00
2011-02-05 06:07:05 +01:00
//printf("Surface Cache Size for Rendering using VA's = %lu\n",mapSurfaceData.size());
}
2011-02-05 00:27:55 +01:00
glEnableClientState ( GL_VERTEX_ARRAY ) ;
glEnableClientState ( GL_NORMAL_ARRAY ) ;
2011-02-05 06:07:05 +01:00
for ( int i = 0 ; i < surface - > size ( ) ; + + i ) {
SurfaceData & data = ( * surface ) [ i ] ;
if ( useVBOs = = true ) {
VisibleQuadContainerVBOCache * vboCache = GetSurfaceVBOs ( & data ) ;
2011-01-20 16:56:30 +01:00
2011-02-05 06:07:05 +01:00
//glBindTexture(GL_TEXTURE_2D, static_cast<const Texture2DGl*>(fowTex)->getHandle());
glClientActiveTexture ( fowTexUnit ) ;
glEnableClientState ( GL_TEXTURE_COORD_ARRAY ) ;
2011-01-20 16:56:30 +01:00
2011-02-05 06:07:05 +01:00
glBindBufferARB ( GL_ARRAY_BUFFER_ARB , vboCache - > m_nVBOFowTexCoords ) ;
glTexCoordPointer ( 2 , GL_FLOAT , 0 , ( char * ) NULL ) ;
2011-01-20 16:56:30 +01:00
2011-02-05 06:07:05 +01:00
glBindTexture ( GL_TEXTURE_2D , data . textureHandle ) ;
glClientActiveTexture ( baseTexUnit ) ;
glEnableClientState ( GL_TEXTURE_COORD_ARRAY ) ;
2011-01-20 16:56:30 +01:00
2011-02-05 06:07:05 +01:00
glBindBufferARB ( GL_ARRAY_BUFFER_ARB , vboCache - > m_nVBOSurfaceTexCoords ) ;
glTexCoordPointer ( 2 , GL_FLOAT , 0 , ( char * ) NULL ) ;
2011-01-20 16:56:30 +01:00
2011-02-05 06:07:05 +01:00
glBindBufferARB ( GL_ARRAY_BUFFER_ARB , vboCache - > m_nVBOVertices ) ;
glVertexPointer ( 3 , GL_FLOAT , 0 , ( char * ) NULL ) ;
2011-01-20 16:56:30 +01:00
2011-02-05 06:07:05 +01:00
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 ) ;
}
2011-01-20 16:56:30 +01:00
}
2011-02-05 00:27:55 +01:00
glDisableClientState ( GL_NORMAL_ARRAY ) ;
glDisableClientState ( GL_VERTEX_ARRAY ) ;
2011-02-05 06:07:05 +01:00
//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 ) ;
glPopAttrib ( ) ;
//assert
glGetError ( ) ; //remove when first mtex problem solved
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 ) {
2010-06-22 06:09:23 +02:00
const World * world = game - > getWorld ( ) ;
const Map * map = world - > getMap ( ) ;
2010-07-07 20:50:55 +02:00
assertGl ( ) ;
2010-03-13 22:10:45 +01:00
2010-08-21 21:15:39 +02:00
const Texture2D * fowTex = NULL ;
Vec3f baseFogColor ;
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 ( ) ;
for ( int visibleIndex = 0 ;
visibleIndex < qCache . visibleObjectList . size ( ) ; + + visibleIndex ) {
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 ( ) ;
2011-01-15 09:45:17 +01: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
fowTex = world - > getMinimap ( ) - > getFowTexture ( ) ;
baseFogColor = world - > getTileset ( ) - > getFogColor ( ) * computeLightColor ( world - > getTimeFlow ( ) - > getTime ( ) ) ;
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-01-15 09:45:17 +01:00
if ( ! shadowsOffDueToMinRender & &
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
2011-01-15 09:45:17 +01:00
modelRenderer - > begin ( true , true , 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
const Pixmap2D * fowTexPixmap = fowTex - > getPixmapConst ( ) ;
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
2011-01-15 09:45:17 +01:00
objModel - > updateInterpolationData ( 0.f , true ) ;
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 ( ) {
2010-03-13 22:10:45 +01:00
bool closed = false ;
const World * world = game - > getWorld ( ) ;
const Map * map = world - > getMap ( ) ;
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 ) ;
if ( textures3D ) {
Texture3D * waterTex = world - > getTileset ( ) - > getWaterTex ( ) ;
2010-09-10 10:51:32 +02:00
if ( waterTex = = NULL ) {
throw runtime_error ( " waterTex == NULL " ) ;
}
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
const Texture2D * fowTex = world - > getMinimap ( ) - > getFowTexture ( ) ;
glActiveTexture ( fowTexUnit ) ;
glEnable ( GL_TEXTURE_2D ) ;
glBindTexture ( GL_TEXTURE_2D , static_cast < const Texture2DGl * > ( fowTex ) - > getHandle ( ) ) ;
glActiveTexture ( baseTexUnit ) ;
assertGl ( ) ;
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 ) ;
int thisTeamIndex = world - > getThisTeamIndex ( ) ;
2010-12-25 09:14:35 +01:00
bool cellExplored = world - > showWorldForPlayer ( world - > getThisFactionIndex ( ) ) ;
if ( cellExplored = = false ) {
cellExplored = ( tc0 - > isExplored ( thisTeamIndex ) | | tc1 - > isExplored ( thisTeamIndex ) ) ;
}
if ( tc0 - > getNearSubmerged ( ) & & cellExplored = = true ) {
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 {
if ( ! closed ) {
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 ( ) ;
}
2010-10-04 20:31:17 +02:00
void Renderer : : renderUnits ( const int renderFps ) {
2010-08-21 21:15:39 +02:00
Unit * unit = NULL ;
2010-03-13 22:10:45 +01:00
const World * world = game - > getWorld ( ) ;
MeshCallbackTeamColor meshCallbackTeamColor ;
//assert
assertGl ( ) ;
2010-09-01 01:14:15 +02:00
visibleFrameUnitList . clear ( ) ;
2010-09-10 02:28:14 +02:00
bool modelRenderStarted = false ;
2011-01-15 09:45:17 +01:00
VisibleQuadContainerCache & qCache = getQuadCache ( ) ;
if ( qCache . visibleQuadUnitList . size ( ) > 0 ) {
for ( int visibleUnitIndex = 0 ;
visibleUnitIndex < qCache . visibleQuadUnitList . size ( ) ; + + visibleUnitIndex ) {
Unit * unit = qCache . visibleQuadUnitList [ visibleUnitIndex ] ;
2010-03-13 22:10:45 +01:00
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
2011-01-15 09:45:17 +01:00
modelRenderer - > begin ( true , true , true , & meshCallbackTeamColor ) ;
}
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
Vec3f currVec = unit - > getCurrVectorFlat ( ) ;
glTranslatef ( currVec . x , currVec . y , currVec . z ) ;
//rotate
glRotatef ( unit - > getRotation ( ) , 0.f , 1.f , 0.f ) ;
glRotatef ( unit - > getVerticalRotation ( ) , 1.f , 0.f , 0.f ) ;
//dead alpha
float alpha = 1.0f ;
const SkillType * st = unit - > getCurrSkill ( ) ;
if ( st - > getClass ( ) = = scDie & & static_cast < const DieSkillType * > ( st ) - > getFade ( ) ) {
alpha = 1.0f - unit - > getAnimProgress ( ) ;
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 {
glEnable ( GL_COLOR_MATERIAL ) ;
glAlphaFunc ( GL_GREATER , 0.4f ) ;
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 ( ) ;
2011-01-15 09:45:17 +01:00
model - > updateInterpolationData ( unit - > getAnimProgress ( ) , unit - > isAlive ( ) ) ;
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 ) ;
unit - > setScreenPos ( computeScreenPosition ( unit - > getCurrVectorFlat ( ) ) ) ;
visibleFrameUnitList . push_back ( unit ) ;
2010-05-10 19:50:57 +02:00
2011-01-15 09:45:17 +01:00
//if(allowRenderUnitTitles == true) {
// Add to the pending render unit title list
//renderUnitTitleList.push_back(std::pair<Unit *,Vec3f>(unit,computeScreenPosition(unit->getCurrVectorFlat())) );
//}
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 ( ) ;
2010-05-10 19:50:57 +02:00
}
2011-01-15 09:45:17 +01:00
void Renderer : : renderSelectionEffects ( ) {
2010-03-13 22:10:45 +01:00
const World * world = game - > getWorld ( ) ;
const Map * map = world - > getMap ( ) ;
const Selection * selection = game - > getGui ( ) - > getSelection ( ) ;
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 ) ;
//translate
Vec3f currVec = unit - > getCurrVectorFlat ( ) ;
currVec . y + = 0.3f ;
//selection circle
2010-09-01 01:14:15 +02:00
if ( world - > getThisFactionIndex ( ) = = unit - > getFactionIndex ( ) ) {
2011-02-06 08:01:54 +01:00
if ( showDebugUI = = true & &
( ( showDebugUILevel & debugui_unit_titles ) = = debugui_unit_titles ) & &
unit - > getCommandSize ( ) > 0 & &
2010-09-01 01:14:15 +02:00
dynamic_cast < const BuildCommandType * > ( unit - > getCurrCommand ( ) - > getCommandType ( ) ) ! = NULL ) {
glColor4f ( unit - > getHpRatio ( ) , unit - > getHpRatio ( ) , unit - > getHpRatio ( ) , 0.3f ) ;
}
else {
glColor4f ( 0 , unit - > getHpRatio ( ) , 0 , 0.3f ) ;
}
2010-03-13 22:10:45 +01:00
}
2010-09-10 10:51:32 +02:00
else if ( world - > getThisTeamIndex ( ) = = unit - > getTeam ( ) ) {
2010-08-22 23:09:35 +02:00
glColor4f ( unit - > getHpRatio ( ) , unit - > getHpRatio ( ) , 0 , 0.3f ) ;
}
2010-03-13 22:10:45 +01:00
else {
glColor4f ( unit - > getHpRatio ( ) , 0 , 0 , 0.3f ) ;
}
renderSelectionCircle ( currVec , unit - > getType ( ) - > getSize ( ) , selectionCircleRadius ) ;
//magic circle
2010-09-10 10:51:32 +02:00
if ( world - > getThisFactionIndex ( ) = = unit - > getFactionIndex ( ) & & unit - > getType ( ) - > getMaxEp ( ) > 0 ) {
2010-03-13 22:10:45 +01:00
glColor4f ( unit - > getEpRatio ( ) / 2.f , unit - > getEpRatio ( ) , unit - > getEpRatio ( ) , 0.5f ) ;
renderSelectionCircle ( currVec , unit - > getType ( ) - > getSize ( ) , magicCircleRadius ) ;
}
}
//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 ) ;
//comand arrow
2010-09-10 10:51:32 +02:00
if ( focusArrows & & unit - > anyCommand ( ) ) {
2010-03-13 22:10:45 +01:00
const CommandType * ct = unit - > getCurrCommand ( ) - > getCommandType ( ) ;
2010-09-10 10:51:32 +02:00
if ( ct - > getClicks ( ) ! = cOne ) {
2010-03-13 22:10:45 +01:00
//arrow color
Vec3f arrowColor ;
2010-09-10 10:51:32 +02:00
switch ( ct - > getClass ( ) ) {
2010-03-13 22:10:45 +01:00
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 ) ;
}
//arrow target
Vec3f arrowTarget ;
Command * c = unit - > getCurrCommand ( ) ;
2010-09-10 10:51:32 +02:00
if ( c - > getUnit ( ) ! = NULL ) {
2010-03-13 22:10:45 +01:00
arrowTarget = c - > getUnit ( ) - > getCurrVectorFlat ( ) ;
}
2010-09-10 10:51:32 +02:00
else {
2010-03-13 22:10:45 +01:00
Vec2i pos = c - > getPos ( ) ;
2010-05-01 22:14:25 +02:00
arrowTarget = Vec3f ( pos . x , map - > getCell ( pos ) - > getHeight ( ) , pos . y ) ;
2010-03-13 22:10:45 +01:00
}
renderArrow ( unit - > getCurrVectorFlat ( ) , arrowTarget , arrowColor , 0.3f ) ;
}
}
//meeting point arrow
2010-09-10 10:51:32 +02:00
if ( unit - > getType ( ) - > getMeetingPoint ( ) ) {
2010-03-13 22:10:45 +01:00
Vec2i pos = unit - > getMeetingPos ( ) ;
2010-05-01 22:14:25 +02:00
Vec3f arrowTarget = Vec3f ( pos . x , map - > getCell ( pos ) - > getHeight ( ) , pos . y ) ;
2010-03-13 22:10:45 +01:00
renderArrow ( unit - > getCurrVectorFlat ( ) , arrowTarget , Vec3f ( 0.f , 0.f , 1.f ) , 0.3f ) ;
}
}
//render selection hightlights
2010-09-10 10:51:32 +02:00
for ( int i = 0 ; i < world - > getFactionCount ( ) ; + + i ) {
for ( int j = 0 ; j < world - > getFaction ( i ) - > getUnitCount ( ) ; + + j ) {
2010-03-13 22:10:45 +01:00
const Unit * unit = world - > getFaction ( i ) - > getUnit ( j ) ;
2010-09-10 10:51:32 +02:00
if ( unit - > isHighlighted ( ) ) {
2010-03-13 22:10:45 +01:00
float highlight = unit - > getHightlight ( ) ;
2010-09-10 10:51:32 +02:00
if ( game - > getWorld ( ) - > getThisFactionIndex ( ) = = unit - > getFactionIndex ( ) ) {
2010-03-13 22:10:45 +01:00
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 ( ) , selectionCircleRadius ) ;
}
}
}
glPopAttrib ( ) ;
}
void Renderer : : renderWaterEffects ( ) {
const World * world = game - > getWorld ( ) ;
const WaterEffects * we = world - > getWaterEffects ( ) ;
const Map * map = world - > getMap ( ) ;
const CoreData & coreData = CoreData : : getInstance ( ) ;
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 ( ) ;
}
void Renderer : : renderMinimap ( ) {
const World * world = game - > getWorld ( ) ;
const Minimap * minimap = world - > getMinimap ( ) ;
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 ( ) ;
glPushAttrib ( GL_CURRENT_BIT | GL_ENABLE_BIT | GL_LINE_BIT | GL_TEXTURE_BIT ) ;
//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 ( ) ) ;
glColor4f ( 0.5f , 0.5f , 0.5f , 0.1f ) ;
glBegin ( GL_TRIANGLE_STRIP ) ;
glTexCoord2f ( 0.0f , 1.0f ) ;
glMultiTexCoord2f ( fowTexUnit , 0.0f , 1.0f ) ;
glVertex2i ( mx , my ) ;
glTexCoord2f ( 0.0f , 0.0f ) ;
glMultiTexCoord2f ( fowTexUnit , 0.0f , 0.0f ) ;
glVertex2i ( mx , my + mh ) ;
glTexCoord2f ( 1.0f , 1.0f ) ;
glMultiTexCoord2f ( fowTexUnit , 1.0f , 1.0f ) ;
glVertex2i ( mx + mw , my ) ;
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 ;
Vec2f vertices [ itemCount ] ;
Vec4f colors [ itemCount ] ;
// draw attack alarm
int vertexIndex = 0 ;
//int vertexIndex1 = 0;
for ( int i = 0 ; i < attackEffects - > getWaterSplashCount ( ) ; + + i ) {
const WaterSplash * ws = attackEffects - > getWaterSplash ( i ) ;
2010-12-19 23:33:08 +01:00
float scale = ( 1 / ws - > getAnim ( ) * ws - > getSize ( ) ) * 5 ;
2011-02-09 02:27:41 +01:00
//glColor4f(1.f, 1.f, 0.f, 1.f-ws->getAnim());
2010-12-19 23:33:08 +01:00
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();
2011-02-09 02:27:41 +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 ) ;
vertices [ vertexIndex ] = Vec2f ( attackX - scale , attackY + scale ) ;
vertexIndex + + ;
colors [ vertexIndex ] = Vec4f ( 1.f , 1.f , 0.f , 0.8f ) ;
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 , alpha ) ;
vertices [ vertexIndex ] = Vec2f ( attackX + scale , attackY + scale ) ;
vertexIndex + + ;
colors [ vertexIndex ] = Vec4f ( 1.f , 1.f , 0.f , 0.8f ) ;
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 , alpha ) ;
vertices [ vertexIndex ] = Vec2f ( attackX - scale , attackY - scale ) ;
vertexIndex + + ;
colors [ vertexIndex ] = Vec4f ( 1.f , 1.f , 0.f , 0.8f ) ;
vertices [ vertexIndex ] = Vec2f ( attackX , attackY ) ;
vertexIndex + + ;
colors [ vertexIndex ] = Vec4f ( 1.f , 1.f , 0.f , alpha ) ;
vertices [ vertexIndex ] = Vec2f ( attackX , attackY ) ;
vertexIndex + + ;
colors [ vertexIndex ] = Vec4f ( 1.f , 1.f , 0.f , alpha ) ;
vertices [ vertexIndex ] = Vec2f ( attackX , attackY ) ;
vertexIndex + + ;
colors [ vertexIndex ] = Vec4f ( 1.f , 1.f , 0.f , 0.8f ) ;
vertices [ vertexIndex ] = Vec2f ( attackX , attackY ) ;
vertexIndex + + ;
/*
2010-12-19 23:33:08 +01:00
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 ) ;
2010-12-24 03:10:31 +01:00
glColor4f ( 1.f , 1.f , 0.f , alpha ) ;
2010-12-19 23:33:08 +01:00
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
glBegin ( GL_TRIANGLES ) ;
glColor4f ( 1.f , 1.f , 0.f , alpha ) ;
2010-12-19 23:33:08 +01:00
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
glBegin ( GL_TRIANGLES ) ;
glColor4f ( 1.f , 1.f , 0.f , alpha ) ;
2010-12-19 23:33:08 +01:00
glVertex2f ( attackX + scale , attackY - scale ) ;
glVertex2f ( attackX - scale , attackY - scale ) ;
glColor4f ( 1.f , 1.f , 0.f , 0.8f ) ;
glVertex2f ( attackX , attackY ) ;
glEnd ( ) ;
2011-02-09 02:27:41 +01:00
*/
2010-12-24 03:10:31 +01:00
2010-12-19 23:33:08 +01:00
}
}
2011-02-09 02:27:41 +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 ) ;
}
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 ( ) ;
if ( qCache . visibleUnitList . size ( ) > 0 ) {
2011-02-09 02:27:41 +01:00
uint32 unitIdx = 0 ;
Vec2f unit_vertices [ qCache . visibleUnitList . size ( ) * 4 ] ;
Vec3f unit_colors [ qCache . visibleUnitList . size ( ) * 4 ] ;
2011-01-15 09:45:17 +01:00
for ( int visibleIndex = 0 ;
visibleIndex < qCache . visibleUnitList . size ( ) ; + + visibleIndex ) {
Unit * unit = qCache . 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 + + ;
/*
2011-01-15 09:45:17 +01:00
glColor3fv ( color . ptr ( ) ) ;
2010-09-10 10:51:32 +02:00
2011-01-15 09:45:17 +01:00
glBegin ( GL_QUADS ) ;
2010-09-10 10:51:32 +02:00
2011-01-15 09:45:17 +01:00
glVertex2f ( mx + pos . x * zoom . x , my + mh - ( pos . y * zoom . y ) ) ;
glVertex2f ( mx + ( pos . x + 1 ) * zoom . x + size , my + mh - ( pos . y * zoom . y ) ) ;
glVertex2f ( mx + ( pos . x + 1 ) * zoom . x + size , my + mh - ( ( pos . y + size ) * zoom . y ) ) ;
glVertex2f ( mx + pos . x * zoom . x , my + mh - ( ( pos . y + size ) * zoom . y ) ) ;
2010-09-10 10:51:32 +02:00
2011-01-15 09:45:17 +01:00
glEnd ( ) ;
2011-02-09 02:27:41 +01:00
*/
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
//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 ) ;
2010-09-10 10:51:32 +02:00
int x1 = 0 ;
int y1 = 0 ;
2010-05-01 22:14:25 +02:00
# ifdef USE_STREFLOP
2010-09-10 10:51:32 +02:00
x1 = mx + x + static_cast < int > ( 20 * streflop : : sin ( ang - pi / 5 ) ) ;
y1 = my + mh - ( y - static_cast < int > ( 20 * streflop : : cos ( ang - pi / 5 ) ) ) ;
2010-05-01 22:14:25 +02:00
# else
2010-09-10 10:51:32 +02:00
x1 = mx + x + static_cast < int > ( 20 * sin ( ang - pi / 5 ) ) ;
y1 = my + mh - ( y - static_cast < int > ( 20 * cos ( ang - pi / 5 ) ) ) ;
2010-05-01 22:14:25 +02:00
# endif
2010-09-10 10:51:32 +02:00
int x2 = 0 ;
int y2 = 0 ;
2010-05-01 22:14:25 +02:00
# ifdef USE_STREFLOP
2010-09-10 10:51:32 +02:00
x2 = mx + x + static_cast < int > ( 20 * streflop : : sin ( ang + pi / 5 ) ) ;
y2 = my + mh - ( y - static_cast < int > ( 20 * streflop : : cos ( ang + pi / 5 ) ) ) ;
2010-05-01 22:14:25 +02:00
# else
2010-09-10 10:51:32 +02:00
x2 = mx + x + static_cast < int > ( 20 * sin ( ang + pi / 5 ) ) ;
y2 = my + mh - ( y - static_cast < int > ( 20 * cos ( ang + pi / 5 ) ) ) ;
2010-05-01 22:14:25 +02:00
# endif
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 ( ) ;
}
void Renderer : : renderDisplay ( ) {
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
2010-03-13 22:10:45 +01:00
//infoString
renderTextShadow (
display - > getInfoText ( ) . c_str ( ) ,
coreData . getDisplayFont ( ) ,
2010-04-08 22:19:25 +02:00
display - > getColor ( ) ,
2010-03-13 22:10:45 +01:00
metrics . getDisplayX ( ) ,
metrics . getDisplayY ( ) + Display : : infoStringY ) ;
//title
renderTextShadow (
display - > getTitle ( ) . c_str ( ) ,
coreData . getDisplayFont ( ) ,
2010-04-08 22:19:25 +02:00
display - > getColor ( ) ,
2010-03-13 22:10:45 +01:00
metrics . getDisplayX ( ) + 40 ,
metrics . getDisplayY ( ) + metrics . getDisplayH ( ) - 20 ) ;
glColor3f ( 0.0f , 0.0f , 0.0f ) ;
//text
renderTextShadow (
display - > getText ( ) . c_str ( ) ,
coreData . getDisplayFont ( ) ,
2010-04-08 22:19:25 +02:00
display - > getColor ( ) ,
2010-03-13 22:10:45 +01:00
metrics . getDisplayX ( ) - 1 ,
metrics . getDisplayY ( ) + metrics . getDisplayH ( ) - 56 ) ;
//progress Bar
if ( display - > getProgressBar ( ) ! = - 1 ) {
renderProgressBar (
display - > getProgressBar ( ) ,
metrics . getDisplayX ( ) ,
metrics . getDisplayY ( ) + metrics . getDisplayH ( ) - 50 ,
2010-04-08 00:20:28 +02:00
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 ) ,
Display : : imageSize , Display : : imageSize , display - > getUpImage ( i ) ) ;
}
}
//down images
for ( int i = 0 ; i < Display : : downCellCount ; + + i ) {
if ( display - > getDownImage ( i ) ! = NULL ) {
if ( display - > getDownLighted ( i ) ) {
glColor3f ( 1.f , 1.f , 1.f ) ;
}
else {
glColor3f ( 0.3f , 0.3f , 0.3f ) ;
}
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 ( ) ;
}
void Renderer : : renderMenuBackground ( const MenuBackground * menuBackground ) {
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 ) ;
modelRenderer - > begin ( true , true , 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 ( ) ) ;
modelRenderer - > begin ( true , true , false ) ;
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 ( ) ;
glTranslatef ( i * 2.f - 4.f , - 1.4f , - 7.5f ) ;
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 ) ) ;
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 ( ) ;
}
// ==================== computing ====================
bool Renderer : : computePosition ( const Vec2i & screenPos , Vec2i & worldPos ) {
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
worldPos = Vec2i ( static_cast < int > ( worldX + 0.5f ) , static_cast < int > ( worldZ + 0.5f ) ) ;
//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 ) {
2010-11-02 20:52:20 +01: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 ) ;
2010-11-02 20:52:20 +01:00
worldToScreenPosCache [ worldPos ] = screenPos ;
2010-05-29 07:41:40 +02:00
return screenPos ;
}
2010-09-10 10:51:32 +02:00
void Renderer : : computeSelected ( Selection : : UnitContainer & units ,
const Vec2i & posDown , const Vec2i & posUp ) {
2010-03-13 22:10:45 +01:00
//declarations
GLuint selectBuffer [ Gui : : maxSelBuff ] ;
const Metrics & metrics = Metrics : : getInstance ( ) ;
//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 ) ;
if ( w < 1 ) w = 1 ;
if ( h < 1 ) h = 1 ;
//setup matrices
glSelectBuffer ( Gui : : maxSelBuff , selectBuffer ) ;
glMatrixMode ( GL_PROJECTION ) ;
glPushMatrix ( ) ;
GLint view [ ] = { 0 , 0 , metrics . getVirtualW ( ) , metrics . getVirtualH ( ) } ;
glRenderMode ( GL_SELECT ) ;
glLoadIdentity ( ) ;
gluPickMatrix ( x , y , w , h , view ) ;
gluPerspective ( perspFov , metrics . getAspectRatio ( ) , perspNearPlane , perspFarPlane ) ;
loadGameCameraMatrix ( ) ;
2010-09-10 10:51:32 +02:00
//render units to find which ones should be selected
2010-03-13 22:10:45 +01:00
renderUnitsFast ( ) ;
//pop matrices
glMatrixMode ( GL_PROJECTION ) ;
glPopMatrix ( ) ;
2010-09-10 10:51:32 +02:00
//select units by checking the selected buffer
2010-03-13 22:10:45 +01:00
int selCount = glRenderMode ( GL_RENDER ) ;
2010-09-10 10:51:32 +02:00
if ( selCount > 0 ) {
2010-09-10 16:06:31 +02:00
VisibleQuadContainerCache & qCache = getQuadCache ( ) ;
2010-09-10 10:51:32 +02:00
for ( int i = 1 ; i < = selCount ; + + i ) {
2010-09-10 16:06:31 +02:00
int visibleUnitIndex = selectBuffer [ i * 4 - 1 ] ;
Unit * unit = qCache . visibleQuadUnitList [ visibleUnitIndex ] ;
if ( unit ! = NULL & & unit - > isAlive ( ) ) {
units . push_back ( unit ) ;
2010-03-13 22:10:45 +01:00
}
}
}
}
// ==================== shadows ====================
2010-06-15 18:27:52 +02:00
void Renderer : : renderShadowsToTexture ( const int renderFps ) {
2010-10-04 18:43:00 +02:00
if ( ! shadowsOffDueToMinRender & &
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
2010-07-06 08:30:49 +02:00
if ( shadows = = sShadowMapping ) {
glClear ( GL_DEPTH_BUFFER_BIT ) ;
}
else {
float color = 1.0f - shadowAlpha ;
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
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
2010-07-06 08:30:49 +02:00
if ( nearestLightPos . w = = 0.f ) {
//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 ( ) ;
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
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 ) ) ;
}
else {
//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 ( ) ;
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
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 ) ;
}
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 ) ;
glPolygonOffset ( 1.0f , 0.001f ) ;
}
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 ) ;
2010-07-06 08:30:49 +02:00
renderObjectsFast ( ) ;
2010-03-13 22:10:45 +01:00
2010-07-06 08:30:49 +02:00
//read color buffer
glBindTexture ( GL_TEXTURE_2D , shadowMapHandle ) ;
glCopyTexSubImage2D ( GL_TEXTURE_2D , 0 , 0 , 0 , 0 , 0 , shadowTextureSize , shadowTextureSize ) ;
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
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
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
2010-07-06 08:30:49 +02:00
//pop
glPopMatrix ( ) ;
2010-03-13 22:10:45 +01:00
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 ( ) {
string infoStr ;
Lang & lang = Lang : : getInstance ( ) ;
infoStr + = lang . get ( " OpenGlInfo " ) + " : \n " ;
infoStr + = " " + lang . get ( " OpenGlVersion " ) + " : " ;
2010-07-12 08:30:54 +02:00
infoStr + = string ( ( getGlVersion ( ) ! = NULL ? getGlVersion ( ) : " ? " ) ) + " \n " ;
2010-03-13 22:10:45 +01:00
infoStr + = " " + lang . get ( " OpenGlRenderer " ) + " : " ;
2010-07-12 08:30:54 +02:00
infoStr + = string ( ( getGlVersion ( ) ! = NULL ? getGlVersion ( ) : " ? " ) ) + " \n " ;
2010-03-13 22:10:45 +01:00
infoStr + = " " + lang . get ( " OpenGlVendor " ) + " : " ;
2010-07-12 08:30:54 +02:00
infoStr + = string ( ( getGlVendor ( ) ! = NULL ? getGlVendor ( ) : " ? " ) ) + " \n " ;
2010-03-13 22:10:45 +01:00
infoStr + = " " + lang . get ( " OpenGlMaxLights " ) + " : " ;
infoStr + = intToStr ( getGlMaxLights ( ) ) + " \n " ;
infoStr + = " " + lang . get ( " OpenGlMaxTextureSize " ) + " : " ;
infoStr + = intToStr ( getGlMaxTextureSize ( ) ) + " \n " ;
infoStr + = " " + lang . get ( " OpenGlMaxTextureUnits " ) + " : " ;
infoStr + = intToStr ( getGlMaxTextureUnits ( ) ) + " \n " ;
infoStr + = " " + lang . get ( " OpenGlModelviewStack " ) + " : " ;
infoStr + = intToStr ( getGlModelviewMatrixStackDepth ( ) ) + " \n " ;
infoStr + = " " + lang . get ( " OpenGlProjectionStack " ) + " : " ;
infoStr + = intToStr ( getGlProjectionMatrixStackDepth ( ) ) + " \n " ;
return infoStr ;
}
string Renderer : : getGlMoreInfo ( ) {
string infoStr ;
Lang & lang = Lang : : getInstance ( ) ;
//gl extensions
infoStr + = lang . get ( " OpenGlExtensions " ) + " : \n " ;
string extensions = getGlExtensions ( ) ;
int charCount = 0 ;
for ( int i = 0 ; i < extensions . size ( ) ; + + i ) {
infoStr + = extensions [ i ] ;
if ( charCount > 120 & & extensions [ i ] = = ' ' ) {
infoStr + = " \n " ;
charCount = 0 ;
}
+ + charCount ;
}
//platform extensions
infoStr + = " \n \n " ;
infoStr + = lang . get ( " OpenGlPlatformExtensions " ) + " : \n " ;
charCount = 0 ;
string platformExtensions = getGlPlatformExtensions ( ) ;
for ( int i = 0 ; i < platformExtensions . size ( ) ; + + i ) {
infoStr + = platformExtensions [ i ] ;
if ( charCount > 120 & & platformExtensions [ i ] = = ' ' ) {
infoStr + = " \n " ;
charCount = 0 ;
}
+ + charCount ;
}
return infoStr ;
}
void Renderer : : autoConfig ( ) {
Config & config = Config : : getInstance ( ) ;
bool nvidiaCard = toLower ( getGlVendor ( ) ) . find ( " nvidia " ) ! = string : : npos ;
bool atiCard = toLower ( getGlVendor ( ) ) . find ( " ati " ) ! = string : : npos ;
2010-10-27 17:04:47 +02:00
//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
//3D textures
config . setBool ( " Textures3D " , isGlExtensionSupported ( " GL_EXT_texture3D " ) ) ;
//shadows
string shadows ;
if ( getGlMaxTextureUnits ( ) > = 3 ) {
if ( nvidiaCard & & shadowExtensions ) {
shadows = shadowsToStr ( sShadowMapping ) ;
}
else {
shadows = shadowsToStr ( sProjected ) ;
}
}
else {
shadows = shadowsToStr ( sDisabled ) ;
}
config . setString ( " Shadows " , shadows ) ;
//lights
config . setInt ( " MaxLights " , atiCard ? 1 : 4 ) ;
//filter
config . setString ( " Filter " , " Bilinear " ) ;
}
void Renderer : : clearBuffers ( ) {
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ;
}
void Renderer : : clearZBuffer ( ) {
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 " ) ;
//load shadows
shadows = strToShadows ( config . getString ( " Shadows " ) ) ;
if ( shadows = = sProjected | | shadows = = sShadowMapping ) {
shadowTextureSize = config . getInt ( " ShadowTextureSize " ) ;
shadowFrameSkip = config . getInt ( " ShadowFrameSkip " ) ;
shadowAlpha = config . getFloat ( " ShadowAlpha " ) ;
}
//load filter settings
Texture2D : : Filter textureFilter = strToTextureFilter ( config . getString ( " Filter " ) ) ;
int maxAnisotropy = config . getInt ( " FilterMaxAnisotropy " ) ;
for ( int i = 0 ; i < rsCount ; + + i ) {
textureManager [ i ] - > setFilter ( textureFilter ) ;
textureManager [ i ] - > setMaxAnisotropy ( maxAnisotropy ) ;
}
}
2010-11-01 17:44:05 +01:00
Texture2D * Renderer : : saveScreenToTexture ( int x , int y , int width , int height ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __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->setFormat(Texture::fRgba);
texture - > setForceCompressionDisabled ( true ) ;
texture - > setMipmap ( false ) ;
//Pixmap2D *pixmapScreenShot = new Pixmap2D(width, height, 3);
Pixmap2D * pixmapScreenShot = texture - > getPixmap ( ) ;
pixmapScreenShot - > init ( width , height , 3 ) ;
//const Metrics &sm= Metrics::getInstance();
//pixmapScreenShot->init(sm.getScreenW(), sm.getScreenH(), 3);
texture - > init ( textureFilter , maxAnisotropy ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
//glFinish();
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
glReadPixels ( x , y , pixmapScreenShot - > getW ( ) , pixmapScreenShot - > getH ( ) ,
GL_RGB , GL_UNSIGNED_BYTE , pixmapScreenShot - > getPixels ( ) ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
return texture ;
}
2010-10-30 04:21:47 +02:00
void Renderer : : saveScreen ( const string & path ) {
2010-03-13 22:10:45 +01:00
const Metrics & sm = Metrics : : getInstance ( ) ;
2010-09-17 06:59:32 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
//Pixmap2D pixmap(sm.getScreenW(), sm.getScreenH(), 3);
2010-10-30 04:21:47 +02:00
Pixmap2D * pixmapScreenShot = new Pixmap2D ( sm . getScreenW ( ) , sm . getScreenH ( ) , 3 ) ;
2010-09-17 06:59:32 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-09-15 00:26:54 +02:00
glFinish ( ) ;
2010-09-17 06:59:32 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
glReadPixels ( 0 , 0 , pixmapScreenShot - > getW ( ) , pixmapScreenShot - > getH ( ) ,
GL_RGB , GL_UNSIGNED_BYTE , pixmapScreenShot - > getPixels ( ) ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-10-30 04:21:47 +02:00
// Signal the threads queue to add a screenshot save request
2011-02-01 00:01:39 +01:00
MutexSafeWrapper safeMutex ( & saveScreenShotThreadAccessor , string ( __FILE__ ) + " _ " + 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
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
}
2010-10-30 04:21:47 +02:00
unsigned int Renderer : : getSaveScreenQueueSize ( ) {
2011-02-01 00:01:39 +01:00
MutexSafeWrapper safeMutex ( & saveScreenShotThreadAccessor , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2010-10-30 04:21:47 +02:00
int queueSize = saveScreenQueue . size ( ) ;
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 ) ;
2010-05-01 22:14:25 +02:00
# ifdef USE_STREFLOP
2010-04-24 05:57:38 +02:00
return Vec4f ( - streflop : : cos ( ang ) * sunDist , streflop : : sin ( ang ) * sunDist , 0.f , 0.f ) ;
2010-05-01 22:14:25 +02:00
# else
return Vec4f ( - cos ( ang ) * sunDist , sin ( ang ) * sunDist , 0.f , 0.f ) ;
# endif
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 ) ;
2010-05-01 22:14:25 +02:00
# ifdef USE_STREFLOP
2010-04-24 05:57:38 +02:00
return Vec4f ( - streflop : : cos ( ang ) * moonDist , streflop : : sin ( ang ) * moonDist , 0.f , 0.f ) ;
2010-05-01 22:14:25 +02:00
# else
return Vec4f ( - cos ( ang ) * moonDist , sin ( ang ) * moonDist , 0.f , 0.f ) ;
# endif
2010-03-13 22:10:45 +01:00
}
2010-09-10 10:51:32 +02:00
Vec3f Renderer : : computeLightColor ( float time ) {
2010-03-13 22:10:45 +01:00
const Tileset * tileset = game - > getWorld ( ) - > getTileset ( ) ;
Vec3f color ;
const float transition = 2 ;
const float dayStart = TimeFlow : : dawn ;
const float dayEnd = TimeFlow : : dusk - transition ;
const float nightStart = TimeFlow : : dusk ;
const float nightEnd = TimeFlow : : dawn - transition ;
2010-09-10 10:51:32 +02:00
if ( time > dayStart & & time < dayEnd ) {
2010-03-13 22:10:45 +01:00
color = tileset - > getSunLightColor ( ) ;
}
2010-09-10 10:51:32 +02:00
else if ( time > nightStart | | time < nightEnd ) {
2010-03-13 22:10:45 +01:00
color = tileset - > getMoonLightColor ( ) ;
}
2010-09-10 10:51:32 +02:00
else if ( time > = dayEnd & & time < = nightStart ) {
2010-03-13 22:10:45 +01:00
color = tileset - > getSunLightColor ( ) . lerp ( ( time - dayEnd ) / transition , tileset - > getMoonLightColor ( ) ) ;
}
2010-09-10 10:51:32 +02:00
else if ( time > = nightEnd & & time < = dayStart ) {
2010-03-13 22:10:45 +01:00
color = tileset - > getMoonLightColor ( ) . lerp ( ( time - nightEnd ) / transition , tileset - > getSunLightColor ( ) ) ;
}
2010-09-10 10:51:32 +02:00
else {
2010-03-13 22:10:45 +01:00
assert ( false ) ;
color = tileset - > getSunLightColor ( ) ;
}
return color ;
}
2010-09-10 10:51:32 +02:00
Vec4f Renderer : : computeWaterColor ( float waterLevel , float cellHeight ) {
2010-03-13 22:10:45 +01:00
const float waterFactor = 1.5f ;
return Vec4f ( 1.f , 1.f , 1.f , clamp ( ( waterLevel - cellHeight ) * waterFactor , 0.f , 1.f ) ) ;
}
// ==================== fast render ====================
//render units for selection purposes
2010-09-26 01:03:27 +02:00
void Renderer : : renderUnitsFast ( bool renderingShadows ) {
2010-05-03 08:25:54 +02:00
assert ( game ! = NULL ) ;
2010-03-13 22:10:45 +01:00
const World * world = game - > getWorld ( ) ;
2010-05-03 08:25:54 +02:00
assert ( world ! = NULL ) ;
2010-03-13 22:10:45 +01:00
assertGl ( ) ;
2010-08-21 20:50:56 +02:00
bool modelRenderStarted = false ;
2011-01-15 09:45:17 +01:00
VisibleQuadContainerCache & qCache = getQuadCache ( ) ;
if ( qCache . visibleQuadUnitList . size ( ) > 0 ) {
for ( int visibleUnitIndex = 0 ;
visibleUnitIndex < qCache . visibleQuadUnitList . size ( ) ; + + visibleUnitIndex ) {
Unit * unit = qCache . visibleQuadUnitList [ visibleUnitIndex ] ;
2010-12-05 02:33:28 +01:00
2011-01-15 09:45:17 +01:00
if ( modelRenderStarted = = false ) {
modelRenderStarted = true ;
//glPushAttrib(GL_ENABLE_BIT| GL_TEXTURE_BIT);
glDisable ( GL_LIGHTING ) ;
if ( renderingShadows = = false ) {
glPushAttrib ( GL_ENABLE_BIT ) ;
glDisable ( GL_TEXTURE_2D ) ;
2010-08-21 20:50:56 +02:00
}
2011-01-15 09:45:17 +01:00
else {
glPushAttrib ( GL_ENABLE_BIT | GL_TEXTURE_BIT ) ;
glEnable ( GL_TEXTURE_2D ) ;
glAlphaFunc ( GL_GREATER , 0.4f ) ;
2010-09-10 10:51:32 +02:00
2011-01-15 09:45:17 +01:00
glTexEnvi ( GL_TEXTURE_ENV , GL_TEXTURE_ENV_MODE , GL_COMBINE ) ;
2010-05-10 19:50:57 +02:00
2011-01-15 09:45:17 +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-09-10 10:51:32 +02:00
2011-01-15 09:45:17 +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 ) ;
}
2010-09-10 10:51:32 +02:00
2011-01-15 09:45:17 +01:00
modelRenderer - > begin ( false , renderingShadows , false ) ;
glInitNames ( ) ;
2010-07-07 20:50:55 +02:00
}
2010-09-10 02:28:14 +02:00
2011-01-15 09:45:17 +01:00
glPushName ( visibleUnitIndex ) ;
2010-05-10 19:50:57 +02:00
2011-01-15 09:45:17 +01:00
glMatrixMode ( GL_MODELVIEW ) ;
//debuxar modelo
glPushMatrix ( ) ;
2010-09-10 10:51:32 +02:00
2011-01-15 09:45:17 +01:00
//translate
Vec3f currVec = unit - > getCurrVectorFlat ( ) ;
glTranslatef ( currVec . x , currVec . y , currVec . z ) ;
2010-09-10 10:51:32 +02:00
2011-01-15 09:45:17 +01:00
//rotate
glRotatef ( unit - > getRotation ( ) , 0.f , 1.f , 0.f ) ;
2010-09-10 10:51:32 +02:00
2011-01-15 09:45:17 +01:00
//render
2011-01-18 08:52:06 +01:00
Model * model = unit - > getCurrentModelPtr ( ) ;
2011-01-15 09:45:17 +01:00
model - > updateInterpolationVertices ( unit - > getAnimProgress ( ) , unit - > isAlive ( ) ) ;
modelRenderer - > render ( model ) ;
2010-09-10 10:51:32 +02:00
2011-01-15 09:45:17 +01:00
glPopMatrix ( ) ;
glPopName ( ) ;
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-06-22 01:38:53 +02:00
}
2010-05-10 19:50:57 +02:00
}
2010-09-10 10:51:32 +02:00
assertGl ( ) ;
2010-05-10 19:50:57 +02:00
}
2010-03-13 22:10:45 +01:00
//render objects for selection purposes
2010-06-15 18:27:52 +02:00
void Renderer : : renderObjectsFast ( ) {
2010-03-13 22:10:45 +01:00
const World * world = game - > getWorld ( ) ;
const Map * map = world - > getMap ( ) ;
assertGl ( ) ;
2010-08-21 20:50:56 +02:00
bool modelRenderStarted = false ;
2010-03-13 22:10:45 +01:00
2011-01-15 09:45:17 +01:00
VisibleQuadContainerCache & qCache = getQuadCache ( ) ;
if ( qCache . visibleObjectList . size ( ) > 0 ) {
for ( int visibleIndex = 0 ;
visibleIndex < qCache . visibleObjectList . size ( ) ; + + visibleIndex ) {
Object * o = qCache . visibleObjectList [ visibleIndex ] ;
2010-08-21 21:15:39 +02:00
2011-01-19 00:56:30 +01:00
Model * objModel = o - > getModelPtr ( ) ;
2011-01-15 09:45:17 +01:00
const Vec3f & v = o - > getConstPos ( ) ;
2010-08-21 21:15:39 +02:00
2011-01-15 09:45:17 +01:00
if ( modelRenderStarted = = false ) {
modelRenderStarted = true ;
glPushAttrib ( GL_ENABLE_BIT | GL_TEXTURE_BIT ) ;
glDisable ( GL_LIGHTING ) ;
2010-08-21 21:15:39 +02:00
2011-01-15 09:45:17 +01:00
glAlphaFunc ( GL_GREATER , 0.5f ) ;
2010-03-13 22:10:45 +01:00
2011-01-15 09:45:17 +01:00
glTexEnvi ( GL_TEXTURE_ENV , GL_TEXTURE_ENV_MODE , GL_COMBINE ) ;
2010-03-13 22:10:45 +01:00
2011-01-15 09:45:17 +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-01-15 09:45:17 +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 ) ;
2010-03-13 22:10:45 +01:00
2011-01-15 09:45:17 +01:00
modelRenderer - > begin ( false , true , false ) ;
2010-09-10 10:51:32 +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-05-10 19:50:57 +02:00
2011-01-15 09:45:17 +01:00
modelRenderer - > render ( objModel ) ;
2010-05-10 19:50:57 +02:00
2011-01-15 09:45:17 +01:00
glPopMatrix ( ) ;
2010-05-10 19:50:57 +02: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 ( ) ;
glPopAttrib ( ) ;
}
2010-05-10 19:50:57 +02:00
}
2010-09-10 10:51:32 +02:00
assertGl ( ) ;
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 ( ) {
2010-03-13 22:10:45 +01:00
//opengl 1.3
2010-09-10 10:51:32 +02:00
if ( ! isGlVersionSupported ( 1 , 3 , 0 ) ) {
2010-03-13 22:10:45 +01:00
string message ;
message + = " Your system supports OpenGL version \" " ;
message + = getGlVersion ( ) + string ( " \" \n " ) ;
2010-12-13 01:32:59 +01:00
message + = " MegaGlest needs at least version 1.3 to work \n " ;
2010-03-13 22:10:45 +01:00
message + = " You may solve this problem by installing your latest video card drivers " ;
throw runtime_error ( message . c_str ( ) ) ;
}
//opengl 1.4 or extension
if ( ! isGlVersionSupported ( 1 , 4 , 0 ) ) {
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 ( ) {
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 ) {
2010-03-13 22:10:45 +01:00
throw runtime_error ( " Your system doesn't support 3 texture units, required for shadows " ) ;
}
}
//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
}
}
2010-09-10 10:51:32 +02:00
void Renderer : : checkExtension ( const string & extension , const string & msg ) {
if ( ! isGlExtensionSupported ( extension . c_str ( ) ) ) {
2010-03-13 22:10:45 +01:00
string str = " OpenGL extension not supported: " + extension + " , required for " + msg ;
throw runtime_error ( str ) ;
}
}
// ==================== init 3d lists ====================
2010-09-10 10:51:32 +02:00
void Renderer : : init3dList ( ) {
2010-03-13 22:10:45 +01:00
2010-04-04 06:14:27 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
const Metrics & metrics = Metrics : : getInstance ( ) ;
assertGl ( ) ;
2010-04-04 06:14:27 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
list3d = glGenLists ( 1 ) ;
2010-04-04 06:14:27 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
glNewList ( list3d , GL_COMPILE_AND_EXECUTE ) ;
//need to execute, because if not gluPerspective takes no effect and gluLoadMatrix is wrong
2010-04-04 06:14:27 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01: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-04-04 06:14:27 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
//texture state
glActiveTexture ( shadowTexUnit ) ;
glDisable ( GL_TEXTURE_2D ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_TEXTURE_ENV_MODE , GL_MODULATE ) ;
glActiveTexture ( fowTexUnit ) ;
glDisable ( GL_TEXTURE_2D ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_TEXTURE_ENV_MODE , GL_MODULATE ) ;
glActiveTexture ( baseTexUnit ) ;
glEnable ( GL_TEXTURE_2D ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_TEXTURE_ENV_MODE , GL_MODULATE ) ;
2010-04-04 06:14:27 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01: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 ( ) ) ;
//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 ) ;
2010-04-04 06:14:27 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
//lighting state
glEnable ( GL_LIGHTING ) ;
glEnable ( GL_LIGHT0 ) ;
//matrix mode
glMatrixMode ( GL_MODELVIEW ) ;
//stencil test
glDisable ( GL_STENCIL_TEST ) ;
2010-04-04 06:14:27 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
//fog
2010-04-04 06:14:27 +02:00
const Tileset * tileset = NULL ;
if ( game ! = NULL & & game - > getWorld ( ) ! = NULL ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
tileset = game - > getWorld ( ) - > getTileset ( ) ;
}
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-09-10 10:51:32 +02:00
if ( tileset ! = NULL & & tileset - > getFog ( ) ) {
2010-04-04 06:14:27 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
glEnable ( GL_FOG ) ;
2010-09-10 10:51:32 +02:00
if ( tileset - > getFogMode ( ) = = fmExp ) {
2010-03-13 22:10:45 +01:00
glFogi ( GL_FOG_MODE , GL_EXP ) ;
}
2010-09-10 10:51:32 +02:00
else {
2010-03-13 22:10:45 +01:00
glFogi ( GL_FOG_MODE , GL_EXP2 ) ;
}
glFogf ( GL_FOG_DENSITY , tileset - > getFogDensity ( ) ) ;
glFogfv ( GL_FOG_COLOR , tileset - > getFogColor ( ) . ptr ( ) ) ;
}
2010-04-04 06:14:27 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
glEndList ( ) ;
2010-04-04 06:14:27 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
//assert
assertGl ( ) ;
}
2010-09-10 10:51:32 +02:00
void Renderer : : init2dList ( ) {
2010-03-13 22:10:45 +01:00
const Metrics & metrics = Metrics : : getInstance ( ) ;
//this list sets the state for the 2d rendering
list2d = glGenLists ( 1 ) ;
glNewList ( list2d , GL_COMPILE ) ;
//projection
glViewport ( 0 , 0 , metrics . getScreenW ( ) , metrics . getScreenH ( ) ) ;
glMatrixMode ( GL_PROJECTION ) ;
glLoadIdentity ( ) ;
glOrtho ( 0 , metrics . getVirtualW ( ) , 0 , metrics . getVirtualH ( ) , 0 , 1 ) ;
//modelview
glMatrixMode ( GL_MODELVIEW ) ;
glLoadIdentity ( ) ;
//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 ) ;
glActiveTexture ( baseTexUnit ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_TEXTURE_ENV_MODE , GL_MODULATE ) ;
glDisable ( GL_TEXTURE_2D ) ;
//blend func
glBlendFunc ( GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA ) ;
//color
glColor4f ( 1.f , 1.f , 1.f , 1.f ) ;
glEndList ( ) ;
assertGl ( ) ;
}
2010-09-10 10:51:32 +02:00
void Renderer : : init3dListMenu ( const MainMenu * mm ) {
2010-03-13 22:10:45 +01:00
assertGl ( ) ;
2010-04-04 06:14:27 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
const Metrics & metrics = Metrics : : getInstance ( ) ;
2010-04-04 06:14:27 +02:00
const MenuBackground * mb = mm - > getConstMenuBackground ( ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
list3dMenu = glGenLists ( 1 ) ;
2010-04-04 06:14:27 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
glNewList ( list3dMenu , GL_COMPILE ) ;
2010-04-04 06:14:27 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
//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 , 1000 ) ;
//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 ) ;
2010-04-04 06:14:27 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
//fog
2010-04-04 06:14:27 +02:00
if ( mb ! = NULL & & mb - > getFog ( ) ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
glEnable ( GL_FOG ) ;
glFogi ( GL_FOG_MODE , GL_EXP2 ) ;
glFogf ( GL_FOG_DENSITY , mb - > getFogDensity ( ) ) ;
}
2010-04-04 06:14:27 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
glEndList ( ) ;
2010-04-04 06:14:27 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
//assert
assertGl ( ) ;
}
// ==================== misc ====================
2010-09-10 10:51:32 +02:00
void Renderer : : loadProjectionMatrix ( ) {
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 ( ) {
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 ====================
2010-09-10 10:51:32 +02:00
void Renderer : : renderSelectionCircle ( Vec3f v , int size , float radius ) {
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 ) ;
gluCylinder ( disc , radius * ( size - 0.2f ) , radius * size , 0.2f , 30 , 1 ) ;
gluDeleteQuadric ( disc ) ;
glPopMatrix ( ) ;
}
2010-09-10 10:51:32 +02:00
void Renderer : : renderArrow ( const Vec3f & pos1 , const Vec3f & pos2 ,
const Vec3f & color , float width ) {
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 ) ;
float len = dir . length ( ) ;
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 ) ;
dir . normalize ( ) ;
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-01-04 09:44:00 +01:00
void Renderer : : renderProgressBar ( int size , int x , int y , Font2D * font , int customWidth , string prefixLabel ) {
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 ;
}
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 ( ) ) ;
textRenderer - > begin ( font ) ;
2011-01-04 09:44:00 +01:00
textRenderer - > render ( renderText . c_str ( ) , x + maxSize / 2 , y , true ) ;
2010-03-13 22:10:45 +01:00
textRenderer - > end ( ) ;
}
2010-09-10 10:51:32 +02:00
void Renderer : : renderTile ( const Vec2i & pos ) {
2010-03-13 22:10:45 +01:00
const Map * map = game - > getWorld ( ) - > getMap ( ) ;
Vec2i scaledPos = pos * Map : : cellScale ;
glMatrixMode ( GL_MODELVIEW ) ;
glPushMatrix ( ) ;
glTranslatef ( - 0.5f , 0.f , - 0.5f ) ;
glInitNames ( ) ;
2010-09-10 10:51:32 +02:00
for ( int i = 0 ; i < Map : : cellScale ; + + i ) {
for ( int j = 0 ; j < Map : : cellScale ; + + j ) {
2010-03-13 22:10:45 +01:00
Vec2i renderPos = scaledPos + Vec2i ( i , j ) ;
glPushName ( renderPos . y ) ;
glPushName ( renderPos . x ) ;
glDisable ( GL_CULL_FACE ) ;
2010-09-10 10:51:32 +02:00
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 ( ) ;
2010-03-13 22:10:45 +01:00
glBegin ( GL_TRIANGLE_STRIP ) ;
glVertex3f (
static_cast < float > ( renderPos . x ) ,
2010-09-10 10:51:32 +02:00
h1 ,
2010-03-13 22:10:45 +01:00
static_cast < float > ( renderPos . y ) ) ;
glVertex3f (
static_cast < float > ( renderPos . x ) ,
2010-09-10 10:51:32 +02:00
h2 ,
2010-03-13 22:10:45 +01:00
static_cast < float > ( renderPos . y + 1 ) ) ;
glVertex3f (
static_cast < float > ( renderPos . x + 1 ) ,
2010-09-10 10:51:32 +02:00
h3 ,
2010-03-13 22:10:45 +01:00
static_cast < float > ( renderPos . y ) ) ;
glVertex3f (
static_cast < float > ( renderPos . x + 1 ) ,
2010-09-10 10:51:32 +02:00
h4 ,
2010-03-13 22:10:45 +01:00
static_cast < float > ( renderPos . y + 1 ) ) ;
glEnd ( ) ;
glPopName ( ) ;
glPopName ( ) ;
}
}
glPopMatrix ( ) ;
}
2010-09-10 10:51:32 +02:00
void Renderer : : renderQuad ( int x , int y , int w , int h , const Texture2D * texture ) {
2010-11-01 17:44:05 +01:00
if ( w < 0 ) {
2010-11-09 10:06:52 +01:00
w = texture - > getPixmapConst ( ) - > getW ( ) ;
2010-11-01 17:44:05 +01:00
}
if ( h < 0 ) {
2010-11-09 10:06:52 +01:00
h = texture - > getPixmapConst ( ) - > getH ( ) ;
2010-11-01 17:44:05 +01:00
}
2010-03-13 22:10:45 +01:00
glBindTexture ( GL_TEXTURE_2D , static_cast < const Texture2DGl * > ( texture ) - > getHandle ( ) ) ;
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 :
return " Disabled " ;
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 ;
}
throw runtime_error ( " Error converting from string to FilterType, found: " + s ) ;
}
2010-05-29 09:07:46 +02:00
void Renderer : : setAllowRenderUnitTitles ( bool value ) {
allowRenderUnitTitles = value ;
2010-11-02 20:52:20 +01:00
//if(allowRenderUnitTitles == false) {
//renderUnitTitleList.clear();
//}
2010-05-29 09:07:46 +02:00
}
2010-05-29 07:41:40 +02:00
// This method renders titles for units
void Renderer : : renderUnitTitles ( Font2D * font , Vec3f color ) {
2010-09-01 01:14:15 +02:00
std : : map < int , bool > unitRenderedList ;
if ( visibleFrameUnitList . size ( ) > 0 ) {
for ( int idx = 0 ; idx < visibleFrameUnitList . size ( ) ; idx + + ) {
const Unit * unit = visibleFrameUnitList [ idx ] ;
if ( unit ! = NULL & & unit - > getCurrentUnitTitle ( ) ! = " " ) {
//get the screen coordinates
Vec3f screenPos = unit - > getScreenPos ( ) ;
renderText ( unit - > getCurrentUnitTitle ( ) , font , color , fabs ( screenPos . x ) + 5 , fabs ( screenPos . y ) + 5 , false ) ;
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] screenPos.x = %f, screenPos.y = %f, screenPos.z = %f\n",__FILE__,__FUNCTION__,__LINE__,screenPos.x,screenPos.y,screenPos.z);
unitRenderedList [ unit - > getId ( ) ] = true ;
}
2010-11-02 20:52:20 +01:00
else {
string str = unit - > getFullName ( ) + " - " + intToStr ( unit - > getId ( ) ) ;
Vec3f screenPos = unit - > getScreenPos ( ) ;
renderText ( str , font , color , fabs ( screenPos . x ) + 5 , fabs ( screenPos . y ) + 5 , false ) ;
}
2010-09-01 01:14:15 +02:00
}
visibleFrameUnitList . clear ( ) ;
}
2010-11-02 20:52:20 +01:00
/*
2010-05-29 07:41:40 +02:00
if ( renderUnitTitleList . size ( ) > 0 ) {
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 ) ;
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] screenPos.x = %f, screenPos.y = %f, screenPos.z = %f\n",__FILE__,__FUNCTION__,__LINE__,screenPos.x,screenPos.y,screenPos.z);
}
}
renderUnitTitleList . clear ( ) ;
}
2010-11-02 20:52:20 +01:00
*/
2010-05-29 07:41:40 +02:00
}
2010-09-10 17:47:19 +02:00
void Renderer : : setQuadCacheDirty ( bool value ) {
quadCache . cacheIsDirty = value ;
}
2010-09-10 21:44:00 +02:00
void Renderer : : removeObjectFromQuadCache ( const Object * o ) {
VisibleQuadContainerCache & qCache = getQuadCache ( ) ;
for ( int visibleIndex = 0 ;
visibleIndex < qCache . visibleObjectList . size ( ) ; + + visibleIndex ) {
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 ;
visibleIndex < qCache . visibleQuadUnitList . size ( ) ; + + visibleIndex ) {
Unit * currentUnit = qCache . visibleQuadUnitList [ visibleIndex ] ;
if ( currentUnit = = unit ) {
qCache . visibleQuadUnitList . erase ( qCache . visibleQuadUnitList . begin ( ) + visibleIndex ) ;
break ;
}
}
for ( int visibleIndex = 0 ;
visibleIndex < qCache . visibleUnitList . size ( ) ; + + visibleIndex ) {
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
2010-09-10 17:47:19 +02:00
if ( quadCache . cacheIsDirty = = true ) {
forceNew = true ;
}
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 ( ) ;
//}
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
bool insideQuad = visibleQuad . isInside ( unit - > getPos ( ) ) ;
bool renderInMap = world - > toRenderUnit ( unit ) ;
if ( insideQuad = = true & & renderInMap = = true ) {
2010-09-10 10:51:32 +02:00
quadCache . visibleQuadUnitList . push_back ( unit ) ;
2010-09-10 02:28:14 +02:00
}
else {
unit - > setVisible ( false ) ;
2010-09-10 10:51:32 +02:00
// Currently don't need this list
//quadCache.inVisibleUnitList.push_back(unit);
}
2010-09-10 11:09:12 +02:00
if ( renderInMap = = true ) {
2010-09-10 10:51:32 +02:00
quadCache . visibleUnitList . push_back ( unit ) ;
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 ( ) ;
2010-09-10 10:51:32 +02:00
quadCache . clearNonVolatileCacheData ( ) ;
PosQuadIterator pqi ( visibleQuad , Map : : cellScale ) ;
while ( pqi . next ( ) ) {
2010-09-10 02:41:51 +02:00
const Vec2i & pos = pqi . getPos ( ) ;
if ( map - > isInside ( pos ) ) {
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
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 ) ;
}
2010-09-10 02:28:14 +02:00
}
}
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 ;
2010-09-10 10:51:32 +02:00
PosQuadIterator pqis ( 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 ) ) {
2010-09-10 02:41:51 +02:00
quadCache . visibleScaledCellList . push_back ( pos ) ;
}
2010-09-10 02:28:14 +02:00
}
2010-09-10 02:41:51 +02:00
}
2010-09-10 02:28:14 +02:00
quadCache . cacheFrame = world - > getFrameCount ( ) ;
2010-09-10 17:47:19 +02:00
quadCache . cacheIsDirty = false ;
2010-09-10 10:51:32 +02:00
quadCache . lastVisibleQuad = visibleQuad ;
2010-09-10 02:28:14 +02:00
}
}
return quadCache ;
}
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 ) {
2010-12-05 02:33:28 +01:00
2011-02-08 06:54:05 +01:00
static bool supportFBOs = Texture2DGl ( ) . supports_FBO_RBO ( ) ;
//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 ( ) ;
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
if ( supportFBOs = = true & & renderToTexture ! = NULL ) {
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-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-02-08 06:54:05 +01:00
if ( supportFBOs = = true & & renderToTexture ! = NULL ) {
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-02-08 06:54:05 +01:00
if ( supportFBOs = = false | | renderToTexture = = NULL ) {
glTranslatef ( static_cast < float > ( screenPosX ) , static_cast < float > ( screenPosY ) - clientH , 0.0f ) ;
}
2010-11-01 17:44:05 +01:00
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-02-08 06:54:05 +01:00
if ( supportFBOs = = true & & renderToTexture ! = NULL ) {
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
for ( int i = 0 ; i < map - > getMaxFactions ( ) ; i + + ) {
switch ( i ) {
2011-02-08 06:54:05 +01:00
case 0 :
glColor3f ( 1.f , 0.f , 0.f ) ;
break ;
case 1 :
glColor3f ( 0.f , 0.f , 1.f ) ;
break ;
case 2 :
glColor3f ( 0.f , 1.f , 0.f ) ;
break ;
case 3 :
glColor3f ( 1.f , 1.f , 0.f ) ;
break ;
case 4 :
glColor3f ( 1.f , 1.f , 1.f ) ;
break ;
case 5 :
glColor3f ( 0.f , 1.f , 0.8f ) ;
break ;
case 6 :
glColor3f ( 1.f , 0.5f , 0.f ) ;
break ;
case 7 :
glColor3f ( 1.f , 0.5f , 1.f ) ;
break ;
2010-09-16 01:49:26 +02:00
}
glBegin ( GL_LINES ) ;
glVertex2f ( ( map - > getStartLocationX ( i ) - 1 ) * cellSize , clientH - ( map - > getStartLocationY ( i ) - 1 ) * cellSize ) ;
glVertex2f ( ( map - > getStartLocationX ( i ) + 1 ) * cellSize + playerCrossSize , clientH - ( map - > getStartLocationY ( i ) + 1 ) * cellSize - playerCrossSize ) ;
glVertex2f ( ( map - > getStartLocationX ( i ) - 1 ) * cellSize , clientH - ( map - > getStartLocationY ( i ) + 1 ) * cellSize - playerCrossSize ) ;
glVertex2f ( ( map - > getStartLocationX ( i ) + 1 ) * cellSize + playerCrossSize , clientH - ( map - > getStartLocationY ( i ) - 1 ) * cellSize ) ;
glEnd ( ) ;
}
glPopMatrix ( ) ;
glPopAttrib ( ) ;
glMatrixMode ( GL_PROJECTION ) ;
glPopMatrix ( ) ;
2011-02-08 06:54:05 +01:00
if ( supportFBOs = = true & & 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 ] ) ;
2010-11-01 17:44:05 +01:00
}
2011-02-08 06:54:05 +01:00
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 ;
}
}
2010-10-28 23:06:20 +02:00
uint64 Renderer : : getCurrentPixelByteCount ( ResourceScope rs ) const {
uint64 result = 0 ;
for ( int i = ( rs = = rsCount ? 0 : rs ) ; i < rsCount ; + + i ) {
const Shared : : Graphics : : TextureContainer & textures = textureManager [ i ] - > getTextures ( ) ;
for ( int j = 0 ; j < textures . size ( ) ; + + j ) {
const Texture * texture = textures [ j ] ;
result + = texture - > getPixelByteCount ( ) ;
}
if ( rs ! = rsCount ) {
break ;
}
}
return result ;
}
2010-09-16 01:49:26 +02:00
2011-01-26 10:09:59 +01:00
Texture2D * Renderer : : findFactionLogoTexture ( string logoFilename ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] logoFilename [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , logoFilename . c_str ( ) ) ;
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 ( ) ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] logoFilename [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , logoFilename . c_str ( ) ) ;
result = crcFactionPreviewTextureCache [ logoFilename ] ;
}
else {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] logoFilename [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , logoFilename . c_str ( ) ) ;
Renderer & renderer = Renderer : : getInstance ( ) ;
result = renderer . newTexture2D ( rsGlobal ) ;
result - > setMipmap ( true ) ;
result - > load ( logoFilename ) ;
renderer . initTexture ( rsGlobal , result ) ;
crcFactionPreviewTextureCache [ logoFilename ] = result ;
}
}
return result ;
}
2011-02-06 08:01:54 +01:00
void Renderer : : cycleShowDebugUILevel ( ) {
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-01-26 10:09:59 +01:00
2010-03-13 22:10:45 +01:00
} } //end namespace