Jump to content
  • Advertisement
Sign in to follow this  
birdjames

OpenGL GLSL / Multi-texture problem

This topic is 4516 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm having difficulties with multi-texturing in GLSL. I have binded my textures in the usual way (glActiveTexture, glBindTexture, glEnable(GL_TEXTURE_2D) ) and multi-texturing works for the fixed function pipeline. When I switch to using a shader object, multi-texturing doesn't work! This leads me to believe that either: 1. My GLSL code is incorrect 2. There is something that I haven't done (an OpenGL function I haven't called maybe?) before the geometry is rendered Attached below is a simple fragment shader that should use the first set of texture coordinates to sample the 2D texture binded to GL_TEXTURE1:
uniform sampler2D sampler0, sampler1;
void main ( void )
{
	gl_FragColor = texture2D ( sampler1, gl_TexCoord[0] );
}
What actually happens is no matter which sampler I use for the first argument of 'texture2D', it always samples the 2D texture bound to GL_TEXTURE0. I am definitely binding my textures correctly, as fixed-function works fine. Any help would be much appreciated! Thanks, birdjames.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
in GLSL, you must tell openGL wich texture is associated with wich sampler.opengl don't know that sampler0 is bound to texture 0, and sampler1 to texture 1. You must explicitely tell him.

you have to set your's samplers values their texture unit numbers with the GLUniform functions, like you would do with other uniforms.

Share this post


Link to post
Share on other sites
Glad you got that sorted out! However, it's possible I'm wrojng but I think texture2D(...) expects a vec2 as the second argument. You should really be using gl_TexCoord[0].st

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!