multi-textures in vertex shader problem!

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.

Okay, I think the problem was that I haven’t used :

glActiveTexture()

function after loading my textures therefore I had only the data that comes from the last loaded texture.

Now, my question turned to how many “uniform samplesr2D texturei” in the vertex shader can I use ?.. this question regarding to the new problem that I have:
if I use more than 4 uniform for textures and the switching variable the shader doesn’t get any data from any texture and the loactions for uniforms become all “-1”…
Is that a real problem or I have just to add some missing commands I have to add ;-). Could this related to the storage size of the shader I am using …

Thanks in advance for any kind of help!

int p; glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, &p);

thanks :-), I know now how many textures I can use …
and this :

glGetIntegerv (GL_MAX_TEXTURE_SIZE, &p);

for getting texture size … does that mean for each or in total?

It’s for each texture. It is not related to texture samplers.

okay I see, thanks betgp