From 9f8f493aedf1d8ad90c591ea859a1909964c74f9 Mon Sep 17 00:00:00 2001 From: Alexander Szpakowski Date: Thu, 17 Jan 2013 04:18:38 -0400 Subject: [PATCH] Texel (texture2D) calls in shaders now return pure white instead of pure black when drawing untextured graphics primitives. This prevents the need for separate "passthrough" shaders to be used when drawing graphics primitives vs images. --- src/modules/graphics/opengl/OpenGL.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/modules/graphics/opengl/OpenGL.cpp b/src/modules/graphics/opengl/OpenGL.cpp index 1d49cb24d..b9120085a 100644 --- a/src/modules/graphics/opengl/OpenGL.cpp +++ b/src/modules/graphics/opengl/OpenGL.cpp @@ -89,6 +89,24 @@ void initializeContext() glGetIntegerv(GL_TEXTURE_BINDING_2D, (GLint *) &textureUnits[0]); } + + // Set the 'default' texture (id 0) as a repeating white pixel. + // Otherwise, texture2D inside a shader would return black when drawing graphics primitives, + // which would create the need to use different "passthrough" shaders for untextured primitives vs images. + + GLuint curtexture = textureUnits[curTextureUnit]; + bindTexture(0); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + + GLubyte pixel = 255; + glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE8, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, &pixel); + + bindTexture(curtexture); } void uninitializeContext()