Hi everyone,
I have a problem of using multi-texture in vertex shader. What I want to do is as following:
first load multi-textures and then switch between them in the vertex shadre w.r.t a variable controlled from keyboard function, but the problem is that the shader uses only the last loaded texture, so I will show you how I do it:
first in main function:
GLuint texture[2];
glGenTextures( 2, texture );
glBindTexture( GL_TEXTURE_2D, texture[0] );
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D,0,4,1,1,0,GL_RGBA,GL_FLOAT,data_array0);
glBindTexture( GL_TEXTURE_2D, texture[1] );
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D,0,4,1,1,0,GL_RGBA,GL_FLOAT,data_array1);
//here will be shader setting create, link, use…
loc0 = glGetUniformLocation(p,"texture0");
glUniform1i(loc0,0);
loc1 = glGetUniformLocation(p,"texture1");
glUniform1i(loc1,1);
//in vertex shadre
uniform sampler2D texture0;
uniform sampler2D texture1;
//witch between int variable
uniform int swt;
void main()
{
//getting vetrex
if(swt == 0)
texel = texture2D(texture0,tex_coord);
else if(swt == 1)
texel = texture2D(texture1,tex_coord);
//pass to fragment shader
}
but if swt is 0 or 1 it chooses the data from texture1, which is the last loaded one and if I change the loading to be first texture1 and then texture0 then it choose texture0.
So, if you have any clue, where is the problem or what I have missed please let me know … comments, suggestions are appreciated ae well.