summaryrefslogtreecommitdiffstats
path: root/src/graphics
diff options
context:
space:
mode:
authorPiotr Dziwinski <piotrdz@gmail.com>2012-09-29 22:44:05 +0200
committerPiotr Dziwinski <piotrdz@gmail.com>2012-09-29 22:44:05 +0200
commit4193f8a3a9f10b563c8fada163c3a6d3860f3457 (patch)
tree65615c8f5b4b7e3efee3b0b2c9f77b3ffef23175 /src/graphics
parent5a751d9c0da79b38d4104bbe0cc1b5feec3d6ecc (diff)
downloadcolobot-4193f8a3a9f10b563c8fada163c3a6d3860f3457.tar.gz
colobot-4193f8a3a9f10b563c8fada163c3a6d3860f3457.tar.bz2
colobot-4193f8a3a9f10b563c8fada163c3a6d3860f3457.zip
Fix for transparent objects and fadeouts
Diffstat (limited to 'src/graphics')
-rw-r--r--src/graphics/core/device.h5
-rw-r--r--src/graphics/core/texture.h4
-rw-r--r--src/graphics/engine/engine.cpp33
-rw-r--r--src/graphics/engine/engine.h2
-rw-r--r--src/graphics/opengl/gldevice.cpp23
-rw-r--r--src/graphics/opengl/gldevice.h3
6 files changed, 11 insertions, 59 deletions
diff --git a/src/graphics/core/device.h b/src/graphics/core/device.h
index 0d76644..0777396 100644
--- a/src/graphics/core/device.h
+++ b/src/graphics/core/device.h
@@ -307,11 +307,6 @@ public:
//! Sets only the texture wrap modes (for faster than thru stage params)
virtual void SetTextureStageWrap(int index, TexWrapMode wrapS, TexWrapMode wrapT) = 0;
- //! Sets the texture factor to the given color value
- virtual void SetTextureFactor(const Color &color) = 0;
- //! Returns the current texture factor
- virtual Color GetTextureFactor() = 0;
-
//! Renders primitive composed of vertices with single texture
virtual void DrawPrimitive(PrimitiveType type, const Vertex *vertices , int vertexCount) = 0;
//! Renders primitive composed of vertices with color information and single texture
diff --git a/src/graphics/core/texture.h b/src/graphics/core/texture.h
index 3ebbee5..49b29f8 100644
--- a/src/graphics/core/texture.h
+++ b/src/graphics/core/texture.h
@@ -22,6 +22,8 @@
#pragma once
+#include "graphics/core/color.h"
+
#include "math/intpoint.h"
@@ -175,6 +177,8 @@ struct TextureStageParams
TexWrapMode wrapS;
//! Wrap mode for 2nd tex coord
TexWrapMode wrapT;
+ //! Constant color factor (for TEX_MIX_ARG_FACTOR)
+ Color factor;
//! Constructor; calls LoadDefault()
TextureStageParams()
diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp
index c094c63..c748605 100644
--- a/src/graphics/engine/engine.cpp
+++ b/src/graphics/engine/engine.cpp
@@ -181,9 +181,6 @@ CEngine::CEngine(CInstanceManager *iMan, CApplication *app)
m_alphaMode = 1;
- m_forceStateColor = true;
- m_stateColor = false;
-
m_updateGeometry = false;
m_interfaceMode = false;
@@ -1851,13 +1848,12 @@ void CEngine::SetState(int state, const Color& color)
m_device->SetRenderState(RENDER_STATE_BLENDING, true);
m_device->SetBlendFunc(BLEND_ONE, BLEND_INV_SRC_COLOR);
- m_device->SetTextureFactor(color);
-
TextureStageParams params;
params.colorOperation = TEX_MIX_OPER_MODULATE;
params.colorArg1 = TEX_MIX_ARG_TEXTURE;
params.colorArg2 = TEX_MIX_ARG_FACTOR;
params.alphaOperation = TEX_MIX_OPER_DEFAULT; // TODO: replace with src color ?
+ params.factor = color;
m_device->SetTextureEnabled(0, true);
m_device->SetTextureStageParams(0, params);
@@ -1871,13 +1867,12 @@ void CEngine::SetState(int state, const Color& color)
m_device->SetRenderState(RENDER_STATE_BLENDING, true);
m_device->SetBlendFunc(BLEND_DST_COLOR, BLEND_ZERO);
- m_device->SetTextureFactor(color.Inverse());
-
TextureStageParams params;
params.colorOperation = TEX_MIX_OPER_ADD;
params.colorArg1 = TEX_MIX_ARG_TEXTURE;
params.colorArg2 = TEX_MIX_ARG_FACTOR;
params.alphaOperation = TEX_MIX_OPER_DEFAULT; // TODO: replace with src color ?
+ params.factor = color.Inverse();
m_device->SetTextureEnabled(0, true);
m_device->SetTextureStageParams(0, params);
@@ -1963,14 +1958,13 @@ void CEngine::SetState(int state, const Color& color)
m_device->SetAlphaTestFunc(COMP_FUNC_GREATER, 0.5f);
- m_device->SetTextureFactor(color);
-
TextureStageParams params;
params.colorOperation = TEX_MIX_OPER_MODULATE;
params.colorArg1 = TEX_MIX_ARG_TEXTURE;
params.colorArg2 = TEX_MIX_ARG_SRC_COLOR;
params.alphaOperation = TEX_MIX_OPER_REPLACE;
params.alphaArg1 = TEX_MIX_ARG_TEXTURE;
+ params.factor = color;
m_device->SetTextureEnabled(0, true);
m_device->SetTextureStageParams(0, params);
@@ -2348,11 +2342,6 @@ bool CEngine::GetFog()
return m_fog;
}
-bool CEngine::GetStateColor()
-{
- return m_stateColor;
-}
-
void CEngine::SetSecondTexture(int texNum)
{
m_secondTexNum = texNum;
@@ -2964,18 +2953,8 @@ void CEngine::Draw3DScene()
if (transparent)
{
- int tState = 0;
- Color tColor;
- if (m_stateColor)
- {
- tState = ENG_RSTATE_TTEXTURE_BLACK | ENG_RSTATE_2FACE;
- tColor = Color(68.0f / 255.0f, 68.0f / 255.0f, 68.0f / 255.0f, 68.0f / 255.0f);
- }
- else
- {
- tState = ENG_RSTATE_TCOLOR_BLACK;
- tColor = Color(136.0f / 255.0f, 136.0f / 255.0f, 136.0f / 255.0f, 136.0f / 255.0f);
- }
+ int tState = ENG_RSTATE_TTEXTURE_BLACK | ENG_RSTATE_2FACE;
+ Color tColor = Color(68.0f / 255.0f, 68.0f / 255.0f, 68.0f / 255.0f, 68.0f / 255.0f);
for (int l1 = 0; l1 < static_cast<int>( m_objectTree.size() ); l1++)
{
@@ -3551,8 +3530,6 @@ void CEngine::DrawForegroundImage()
// Status: PART_TESTED
void CEngine::DrawOverColor()
{
- if (! m_stateColor) return;
-
// TODO: fuzzy compare?
if ( (m_overColor == Color(0.0f, 0.0f, 0.0f, 0.0f) && m_overMode == ENG_RSTATE_TCOLOR_BLACK) ||
(m_overColor == Color(1.0f, 1.0f, 1.0f, 1.0f) && m_overMode == ENG_RSTATE_TCOLOR_WHITE) ) return;
diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h
index 6363fd3..700903f 100644
--- a/src/graphics/engine/engine.h
+++ b/src/graphics/engine/engine.h
@@ -1291,8 +1291,6 @@ protected:
int m_statisticTriangle;
bool m_updateGeometry;
int m_alphaMode;
- bool m_stateColor;
- bool m_forceStateColor;
bool m_groundSpotVisible;
bool m_shadowVisible;
bool m_dirty;
diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp
index 56a7130..78a77bd 100644
--- a/src/graphics/opengl/gldevice.cpp
+++ b/src/graphics/opengl/gldevice.cpp
@@ -684,6 +684,8 @@ void CGLDevice::SetTextureStageParams(int index, const TextureStageParams &param
glActiveTexture(GL_TEXTURE0 + index);
+ glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, params.factor.Array());
+
// To save some trouble
if ( (params.colorOperation == TEX_MIX_OPER_DEFAULT) &&
(params.alphaOperation == TEX_MIX_OPER_DEFAULT) )
@@ -836,27 +838,6 @@ TextureStageParams CGLDevice::GetTextureStageParams(int index)
return m_textureStageParams[index];
}
-void CGLDevice::SetTextureFactor(const Color &color)
-{
- // Needs to be set for all texture stages
- for (int index = 0; index < static_cast<int>( m_currentTextures.size() ); ++index)
- {
- glActiveTexture(GL_TEXTURE0 + index);
- glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color.Array());
- }
-}
-
-Color CGLDevice::GetTextureFactor()
-{
- // Get from 1st stage (should be the same for all stages)
- glActiveTexture(GL_TEXTURE0);
-
- GLfloat color[4] = { 0.0f };
- glGetTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color);
-
- return Color(color[0], color[1], color[2], color[3]);
-}
-
GLenum TranslateGfxPrimitive(PrimitiveType type)
{
GLenum flag = 0;
diff --git a/src/graphics/opengl/gldevice.h b/src/graphics/opengl/gldevice.h
index 78c7433..8af864e 100644
--- a/src/graphics/opengl/gldevice.h
+++ b/src/graphics/opengl/gldevice.h
@@ -119,9 +119,6 @@ public:
virtual void SetTextureStageWrap(int index, Gfx::TexWrapMode wrapS, Gfx::TexWrapMode wrapT);
- virtual void SetTextureFactor(const Color &color);
- virtual Color GetTextureFactor();
-
virtual void DrawPrimitive(PrimitiveType type, const Vertex *vertices, int vertexCount);
virtual void DrawPrimitive(PrimitiveType type, const VertexCol *vertices, int vertexCount);
virtual void DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, int vertexCount);