Binding textures to GLSL

Started by
4 comments, last by zacaj 12 years, 3 months ago
hi,

im trying to send multiple texture ids to glsl via this code:


glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, textureId[]);
glUniform1i(glGetUniformLocation(6, "tex1"), 0);


glActiveTextureARB(GL_TEXTURE1_ARB);
glBindTexture(GL_TEXTURE_2D, textureId[2]);
glUniform1i(glGetUniformLocation(6, "tex2"), 1);


but somehow it slows the program (a lot) and sometimes fail to render. im not sure what happened. when i send only one texture, it works perfectly. but when i send both with the code above, it crashes. there's nothing wrong with the texture: they both successfully sent to gpu and can be rendered. there is no change in the glsl since im not yet using the second texture. anyone know why this happens?


thanks in advance
Advertisement
glBindTexture(GL_TEXTURE_2D, textureId[]) ? what is that?
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);
And aside from what V-man said:glActiveTextureARB(GL_TEXTURE1_ARB);
glBindTexture(GL_TEXTURE_2D, textureId[2]);
glUniform1i(glGetUniformLocation(6, "tex2"), 1);

You're using the third element of the textureId array here. Is that intentional? Is textureId declared as "GLuint textureId[3]"?

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

hi,

yes that was a typo. the array is fine, there are 5 elements all printed out correctly just right before i bind them. so it wouldn't be the array. im still not sure what happened, it can render the first frame, but it stuck after that. any idea why its happened?

thanks in advance
ah sorry, apparently i forgot i already use GL_TEXTURE0 for the background, and I binded the wrong one. thats probably why its not rendered correctly. thanks anyway.
I have a feeling you shouldnt be using glUniformLocation is performance sensitive code

This topic is closed to new replies.

Advertisement