From 92e79b81230554aa681695ba9e78dfaf6b1d39dc Mon Sep 17 00:00:00 2001 From: laurentgom Date: Sat, 13 Jun 2009 19:09:02 +0000 Subject: [PATCH] Fixed blending functions so that alpha is properly forwarded when rendered to a RenderImage git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1137 4e206d99-4929-0410-ac5d-dfc041789085 --- src/SFML/Graphics/Drawable.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/SFML/Graphics/Drawable.cpp b/src/SFML/Graphics/Drawable.cpp index db7c6662..e2484c65 100644 --- a/src/SFML/Graphics/Drawable.cpp +++ b/src/SFML/Graphics/Drawable.cpp @@ -379,12 +379,22 @@ void Drawable::Draw(RenderTarget& Target) const { GLCheck(glEnable(GL_BLEND)); + // We have to use glBlendFuncSeparate so that the resulting alpha is + // not alphaČ, which is incorrect and would cause problems when rendering + // alpha pixels to a RenderImage that would be in turn rendered to another render target switch (myBlendMode) { - case Blend::Alpha : GLCheck(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); break; - case Blend::Add : GLCheck(glBlendFunc(GL_SRC_ALPHA, GL_ONE)); break; - case Blend::Multiply : GLCheck(glBlendFunc(GL_DST_COLOR, GL_ZERO)); break; - default : break; + case Blend::Alpha : + GLCheck(glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); + break; + case Blend::Add : + GLCheck(glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); + break; + case Blend::Multiply : + GLCheck(glBlendFuncSeparate(GL_DST_COLOR, GL_ZERO, GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); + break; + default : + break; } }