Archived

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

Xewren

Lesson 06 and more than one texture...

Recommended Posts

This doesnt work: // Load Bitmaps, Check For Errors, If Bitmaps are Not Found Quit if (TextureImage[0]=LoadBMP("Data/1.bmp")) if (TextureImage[1]=LoadBMP("Data/2.bmp")) { Status=TRUE; glGenTextures(1, &texture[0]); glGenTextures(1, &texture[1]); // 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); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); 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]) { if (TextureImage[0]->data) if (TextureImage[1]->data) { free(TextureImage[0]->data); free(TextureImage[1]->data); } free(TextureImage[0]); free(TextureImage[1]); } Basically this is the same code as in Lesson 06, but i try to load 2 textures at the same time... Why doesnt this work and if i put these alone (load one at a time) it works. I think the problem is in glTexParametri, but cant find it. Pls if you find what is wrong, answer... Thx, Xewren Edited by - Xewren on October 19, 2001 3:56:53 PM Edited by - Xewren on October 19, 2001 3:58:30 PM

Share this post


Link to post
Share on other sites
Basically, you have to loop through each texture and setup it up.
try this:

        
#define nTex 2 // 2 textures


GLuint texture[nTex];

int LoadTextures() // Load Bitmaps And Convert To Textures

{
int Status=FALSE; // Status Indicator

int i;

AUX_RGBImageRec *TextureImage[nTex]; // Create Storage Space For The Texture


memset(TextureImage,0,sizeof(void *)*nTex); // Set The Pointer To NULL


if ((TextureImage[0]= LoadBMP("Data/1.bmp")) &&
(TextureImage[1]= LoadBMP("Data/2.bmp")))
{
Status=TRUE; // Set The Status To TRUE


glGenTextures(nTex, &texture[0]);

for (i=0;i<nTex;i++) {
glBindTexture(GL_TEXTURE_2D, texture[i]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[i]->sizeX, TextureImage[i]->sizeY,
GL_RGB, GL_UNSIGNED_BYTE, TextureImage[i]->data);
}
}

for (i=0;i<nTex;i++) {
if (TextureImage[i]) // If Texture Exists

{
if (TextureImage[i]->data) // If Texture Image Exists

{
free(TextureImage[i]->data); // Free The Texture Image Memory

}

free(TextureImage[i]); // Free The Image Structure

}
}

return Status; // Return The Status

}


Scott

Edited by - wojtos on October 19, 2001 4:06:50 PM

Share this post


Link to post
Share on other sites
Very good looking code there... thx m8. Btw, how did you get that white area for your code???

Thanks a lot, now its easy to load all my textures nice and easy....

Xewren

Share this post


Link to post
Share on other sites
hey wojtos...

I cant make that code to work. it has something wrong in it?
I tried also without that mipmap-thing but nothing. what can i do?

Xewren

Share this post


Link to post
Share on other sites
Your PROBLEM is Solved !!

Fact 1
-> This should not happen (the binded texture at the end is Texture[1]). You need to know the use of glBindTexture.
glBindTexture(GL_TEXTURE_2D, texture[0]);
glBindTexture(GL_TEXTURE_2D, texture[1]);

You should ::

Bind Texture[0] then load the texture for it.
Bind Texture[1] then load the next texture.

hope it helps

Share this post


Link to post
Share on other sites
Just wanted to say next time you''re trying to figure out how someone did something on the board just click the edit button for that post. You won''t be able to make changes cause its not your post originally, but you''ll be able to see how it was written.

Share this post


Link to post
Share on other sites