From 90d5833430818ae2b160b2da63d7c39ed40389c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Fri, 23 Aug 2013 23:06:52 -0300 Subject: [PATCH] Fixed a Color::Blend, it was having problems with the floating point precision. --- include/eepp/graphics/opengl.hpp | 4 +++- include/eepp/system/colors.hpp | 8 +++----- src/test/eetest.cpp | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/eepp/graphics/opengl.hpp b/include/eepp/graphics/opengl.hpp index c2a312047..3145c8eca 100644 --- a/include/eepp/graphics/opengl.hpp +++ b/include/eepp/graphics/opengl.hpp @@ -1,7 +1,9 @@ #ifndef EE_OPENGL_HPP #define EE_OPENGL_HPP -#ifdef EE_64BIT +#include + +#if 1 == EE_USE_DOUBLES #define GL_FP GL_DOUBLE #else #define GL_FP GL_FLOAT diff --git a/include/eepp/system/colors.hpp b/include/eepp/system/colors.hpp index 88f2b890a..705a0816e 100755 --- a/include/eepp/system/colors.hpp +++ b/include/eepp/system/colors.hpp @@ -209,6 +209,8 @@ public: return eeColorAf( red, green, blue, alpha ); } + #define EE_COLOR_BLEND_FTOU8(color) (Uint8)( color == 1.f ? 255 : (color * 255.99f)) + /** Blend a source color to destination color */ static inline eeColorA Blend( eeColorA src, eeColorA dst ) { eeColorAf srcf( (eeFloat)src.Red / 255.f, (eeFloat)src.Green / 255.f, (eeFloat)src.Blue / 255.f, (eeFloat)src.Alpha / 255.f ); @@ -218,11 +220,7 @@ public: eeFloat green = ( srcf.Green * srcf.Alpha + dstf.Green * dstf.Alpha * ( 1.f - srcf.Alpha ) ) / alpha; eeFloat blue = ( srcf.Blue * srcf.Alpha + dstf.Blue * dstf.Alpha * ( 1.f - srcf.Alpha ) ) / alpha; - return eeColorA( ((Uint8)(eefloor(red == 1.f ? 255 : red * 256.f))), - ((Uint8)(eefloor(green == 1.f ? 255 : green * 256.f))), - ((Uint8)(eefloor(blue == 1.f ? 255 : blue * 256.f))), - ((Uint8)(eefloor(alpha == 1.f ? 255 : alpha * 256.f))) - ); + return eeColorA( EE_COLOR_BLEND_FTOU8(red), EE_COLOR_BLEND_FTOU8(green), EE_COLOR_BLEND_FTOU8(blue), EE_COLOR_BLEND_FTOU8(alpha) ); } }; diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index 921fe3abe..29c18e2a3 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -1433,8 +1433,8 @@ void cEETest::Input() { eeFloat nmX = Mousef.x + mAxisX; eeFloat nmY = Mousef.y + mAxisY; - nmX = eemax( nmX, 0.f ); - nmY = eemax( nmY, 0.f ); + nmX = eemax( nmX, 0 ); + nmY = eemax( nmY, 0 ); nmX = eemin( nmX, (eeFloat)EE->GetWidth() ); nmY = eemin( nmY, (eeFloat)EE->GetHeight() );