Sign in to follow this  
JohnnyCode

active unit 0

Recommended Posts

hello all, I got me another problem. I use GLSL shader and texture units. In my mesh render method I do following to set up texture units: int l=-1; if (m_vTextures.size()>0){ for (int n=0;n<m_vTextures.size();n++) { l++; glActiveTexture(GL_TEXTURE0+l); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,m_vTextures.at(n)->GetHWName()); glClientActiveTexture(GL_TEXTURE0+l); } } The problem is that if I set unit 0 as the active unit my mesh is all black but if I use other higher units(and change uniforms setting to correspond of course) I get my texture drawn. I do no settings or operations on unit 0 except that I load my textures by that unit like this: glActiveTexture(GL_TEXTURE0); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,m_iTextureName); glTexImage2D(GL_TEXTURE_2D,0, 3, m_iWidth, m_iHeight,0, GL_BGR, GL_UNSIGNED_BYTE, colorsa); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, m_iWidth, m_iHeight, GL_BGR, GL_UNSIGNED_BYTE, colorsa); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glBindTextureEXT(GL_TEXTURE_2D,0); glDisable(GL_TEXTURE_2D); This is how I pass textures to my shader: if (mesh->GetTexture(0,1)) glUniform1i(texuA,0); if (mesh->GetTexture(1,1)) glUniform1i(texuB,1); if (mesh->GetTexture(2,1)) glUniform1i(texuC,2); if (mesh->GetTexture(3,1)) glUniform1i(texuD,3); So I somehow can't use unit 0. Why could that be?

Share this post


Link to post
Share on other sites
I don't know about the problem you are having but...
You don't need to call glClientActiveTexture. That is for glTexCoordPointer.

You don't need to glEnable(GL_TEXTURE_2D);

You don't need to glBindTextureEXT(GL_TEXTURE_2D,0);

You don't need glTexImage2D since you re calling gluBuild2DMipmaps

Since you want to use mipmaps
why do you call glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
Use glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);

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