Hi,
I’m using 3rd party that provides 2d and 3d views.
In both of them i am doing my drawing in pure OpenGL commands.
And now the problem:
I’m drawing quads with textures, and i’m doing it using VBO and shaders.
In the data arrays I’m providing for every vertex an attribute which is the texture number,
and according to this number i’m fetching the right sampler2D in the fragment shader.
It is working very good in 2D.
Application code
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, intTexID1);
glActiveTexture(GL_TEXTURE0 + 1);
glBindTexture(GL_TEXTURE_2D, intTexID2);
glActiveTexture(GL_TEXTURE0); // resetting the active texture back
glUniform1iv(UniformTextureLoc, new float[]{ 0, 1 });
Shader code
varying vec4 v_texture_color;
varying float v_texture_id; // The attribute from the vertex
uniform sampler2D u_textures[10];
void main(void)
{
gl_FragColor = v_texture_color * texture2D(u_textures[v_texture_id], gl_TexCoord[0].xy);
}
In 3D, it is working (after allot of fixes) but weird problem occurs.
I’ve attached a screen preview of the problem. There are 2 quads. each has different textures.
It’s look like the second texture is acting weird (the green). every movement of the camera it’s showing something else, but its mixing the textures - It’s like he is using some of the first texture also sometimes.
I’ve had few problems with this 3rd party before, but I found my mistakes (like not setting back the active texture to GL_TEXTURE0, or reset the binned buffer glBindBuffer(GL_ARRAY_BUFFER, 0)).
The thing is that it is working on 2D. so the 3rd party must enable\disable something that i’m not familiar with.
Is it familiar to anyone ? any ideas ?