• Advertisement

Archived

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

Loading more than one Texture

This topic is 6060 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a rather simple problem, when I try to load 1 texture everything is fine. But when I try to load another one all hell breaks loose. I will post my code cause i know i messaed something up . Code: int LoadGLTexture() { int status = FALSE; AUX_RGBImageRec *TextureImage[2]; memset(TextureImage, 0, sizeof(void *)*1); if (TextureImage[0] = LoadBMP("/TheMan.bmp")) { status = TRUE; glGenTextures(2, &texture[0]); glBindTexture(GL_TEXTURE_2D, texture[0]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->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 (TextureImage[0]->data) { free(TextureImage[0]->data); } free(TextureImage[0]); } //This is where the problem is: if (TextureImage[1] = LoadBMP("/CrazyFoo")) { status = TRUE; glGenTextures(2, &texture[1]); glBindTexture(GL_TEXTURE_2D, texture[1]); 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 (TextureImage[1]->data) { free(TextureImage[1]->data); } free(TextureImage[1]); } } END CODE. Also my other question is why after a while does my computer start running really really slow, and the my textures stop loading right? I am new to OpenGL, but not really to C++ so it would be great to figure this one out, thanks. BigLuniticFatPsychoProgrammerDude HAVE SOME TOAST DARLING! OR I WILL BEAT YOU!

Share this post


Link to post
Share on other sites
Advertisement
You are generating 2 texture IDs in the first call to glGenTextures so you should not call that function a second time. It will just write over the correct ID. A alternative and perhaps clearer is to generate just one ID at each call.

Your computer starts to run really slow probably because that you do not free the memory with glDeleteTextures then the app is finish.

Share this post


Link to post
Share on other sites
Dude, thanks. Are there any parameter that i need to pass to glDeleteTextures();? I will try what you told me.

ToasterFace

HAVE SOME TOAST DARLING! OR I WILL BEAT YOU!

Share this post


Link to post
Share on other sites
Maybe it''s because of this line:

  
if (TextureImage[1] = LoadBMP("/CrazyFoo"))


Instead of "CrazyFoo" it should be "CrazyFoo.BMP" ?

Share this post


Link to post
Share on other sites

  • Advertisement