Sign in to follow this  
AndyPandyV2

GLSL multitexturing

Recommended Posts

Hello, I'm trying to use Multitexturing with GLSL. The following lines should be getting the location of my uniform sampler2D texture units from the shader and binding them to texture unit 0 and texture unit 1. int loc = m_pExt->glGetUniformLocationARB(hShaderPrograms[x].hProgamObject,"textureUnit"); m_pExt->glUniform1iARB(loc,0); int loc2 = m_pExt->glGetUniformLocationARB(hShaderPrograms[x].hProgamObject,"textureUnit2"); m_pExt->glUniform1iARB(loc2,1); The problem is that inside the shader both textureUnit and textureUnit2 both reference the same texture(TU0). I'm setting the textures with.. glActiveTextureARB(GL_TEXTURE0_ARB); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, tex1ID); glActiveTextureARB(GL_TEXTURE1_ARB); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, tex2ID); If I use multitexturing without the shader I can use both textures but when using the shader I can't seem to get any textures besides TU0.. anyone know anything about this?

Share this post


Link to post
Share on other sites
Fragment shader is like this to test if the 2nd texture works.

varying vec2 texCoord;
uniform sampler2D textureUnit;
uniform sampler2D textureUnit2;

void main()
{
vec4 tempFrag = texture2D(textureUnit,texCoord);
vec4 tempFrag2 = texture2D(textureUnit2,texCoord);
gl_FragColor = tempFrag2;
}


Setting FragColor to tempFrag or tempFrag2 makes no difference, it displays the same texture in both cases.

Share this post


Link to post
Share on other sites
Quote:
Original post by AndyPandyV2
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, tex1ID);

glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, tex2ID);



You need this line also when setting up your multitexturing and I am assuming your using Vertex arrays for texture coordinates?

glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textureObject[tex1ID]);
glClientActiveTextureARB(GL_TEXTURE0_ARB);



HTH

Share this post


Link to post
Share on other sites
It seems like this code can be removed completely and it makes no difference.. I don't believe the the TU are being bound properly for whatever reason. All sampler2D's just seem to be defaulting to TU0.

int loc2 = m_pExt->glGetUniformLocationARB(hShaderPrograms[x].hProgamObject,"textureUnit2");
m_pExt->glUniform1iARB(loc2,1)


Share this post


Link to post
Share on other sites
u dont need to enable textures with shaders thus u can remove these totally
glEnable( GL_TEXTUE_2D ) theyre only needed if u use the standard pipeline,
though it should still work even though theyre in.
i cant see whats wrong, did u try glGetError(), textures loading properly etc

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this