PDA

View Full Version : Loading multiple textures



Imaging
03-20-2006, 02:28 PM
Hi, I'm curently creating image viewing software using opengl/c++. This obviously involves loading a high number of textures into the program, when I use the code below the corrct image is loaded, however when I attempt to create a for loop in order to load several images, the initialization fails. I was just wondering if this was actually a constraint in openGL or is it my coding. The for loop I have been using is commented out in the code below.Any help would be much appreciated.

//Code for loading textures
int bi=0;

Status=TRUE;
//for(bi=0;bi>count-1;bi++){
TextureImage[bi] = LoadBMP(name);
glGenTextures(1, &texture[bi]);


glBindTexture(GL_TEXTURE_2D, texture[bi]);


glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
gluBuild2DMipmaps(GL_TEXTURE_2D,3, TextureImage[bi]->sizeX, TextureImage[bi]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[bi]->data);
// }

CatDog
03-20-2006, 02:51 PM
Some suggestions:

- Check GL error state after each command. When does is fail?

- Separate texture name generation from the binding. Something like this:

glGenTextures( count, &textures ); // Generate all names at once
for( ... ) ... // Bind and process

- How much is "a high number"?

- Are the image sizes 2^n? [EDIT] Ops, forget about this one. gluBuildMipmaps handles non-2^n images correctly, of course.

CatDog

jide
03-20-2006, 02:52 PM
What kind of failure do you have ?

jabe
03-21-2006, 07:55 AM
//for(bi=0;bi>count-1;bi++){wouldn't

for(bi=0;bi<count;bi++){make more sense?

Imaging
03-21-2006, 01:06 PM
Thanks finally got the loops working, had to break it up into an number of seperate functions and then the loops, but its working fine now. Eventually I'll be testing the program with approx, 20-100 images.....hopefully. Thanks for the help again