PDA

View Full Version : Loading textures in a loop



IAmLion
07-20-2010, 02:32 PM
Hi there,

I have a problem with a program I'm writing. I'm trying to get a stack of quads to render with different transparent textures so that looking through the stack shows each image overlaid. The images for the textures are loaded at runtime via command line arguments. Loading the textures and getting transparency to work is fine, but looping through the textures (whose IDs are stored in a vector) causes the textures to stop working. The loop looks like this:

for(int i=0; i<numImgs; i++){

GLuint tex;
tex = textures->at(i);
glBindTexture(GL_TEXTURE_2D, tex);

glBegin(GL_QUADS);

glTexCoord2f(1, 0);
glVertex3f( 2.0f, -2.0f, startZ + (i * spacing));

glTexCoord2f(1, 1);
glVertex3f( 2.0f, 2.0f, startZ + (i * spacing));

glTexCoord2f(0, 1);
glVertex3f(-2.0f, 2.0f, startZ + (i * spacing));

glTexCoord2f(0, 0);
glVertex3f(-2.0f, -2.0f, startZ + (i * spacing));

glEnd();
}

So it's not binding the texture in between calls to glBegin() and glEnd(). If I change the line

tex = textures->at(i);

to

tex = textures->at(0);

or any other number within the range of the vector makes the quads render correctly but obviously all with the same texture. When i is left there, the quads lose their transparency as if there was no texture data - even if I limit the range of the for loop from 0-10 or some other small range (105 images are being loaded in).

I cannot find a reason for this or any help in the various tutorials online, nobody else seems to have had this problem!

Any help would be hugely appreciated,

Many thanks,

Matt