Commit 3fe54abf authored by Isaak Lim's avatar Isaak Lim
Browse files

slightly improved the text node rendering by using alpha testing instead of alpha blending

closes #1759

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@17674 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 4ea0a604
...@@ -101,6 +101,9 @@ TextNode( BaseNode* _parent, ...@@ -101,6 +101,9 @@ TextNode( BaseNode* _parent,
cullFaceEnabled_(false), cullFaceEnabled_(false),
depthEnabled_(false), depthEnabled_(false),
alwaysOnTop_(_alwaysOnTop), alwaysOnTop_(_alwaysOnTop),
alphaTest_(false),
alphaTestValue_(0.5f),
alphaTestFunc_(GL_GREATER),
blendSrc_(0), blendSrc_(0),
blendDest_(0), blendDest_(0),
lastScale_(0.f) lastScale_(0.f)
...@@ -234,7 +237,7 @@ createMap() { ...@@ -234,7 +237,7 @@ createMap() {
void void
TextNode:: TextNode::
enter(GLState& /*_state*/, const DrawModes::DrawMode& /*_drawmode*/) { enter(GLState& _state, const DrawModes::DrawMode& /*_drawmode*/) {
if (text_.empty()) if (text_.empty())
return; return;
...@@ -243,6 +246,9 @@ enter(GLState& /*_state*/, const DrawModes::DrawMode& /*_drawmode*/) { ...@@ -243,6 +246,9 @@ enter(GLState& /*_state*/, const DrawModes::DrawMode& /*_drawmode*/) {
texture2dEnabled_ = glIsEnabled(GL_TEXTURE_2D); texture2dEnabled_ = glIsEnabled(GL_TEXTURE_2D);
blendEnabled_ = glIsEnabled(GL_BLEND); blendEnabled_ = glIsEnabled(GL_BLEND);
depthEnabled_ = glIsEnabled(GL_DEPTH_TEST); depthEnabled_ = glIsEnabled(GL_DEPTH_TEST);
alphaTest_ = glIsEnabled(GL_ALPHA_TEST);
if (alphaTest_)
ACG::GLState::getAlphaFunc(&alphaTestFunc_, &alphaTestValue_);
glGetIntegerv(GL_BLEND_SRC, &blendSrc_); glGetIntegerv(GL_BLEND_SRC, &blendSrc_);
glGetIntegerv(GL_BLEND_DST, &blendDest_); glGetIntegerv(GL_BLEND_DST, &blendDest_);
...@@ -251,6 +257,8 @@ enter(GLState& /*_state*/, const DrawModes::DrawMode& /*_drawmode*/) { ...@@ -251,6 +257,8 @@ enter(GLState& /*_state*/, const DrawModes::DrawMode& /*_drawmode*/) {
ACG::GLState::disable(GL_CULL_FACE); ACG::GLState::disable(GL_CULL_FACE);
ACG::GLState::enable(GL_TEXTURE_2D); ACG::GLState::enable(GL_TEXTURE_2D);
ACG::GLState::enable(GL_BLEND); ACG::GLState::enable(GL_BLEND);
ACG::GLState::enable(GL_ALPHA_TEST);
ACG::GLState::alphaFunc(GL_GREATER, 0.2);
ACG::GLState::blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); ACG::GLState::blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
if (alwaysOnTop_) if (alwaysOnTop_)
ACG::GLState::disable(GL_DEPTH_TEST); ACG::GLState::disable(GL_DEPTH_TEST);
...@@ -278,6 +286,10 @@ leave(GLState& /*_state*/, const DrawModes::DrawMode& /*_drawmode*/) { ...@@ -278,6 +286,10 @@ leave(GLState& /*_state*/, const DrawModes::DrawMode& /*_drawmode*/) {
ACG::GLState::enable(GL_DEPTH_TEST); ACG::GLState::enable(GL_DEPTH_TEST);
else else
ACG::GLState::disable(GL_DEPTH_TEST); ACG::GLState::disable(GL_DEPTH_TEST);
if (!alphaTest_)
ACG::GLState::disable(GL_ALPHA_TEST);
else
ACG::GLState::alphaFunc(alphaTestFunc_, alphaTestValue_);
ACG::GLState::blendFunc(blendSrc_, blendDest_); ACG::GLState::blendFunc(blendSrc_, blendDest_);
} }
...@@ -570,7 +582,6 @@ getRenderObjects(ACG::IRenderer* _renderer, ACG::GLState& _state , const ACG::S ...@@ -570,7 +582,6 @@ getRenderObjects(ACG::IRenderer* _renderer, ACG::GLState& _state , const ACG::S
} }
ro.culling = false; ro.culling = false;
//ro.alphaTest = true;
ro.blending = true; ro.blending = true;
ro.alpha = 0.f; ro.alpha = 0.f;
......
...@@ -236,6 +236,15 @@ private: ...@@ -236,6 +236,15 @@ private:
/// stores if text should be drawn always on top /// stores if text should be drawn always on top
bool alwaysOnTop_; bool alwaysOnTop_;
/// stores if the alpha test was enabled
bool alphaTest_;
/// stores the alpha value used for alpha test
float alphaTestValue_;
/// stores alpha test comparison function
GLenum alphaTestFunc_;
/// stores the sfactor parameter of glBlendFunc on entering TextNode /// stores the sfactor parameter of glBlendFunc on entering TextNode
GLint blendSrc_; GLint blendSrc_;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment