active unit 0

Started by
1 comment, last by JohnnyCode 15 years, 3 months ago
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?
Advertisement
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);
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
solved, I was setting the same sampler to more shader unifroms. So it seems I cant use the same sampler on more then one uniform shader sampler. Hmmm, can I somehow set more shader sampler2d unifroms to the same sampler?

This topic is closed to new replies.

Advertisement