How GLSL know if texture is unbinded?

Started by
0 comments, last by Marco81 13 years, 8 months ago
Hi,

Kinda simple question I think, but have searched in many OpenGL forums and haven't found answer yet :(

I have shader for multitexture which works well, if all surfaces in scene uses 2 different textures to mix. But if some surfaces uses only 1 texture then those surfaces are black. How GLSL know if texture is binded or unbinded?

Function to bind one texture.
GLvoid Texture::Bind(GLuint ID) {	glActiveTexture(GL_TEXTURE1);	glBindTexture(GL_TEXTURE_2D, 0);	glActiveTexture(GL_TEXTURE0);	glBindTexture(GL_TEXTURE_2D, ID);}


Shader:
uniform sampler2D Tex0;uniform sampler2D Tex1;...Texture0 = texture2D(Tex0, gl_TexCoord[0].st);// Surface is black because Texture1 is (0,0,0,0) ?!Texture1 = texture2D(Tex1, gl_TexCoord[0].st);Texture = Texture0 * Texture1;...gl_FragColor = Color * Texture;


Any good suggestions will be rated highly.
Thanks in advance!
Advertisement
AFAIK GLSL doesn't know that you haven't bound a texture to the sampler, causing it to use black as the texture color. A solution could be to use a different shader for single texturing. Alternatively if you want to use only 1 shader you can bind a small white texture (1x1) to GL_TEXTURE1 when you only have one regular texture.

This topic is closed to new replies.

Advertisement