2011-12-14 07:40:48 +00:00
// ==============================================================
// This file is part of MegaGlest (www.glest.org)
//
// Copyright (C) 2011 - by Mark Vejvoda <mark_vejvoda@hotmail.com>
//
// 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
// ==============================================================
2010-03-13 10:39:22 +00:00
# include "renderer.h"
# include "graphics_factory_gl.h"
# include "graphics_interface.h"
2012-08-10 07:10:47 +00:00
# include "config.h"
2011-03-13 22:43:44 +00:00
//#include <png.h>
2011-01-21 16:34:33 +00:00
# include <memory>
2010-03-13 10:39:22 +00:00
using namespace Shared : : Graphics ;
using namespace Shared : : Graphics : : Gl ;
2012-08-10 07:10:47 +00:00
using namespace Glest : : Game ;
using namespace Shared : : Util ;
2010-03-13 10:39:22 +00:00
namespace Shared { namespace G3dViewer {
2012-01-06 21:02:23 +00:00
int Renderer : : windowX = 100 ;
int Renderer : : windowY = 100 ;
2012-01-06 19:34:47 +00:00
int Renderer : : windowW = 640 ;
int Renderer : : windowH = 480 ;
2010-03-13 10:39:22 +00:00
// ===============================================
// class MeshCallbackTeamColor
// ===============================================
void MeshCallbackTeamColor : : execute ( const Mesh * mesh ) {
//team color
if ( mesh - > getCustomTexture ( ) & & teamTexture ! = NULL ) {
//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 ) ;
}
else {
glActiveTexture ( GL_TEXTURE1 ) ;
glDisable ( GL_TEXTURE_2D ) ;
glActiveTexture ( GL_TEXTURE0 ) ;
glTexEnvi ( GL_TEXTURE_ENV , GL_TEXTURE_ENV_MODE , GL_MODULATE ) ;
}
}
// ===============================================
// class Renderer
// ===============================================
2011-01-20 18:05:07 +00:00
Renderer : : Renderer ( ) {
2010-03-13 10:39:22 +00:00
normals = false ;
wireframe = false ;
grid = true ;
modelRenderer = NULL ;
textureManager = NULL ;
2010-05-25 18:06:42 +00:00
particleRenderer = NULL ;
2010-06-24 10:52:58 +00:00
modelManager = NULL ;
2011-01-20 18:05:07 +00:00
width = 0 ;
height = 0 ;
red = 0.3f ;
green = 0.3f ;
blue = 0.3f ;
alpha = 1.0f ;
2012-09-22 20:13:57 +00:00
customTextureRed = NULL ;
customTextureBlue = NULL ;
customTextureGreen = NULL ;
customTextureYellow = NULL ;
customTextureWhite = NULL ;
customTextureCyan = NULL ;
customTextureOrange = NULL ;
customTextureMagenta = NULL ;
particleManager = NULL ;
2010-03-13 10:39:22 +00:00
}
2011-01-20 18:05:07 +00:00
Renderer : : ~ Renderer ( ) {
2010-03-13 10:39:22 +00:00
delete modelRenderer ;
delete textureManager ;
2010-05-25 18:06:42 +00:00
delete particleRenderer ;
//resources
delete particleManager ;
2010-06-24 10:52:58 +00:00
delete modelManager ;
2012-07-21 20:21:27 +00:00
if ( GraphicsInterface : : getInstance ( ) . getFactory ( ) ! = NULL ) {
delete GraphicsInterface : : getInstance ( ) . getFactory ( ) ;
GraphicsInterface : : getInstance ( ) . setFactory ( NULL ) ;
}
2010-03-13 10:39:22 +00:00
}
2011-01-20 18:05:07 +00:00
Renderer * Renderer : : getInstance ( ) {
2010-03-13 10:39:22 +00:00
static Renderer * renderer = new Renderer ( ) ;
return renderer ;
}
2011-01-20 18:05:07 +00:00
void Renderer : : transform ( float rotX , float rotY , float zoom ) {
2010-03-13 10:39:22 +00:00
assertGl ( ) ;
glMatrixMode ( GL_MODELVIEW ) ;
glRotatef ( rotY , 1.0f , 0.0f , 0.0f ) ;
glRotatef ( rotX , 0.0f , 1.0f , 0.0f ) ;
glScalef ( zoom , zoom , zoom ) ;
Vec4f pos ( - 8.0f , 5.0f , 10.0f , 0.0f ) ;
glLightfv ( GL_LIGHT0 , GL_POSITION , pos . ptr ( ) ) ;
assertGl ( ) ;
}
2011-01-20 18:05:07 +00:00
void Renderer : : checkGlCaps ( ) {
2012-08-10 07:10:47 +00:00
if ( glActiveTexture = = NULL ) {
string message ;
message + = " Your system supports OpenGL version \" " ;
message + = getGlVersion ( ) + string ( " \" \n " ) ;
message + = " MegaGlest needs a version that supports \n " ;
message + = " glActiveTexture (OpenGL 1.3) or the ARB_multitexture extension. " ;
throw megaglest_runtime_error ( message . c_str ( ) ) ;
}
2010-03-13 10:39:22 +00:00
//opengl 1.3
2011-12-06 01:34:51 +00:00
//if(!isGlVersionSupported(1, 3, 0)) {
if ( glewIsSupported ( " GL_VERSION_1_3 " ) = = false ) {
2010-03-13 10:39:22 +00:00
string message ;
message + = " Your system supports OpenGL version \" " ;
message + = getGlVersion ( ) + string ( " \" \n " ) ;
2010-12-13 00:32:59 +00:00
message + = " MegaGlest needs at least version 1.3 to work \n " ;
2010-03-13 10:39:22 +00:00
message + = " You may solve this problem by installing your latest video card drivers " ;
2012-04-14 21:21:09 +00:00
throw megaglest_runtime_error ( message . c_str ( ) ) ;
2010-03-13 10:39:22 +00:00
}
//opengl 1.4 or extension
2011-12-06 01:34:51 +00:00
//if(isGlVersionSupported(1, 4, 0) == false) {
if ( glewIsSupported ( " GL_VERSION_1_4 " ) = = false ) {
2010-12-13 00:32:59 +00:00
checkExtension ( " GL_ARB_texture_env_crossbar " , " MegaGlest " ) ;
2010-03-13 10:39:22 +00:00
}
}
2011-01-20 18:05:07 +00:00
void Renderer : : checkExtension ( const string & extension , const string & msg ) {
if ( isGlExtensionSupported ( extension . c_str ( ) ) = = false ) {
2010-03-13 10:39:22 +00:00
string str = " OpenGL extension not supported: " + extension + " , required for " + msg ;
2012-04-14 21:21:09 +00:00
throw megaglest_runtime_error ( str ) ;
2010-03-13 10:39:22 +00:00
}
}
2010-05-25 18:06:42 +00:00
Texture2D * Renderer : : getNewTexture2D ( ) {
Texture2D * newTexture = textureManager - > newTexture2D ( ) ;
return newTexture ;
}
2010-06-24 10:52:58 +00:00
Model * Renderer : : getNewModel ( ) {
Model * newModel = modelManager - > newModel ( ) ;
return newModel ;
}
2011-01-20 18:05:07 +00:00
void Renderer : : init ( ) {
assertGl ( ) ;
2010-03-13 10:39:22 +00:00
2012-07-21 20:21:27 +00:00
GraphicsFactory * gf = GraphicsInterface : : getInstance ( ) . getFactory ( ) ;
if ( gf = = NULL ) {
gf = new GraphicsFactoryGl ( ) ;
GraphicsInterface : : getInstance ( ) . setFactory ( gf ) ;
}
2010-03-13 10:39:22 +00:00
2012-08-10 07:10:47 +00:00
Config & config = Config : : getInstance ( ) ;
if ( config . getBool ( " CheckGlCaps " ) ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
checkGlCaps ( ) ;
}
if ( glActiveTexture = = NULL ) {
char szBuf [ 8096 ] = " " ;
2012-10-19 01:31:20 +00:00
snprintf ( szBuf , 8096 , " Error: glActiveTexture == NULL \n glActiveTexture is only supported if the GL version is 1.3 or greater, \n or if the ARB_multitexture extension is supported! " ) ;
2012-08-10 07:10:47 +00:00
throw megaglest_runtime_error ( szBuf ) ;
}
2010-03-13 10:39:22 +00:00
modelRenderer = gf - > newModelRenderer ( ) ;
textureManager = gf - > newTextureManager ( ) ;
2010-05-25 18:06:42 +00:00
particleRenderer = gf - > newParticleRenderer ( ) ;
//resources
particleManager = gf - > newParticleManager ( ) ;
2010-03-13 10:39:22 +00:00
2010-06-24 10:52:58 +00:00
modelManager = gf - > newModelManager ( ) ;
modelManager - > setTextureManager ( textureManager ) ;
2010-03-13 10:39:22 +00:00
//red tex
customTextureRed = textureManager - > newTexture2D ( ) ;
customTextureRed - > getPixmap ( ) - > init ( 1 , 1 , 3 ) ;
customTextureRed - > getPixmap ( ) - > setPixel ( 0 , 0 , Vec3f ( 1.f , 0.f , 0.f ) ) ;
//blue tex
customTextureBlue = textureManager - > newTexture2D ( ) ;
customTextureBlue - > getPixmap ( ) - > init ( 1 , 1 , 3 ) ;
customTextureBlue - > getPixmap ( ) - > setPixel ( 0 , 0 , Vec3f ( 0.f , 0.f , 1.f ) ) ;
2010-11-03 19:03:25 +00:00
//green tex
customTextureGreen = textureManager - > newTexture2D ( ) ;
customTextureGreen - > getPixmap ( ) - > init ( 1 , 1 , 3 ) ;
customTextureGreen - > getPixmap ( ) - > setPixel ( 0 , 0 , Vec3f ( 0.f , 0.5f , 0.f ) ) ;
2010-03-13 10:39:22 +00:00
//yellow tex
customTextureYellow = textureManager - > newTexture2D ( ) ;
customTextureYellow - > getPixmap ( ) - > init ( 1 , 1 , 3 ) ;
customTextureYellow - > getPixmap ( ) - > setPixel ( 0 , 0 , Vec3f ( 1.f , 1.f , 0.f ) ) ;
2010-12-03 05:07:42 +00:00
//white tex
2010-11-03 19:03:25 +00:00
customTextureWhite = textureManager - > newTexture2D ( ) ;
customTextureWhite - > getPixmap ( ) - > init ( 1 , 1 , 3 ) ;
customTextureWhite - > getPixmap ( ) - > setPixel ( 0 , 0 , Vec3f ( 1.f , 1.f , 1.f ) ) ;
//cyan tex
customTextureCyan = textureManager - > newTexture2D ( ) ;
customTextureCyan - > getPixmap ( ) - > init ( 1 , 1 , 3 ) ;
customTextureCyan - > getPixmap ( ) - > setPixel ( 0 , 0 , Vec3f ( 0.f , 1.f , 0.8f ) ) ;
//orange tex
customTextureOrange = textureManager - > newTexture2D ( ) ;
customTextureOrange - > getPixmap ( ) - > init ( 1 , 1 , 3 ) ;
customTextureOrange - > getPixmap ( ) - > setPixel ( 0 , 0 , Vec3f ( 1.f , 0.5f , 0.f ) ) ;
//magenta tex
customTextureMagenta = textureManager - > newTexture2D ( ) ;
customTextureMagenta - > getPixmap ( ) - > init ( 1 , 1 , 3 ) ;
customTextureMagenta - > getPixmap ( ) - > setPixel ( 0 , 0 , Vec3f ( 1.f , 0.5f , 1.f ) ) ;
2010-03-13 10:39:22 +00:00
2011-01-20 18:05:07 +00:00
glClearColor ( red , green , blue , alpha ) ; //backgroundcolor constant 0.3
2011-01-28 05:49:52 +00:00
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2011-01-21 16:34:33 +00:00
/* once the GL context is valid : */
2011-01-28 05:49:52 +00:00
//GLint alpha_bits;
//glGetIntegerv(GL_ALPHA_BITS, &alpha_bits);
2011-01-21 16:34:33 +00:00
//printf("#1 The framebuffer uses %d bit(s) per the alpha component\n", alpha_bits);
2010-03-13 10:39:22 +00:00
glEnable ( GL_TEXTURE_2D ) ;
glFrontFace ( GL_CW ) ;
glEnable ( GL_CULL_FACE ) ;
glEnable ( GL_DEPTH_TEST ) ;
glEnable ( GL_ALPHA_TEST ) ;
2011-01-28 05:49:52 +00:00
//glAlphaFunc(GL_GREATER, 0.5f);
glAlphaFunc ( GL_GREATER , 0.0f ) ;
2010-03-13 10:39:22 +00:00
glEnable ( GL_LIGHTING ) ;
glEnable ( GL_LIGHT0 ) ;
Vec4f diffuse = Vec4f ( 1.0f , 1.0f , 1.0f , 1.0f ) ;
Vec4f ambient = Vec4f ( 0.3f , 0.3f , 0.3f , 1.0f ) ;
Vec4f specular = Vec4f ( 0.1f , 0.1f , 0.1f , 1.0f ) ;
glLightfv ( GL_LIGHT0 , GL_AMBIENT , ambient . ptr ( ) ) ;
glLightfv ( GL_LIGHT0 , GL_DIFFUSE , diffuse . ptr ( ) ) ;
glLightfv ( GL_LIGHT0 , GL_SPECULAR , specular . ptr ( ) ) ;
glColorMaterial ( GL_FRONT_AND_BACK , GL_AMBIENT_AND_DIFFUSE ) ;
glEnable ( GL_COLOR_MATERIAL ) ;
assertGl ( ) ;
}
2011-01-20 18:05:07 +00:00
void Renderer : : reset ( int w , int h , PlayerColor playerColor ) {
2010-03-13 10:39:22 +00:00
assertGl ( ) ;
2011-01-20 18:05:07 +00:00
width = w ;
height = h ;
2011-01-28 05:49:52 +00:00
//glClearColor(red, green, blue, alpha); //backgroundcolor constant 0.3
2011-01-21 16:34:33 +00:00
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ;
/* once the GL context is valid : */
2011-01-28 05:49:52 +00:00
//GLint alpha_bits;
//glGetIntegerv(GL_ALPHA_BITS, &alpha_bits);
2011-01-21 16:34:33 +00:00
//printf("#2 The framebuffer uses %d bit(s) per the alpha component\n", alpha_bits);
2010-03-13 10:39:22 +00:00
glViewport ( 0 , 0 , w , h ) ;
glMatrixMode ( GL_PROJECTION ) ;
glLoadIdentity ( ) ;
gluPerspective ( 60.0f , static_cast < float > ( w ) / h , 1.0f , 200.0f ) ;
glMatrixMode ( GL_MODELVIEW ) ;
glLoadIdentity ( ) ;
glTranslatef ( 0 , - 1.5 , - 5 ) ;
2013-02-04 08:30:43 +00:00
Texture2D * customTexture = NULL ;
2011-01-20 18:05:07 +00:00
switch ( playerColor ) {
2010-03-13 10:39:22 +00:00
case pcRed :
customTexture = customTextureRed ;
break ;
case pcBlue :
customTexture = customTextureBlue ;
break ;
2010-11-03 19:03:25 +00:00
case pcGreen :
customTexture = customTextureGreen ;
break ;
2010-03-13 10:39:22 +00:00
case pcYellow :
customTexture = customTextureYellow ;
break ;
2010-11-03 19:03:25 +00:00
case pcWhite :
customTexture = customTextureWhite ;
break ;
case pcCyan :
customTexture = customTextureCyan ;
break ;
case pcOrange :
customTexture = customTextureOrange ;
break ;
case pcMagenta :
customTexture = customTextureMagenta ;
2010-03-13 10:39:22 +00:00
break ;
default :
assert ( false ) ;
2012-09-22 20:13:57 +00:00
break ;
2010-03-13 10:39:22 +00:00
}
meshCallbackTeamColor . setTeamTexture ( customTexture ) ;
2011-01-20 18:05:07 +00:00
if ( wireframe ) {
2010-03-13 10:39:22 +00:00
glPolygonMode ( GL_FRONT_AND_BACK , GL_LINE ) ;
glDisable ( GL_TEXTURE_2D ) ;
glDisable ( GL_LIGHTING ) ;
glDisable ( GL_LIGHT0 ) ;
}
2011-01-20 18:05:07 +00:00
else {
2010-03-13 10:39:22 +00:00
glEnable ( GL_TEXTURE_2D ) ;
glEnable ( GL_LIGHTING ) ;
glEnable ( GL_LIGHT0 ) ;
glPolygonMode ( GL_FRONT_AND_BACK , GL_FILL ) ;
}
assertGl ( ) ;
}
2011-01-20 18:05:07 +00:00
void Renderer : : renderGrid ( ) {
if ( grid ) {
float i = 0 ;
2010-03-13 10:39:22 +00:00
assertGl ( ) ;
glPushAttrib ( GL_ENABLE_BIT ) ;
glDisable ( GL_TEXTURE_2D ) ;
glDisable ( GL_LIGHTING ) ;
glBegin ( GL_LINES ) ;
2010-12-03 05:07:42 +00:00
glColor3f ( 1.0f , 1.0f , 1.0f ) ; // gridcolor constant
2011-01-20 18:05:07 +00:00
for ( i = - 10.0f ; i < = 10.0f ; i + = 1.0f ) {
2010-03-13 10:39:22 +00:00
glVertex3f ( i , 0.0f , 10.0f ) ;
glVertex3f ( i , 0.0f , - 10.0f ) ;
}
2011-01-20 18:05:07 +00:00
for ( i = - 10.0f ; i < = 10.0f ; i + = 1.0f ) {
2010-03-13 10:39:22 +00:00
glVertex3f ( 10.f , 0.0f , i ) ;
glVertex3f ( - 10.f , 0.0f , i ) ;
}
glEnd ( ) ;
glPopAttrib ( ) ;
assertGl ( ) ;
}
}
2011-01-20 18:05:07 +00:00
void Renderer : : toggleNormals ( ) {
2010-03-13 10:39:22 +00:00
normals = normals ? false : true ;
}
2011-01-20 18:05:07 +00:00
void Renderer : : toggleWireframe ( ) {
2010-03-13 10:39:22 +00:00
wireframe = wireframe ? false : true ;
}
2011-01-20 18:05:07 +00:00
void Renderer : : toggleGrid ( ) {
2010-03-13 10:39:22 +00:00
grid = grid ? false : true ;
}
2011-01-20 18:05:07 +00:00
void Renderer : : loadTheModel ( Model * model , string file ) {
2010-03-13 10:39:22 +00:00
model - > setTextureManager ( textureManager ) ;
model - > loadG3d ( file ) ;
textureManager - > init ( ) ;
2010-06-24 10:52:58 +00:00
modelManager - > init ( ) ;
2010-03-13 10:39:22 +00:00
}
2011-01-20 18:05:07 +00:00
void Renderer : : renderTheModel ( Model * model , float f ) {
2010-03-13 10:39:22 +00:00
if ( model ! = NULL ) {
2013-01-25 15:23:45 +00:00
modelRenderer - > begin ( true , true , ! wireframe , false , & meshCallbackTeamColor ) ;
2010-03-13 10:39:22 +00:00
model - > updateInterpolationData ( f , true ) ;
modelRenderer - > render ( model ) ;
2011-01-20 18:05:07 +00:00
if ( normals ) {
2010-03-13 10:39:22 +00:00
glPushAttrib ( GL_ENABLE_BIT ) ;
glDisable ( GL_LIGHTING ) ;
glDisable ( GL_TEXTURE_2D ) ;
2010-12-03 05:07:42 +00:00
glColor3f ( 1.0f , 1.0f , 1.0f ) ; //normalscolor constant
2010-03-13 10:39:22 +00:00
modelRenderer - > renderNormalsOnly ( model ) ;
glPopAttrib ( ) ;
}
modelRenderer - > end ( ) ;
}
}
2011-01-20 18:05:07 +00:00
void Renderer : : manageParticleSystem ( ParticleSystem * particleSystem ) {
2010-05-25 18:06:42 +00:00
particleManager - > manage ( particleSystem ) ;
}
2011-01-20 18:05:07 +00:00
void Renderer : : updateParticleManager ( ) {
2010-05-25 18:06:42 +00:00
particleManager - > update ( ) ;
}
2011-01-29 03:53:05 +00:00
bool Renderer : : hasActiveParticleSystem ( ParticleSystem : : ParticleSystemType type ) const {
return particleManager - > hasActiveParticleSystem ( type ) ;
}
2011-01-20 18:05:07 +00:00
void Renderer : : renderParticleManager ( ) {
2010-05-25 18:06:42 +00:00
glPushAttrib ( GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ) ;
glDepthFunc ( GL_LESS ) ;
particleRenderer - > renderManager ( particleManager , modelRenderer ) ;
glPopAttrib ( ) ;
}
Texture2D * Renderer : : getPlayerColorTexture ( PlayerColor playerColor ) {
2013-02-04 08:30:43 +00:00
Texture2D * customTexture = NULL ;
2010-05-25 18:06:42 +00:00
switch ( playerColor ) {
case pcRed :
customTexture = customTextureRed ;
break ;
case pcBlue :
customTexture = customTextureBlue ;
break ;
2010-11-03 19:03:25 +00:00
case pcGreen :
customTexture = customTextureGreen ;
break ;
2010-05-25 18:06:42 +00:00
case pcYellow :
customTexture = customTextureYellow ;
break ;
2010-11-03 19:03:25 +00:00
case pcWhite :
customTexture = customTextureWhite ;
break ;
case pcCyan :
customTexture = customTextureCyan ;
break ;
case pcOrange :
customTexture = customTextureOrange ;
break ;
case pcMagenta :
customTexture = customTextureMagenta ;
2010-05-25 18:06:42 +00:00
break ;
default :
2013-06-23 04:17:25 +00:00
throw megaglest_runtime_error ( " Unknown playercolor: " + intToStr ( playerColor ) ) ;
2012-09-22 20:13:57 +00:00
break ;
2010-05-25 18:06:42 +00:00
}
return customTexture ;
}
void Renderer : : initTextureManager ( ) {
textureManager - > init ( ) ;
}
2010-06-24 10:52:58 +00:00
void Renderer : : initModelManager ( ) {
modelManager - > init ( ) ;
}
2010-05-25 18:06:42 +00:00
void Renderer : : end ( ) {
//delete resources
//textureManager->end();
particleManager - > end ( ) ;
2010-06-24 10:52:58 +00:00
modelManager - > end ( ) ;
2010-05-25 18:06:42 +00:00
}
2011-01-21 16:34:33 +00:00
void Renderer : : setBackgroundColor ( float red , float green , float blue ) {
this - > red = red ;
this - > green = green ;
this - > blue = blue ;
glClearColor ( red , green , blue , alpha ) ; //backgroundcolor constant 0.3
2011-01-28 05:49:52 +00:00
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2011-01-21 16:34:33 +00:00
/* once the GL context is valid : */
2011-01-28 05:49:52 +00:00
//GLint alpha_bits;
//glGetIntegerv(GL_ALPHA_BITS, &alpha_bits);
2011-01-21 16:34:33 +00:00
//printf("#3 The framebuffer uses %d bit(s) per the alpha component\n", alpha_bits);
}
void Renderer : : setAlphaColor ( float alpha ) {
this - > alpha = alpha ;
glClearColor ( red , green , blue , alpha ) ; //backgroundcolor constant 0.3
2011-01-28 05:49:52 +00:00
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2011-01-21 16:34:33 +00:00
/* once the GL context is valid : */
2011-01-28 05:49:52 +00:00
//GLint alpha_bits;
//glGetIntegerv(GL_ALPHA_BITS, &alpha_bits);
2011-01-21 16:34:33 +00:00
//printf("#3.1 The framebuffer uses %d bit(s) per the alpha component\n", alpha_bits);
}
2012-01-06 18:49:33 +00:00
void Renderer : : saveScreen ( const string & path , std : : pair < int , int > * overrideSize ) {
2011-01-21 16:34:33 +00:00
Pixmap2D * pixmapScreenShot = new Pixmap2D ( width , height , 4 ) ;
2012-01-04 21:43:34 +00:00
//glFinish();
2011-05-16 13:14:54 +00:00
glPixelStorei ( GL_PACK_ALIGNMENT , 1 ) ;
2012-01-04 21:43:34 +00:00
glReadPixels ( 0 , 0 , pixmapScreenShot - > getW ( ) , pixmapScreenShot - > getH ( ) ,
GL_RGBA , GL_UNSIGNED_BYTE , pixmapScreenShot - > getPixels ( ) ) ;
2011-01-20 18:05:07 +00:00
2011-05-16 13:14:54 +00:00
glPixelStorei ( GL_UNPACK_ALIGNMENT , 1 ) ;
2012-01-06 19:34:47 +00:00
//if(overrideSize != NULL && overrideSize->first > 0 && overrideSize->second > 0) {
// pixmapScreenShot->Scale(GL_RGBA,overrideSize->first,overrideSize->second);
//}
2012-01-06 18:49:33 +00:00
2011-01-20 18:05:07 +00:00
pixmapScreenShot - > save ( path ) ;
delete pixmapScreenShot ;
}
2010-03-13 10:39:22 +00:00
} } //end namespace