This topic is now archived and is closed to further replies.


When loading 2 textures the first one goes blank..

Recommended Posts

ive done it like this: ----------------------- int LoadGLTextures() // Load Bitmaps And Convert To Textures { int Status=FALSE; // Status Indicator AUX_RGBImageRec *TextureImage[2]; // Create Storage Space For The Texture memset(TextureImage,1,sizeof(void *)*1); // Set The Pointer To NULL // Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit if ((TextureImage[0]=LoadBMP("Data/NeHe.bmp")) && (TextureImage[1]=LoadBMP("Data/NeHe1.bmp"))) { Status=TRUE; // Set The Status To TRUE glGenTextures(2, &texture[0]); // Create The Texture //glGenTextures(1, &texture[1]); // Create The Texture // Typical Texture Generation Using Data From The Bitmap glBindTexture(GL_TEXTURE_2D, texture[0]); glBindTexture(GL_TEXTURE_2D, texture[1]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[1]->sizeX, TextureImage[1]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[1]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } if (TextureImage[0]) // If Texture Exists { if (TextureImage[0]->data) // If Texture Image Exists { free(TextureImage[0]->data); // Free The Texture Image Memory } free(TextureImage[0]); // Free The Image Structure } if (TextureImage[1]) // If Texture Exists { if (TextureImage[1]->data) // If Texture Image Exists { free(TextureImage[1]->data);// Free The Texture Image Memory } free(TextureImage[1]);// Free The Image Structure } return Status; // Return The Status } ------------- I fixed the code from the 5th tutorial then when I: glBindTexture(GL_TEXTURE_2D, texture[0]); The following shapes are white but after that (on another quad) when i do glBindTexture(GL_TEXTURE_2D, texture[1]); All goes fine and it desplays the texture for me.. whats the problem? (note i dunno if i could post include long code if i couldnt im sorry) Edited by - Daredevil on January 29, 2002 4:42:18 AM

Share this post

Link to post
Share on other sites
You''re misunderstanding how glBindTexture works.

When you call it, OpenGL selects the texture you specify.

So, you''re code does this...

Select texture 0
Select texture 1
Initialise selected texture (texture 1)

Instead, the initialisation functions should be called for both textures.

As an aside note, copy and paste from tutorials is bad. Learn how the functions work. If you knew what all the functions you''re calling actually did, then you would not have had this problem.

- Pete

Share this post

Link to post
Share on other sites
Why did you bother changing Nehe''s code it works perfectly unless you dont use images of the size 64x64 128x128 256x256 and so on (multiplies of 2).

The reason your code is failing is that your issuing your glBindTexture calls wrong.

glGenTexture() generates a bunch of blank textures when you call it, thats why your texture array must be the same size as the number of textures being generated.

When you bind a texture with glBindTexture only that texture will be available to you (one), binding another texture erases the previous texture and calls up the new one, therefore whatever your going to do to that texture i.e. load a bitmap onto it, must be done before the next texture is called.

If you go back to the orignal Nehe code everything should work out. An advantage to this is that with very large numbers of textures you can use loops to assign everything rather than type everything out.


for(int loop=0;loop<5;loop++){
(see the later Nehe tutorials on this)

Share this post

Link to post
Share on other sites