• Advertisement
Sign in to follow this  

GLSL multitexturing

This topic is 4723 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

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
Advertisement
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
Thanks for the help, I tried glGetError() and on binding to any TU besides TU0 it generates error 1281 "invalid value".

glUniform1iARB(loc2,1);

Share this post


Link to post
Share on other sites
Tried putting it in a loop and checking every Uniform from 0-255, it said Invalid operation for every one except the location of loc/loc2 which it says Invalid value if I try and bind anything other then TU0.

Share this post


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

  • Advertisement