From 90402c285d4ba62aa3f09ed1d7b39578a8c55fbe Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 4 Oct 2013 14:02:14 +0200 Subject: [PATCH] VizFramework: Improve the stability of text color in ResInsight. The setting for current OpenGL texture engine is not controlled well enough, causing the wrong texture to be active when rendering text - hence giving semi-random colors for the text. --- Fwk/VizFwk/LibRender/cvfGlyph.cpp | 4 +--- Fwk/VizFwk/LibRender/cvfTextDrawer.cpp | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Fwk/VizFwk/LibRender/cvfGlyph.cpp b/Fwk/VizFwk/LibRender/cvfGlyph.cpp index 400ab64b5a..ffe0a9f696 100644 --- a/Fwk/VizFwk/LibRender/cvfGlyph.cpp +++ b/Fwk/VizFwk/LibRender/cvfGlyph.cpp @@ -347,11 +347,10 @@ void Glyph::setupAndBindTexture(OpenGLContext* oglContext, bool software) texture->setWrapMode(Texture2D_FF::CLAMP); texture->setMinFilter(Texture2D_FF::NEAREST); texture->setMagFilter(Texture2D_FF::NEAREST); - texture->setupTexture(oglContext); - texture->setupTextureParams(oglContext); ref textureMapping = new RenderStateTextureMapping_FF(texture.p()); textureMapping->setTextureFunction(RenderStateTextureMapping_FF::MODULATE); + textureMapping->setupTexture(oglContext); m_textureBindings = textureMapping; #endif @@ -364,7 +363,6 @@ void Glyph::setupAndBindTexture(OpenGLContext* oglContext, bool software) sampler->setMagFilter(Sampler::NEAREST); ref texture = new Texture(m_textureImage.p()); - texture->setupTexture(oglContext); RenderStateTextureBindings* textureBindings = new RenderStateTextureBindings(texture.p(), sampler.p(), "dummy"); textureBindings->setupTextures(oglContext); diff --git a/Fwk/VizFwk/LibRender/cvfTextDrawer.cpp b/Fwk/VizFwk/LibRender/cvfTextDrawer.cpp index f7af237a07..8106d4918a 100644 --- a/Fwk/VizFwk/LibRender/cvfTextDrawer.cpp +++ b/Fwk/VizFwk/LibRender/cvfTextDrawer.cpp @@ -53,6 +53,7 @@ #include "cvfRenderStateDepth.h" #include "cvfRenderStateBlending.h" #include "cvfRenderStatePolygonOffset.h" +#include "cvfOpenGLCapabilities.h" #ifndef CVF_OPENGL_ES #include "cvfRenderState_FF.h" @@ -349,8 +350,20 @@ void TextDrawer::doRender2d(OpenGLContext* oglContext, const MatrixState& matrix RenderStateLighting_FF light(false); light.applyOpenGL(oglContext); -#endif + + // The active texture may be set to something different than unit 0 if we end up using + // software rendering here, BUT the context actually has higher capabilities + // Must be set before any texture related OpenGL calls + if (oglContext->capabilities()->supportsOpenGL2()) + { + glActiveTexture(GL_TEXTURE0); + } + + // Will get turned on during rendering of text, but must be off for background and border + glDisable(GL_TEXTURE_2D); + projCam.applyOpenGL(); +#endif } else { @@ -417,7 +430,7 @@ void TextDrawer::doRender2d(OpenGLContext* oglContext, const MatrixState& matrix #ifndef CVF_OPENGL_ES glEnable(GL_COLOR_MATERIAL); glDisable(GL_TEXTURE_2D); - glColor4fv(m_backgroundColor.ptr()); + glColor3fv(m_backgroundColor.ptr()); glBegin(GL_TRIANGLE_FAN); glVertex3fv(v1); glVertex3fv(v2);