|
Loading Multiple Textures!!!!!!
Please someone help me... I've just recently started using OGL and am close to killing my self!!! I've read & understood most of the tut's on NeHe's site, and can generate & use single textures from BMP's fine, but when I try to load a second, it displays the second texture twice. If I switch the order the BMP's are loaded, then the texture loaded second is repeated...
This is how Im loading the textures... and yes I am switching texture before drawing the next object... Help me!!!
Edited by - TheSyan on November 30, 2001 4:07:41 PM
Does TXT_BRICK == Textures[1] and TXT_BOARD == Textures[2] ?
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
I think you should try this:
AUX_RGBImageRec Image[2];
GLuint name[2];
glGenTextures(2,name);
Image[0] = auxDIBImageLoad("D:/My Documents/SIMON/PROGRAMMING/C++/Textures/Brick.bmp");
Image[1] =auxDIBImageLoad("D:/My Documents/SIMON/PROGRAMMING/C++/Textures/BackGround.bmp");
for(int i=0;i<=1;i++) {
glBindTexture(GL_TEXTURE_2D,name);
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,Image->sizeX, Image->sizeY,0,GL_RGB,GL_UNSIGNED_BYTE, Image->data);<br><br>} </i> <br><br>Edited by - Major on November 30, 2001 4:12:23 PM<br><br>Edited by - Major on November 30, 2001 4:43:32 PM
AUX_RGBImageRec Image[2];
GLuint name[2];
glGenTextures(2,name);
Image[0] = auxDIBImageLoad("D:/My Documents/SIMON/PROGRAMMING/C++/Textures/Brick.bmp");
Image[1] =auxDIBImageLoad("D:/My Documents/SIMON/PROGRAMMING/C++/Textures/BackGround.bmp");
for(int i=0;i<=1;i++) {
glBindTexture(GL_TEXTURE_2D,name);
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,Image->sizeX, Image->sizeY,0,GL_RGB,GL_UNSIGNED_BYTE, Image->data);<br><br>} </i> <br><br>Edited by - Major on November 30, 2001 4:12:23 PM<br><br>Edited by - Major on November 30, 2001 4:43:32 PM
TXT_BRICK equals the GLuint contained in Texture[1]. I was trying to cut out some code to see where the error was and hastly reverted to the original code before posting it... must of missed that bit , but it shouldn''t matter.
if you make an array like GLuint Texture[2] you got 2 elements
Texture[0] and Texture[1] not 1 and 2.
glGenTextures(1,&Textures[1]); should be glGenTextures(1,&Textures[0]);
glGenTextures(1,&Textures[2]); should be glGenTextures(1,&Textures[1]);
Edited by - Load Runner on November 30, 2001 4:28:28 PM
Edited by - Load Runner on November 30, 2001 4:30:00 PM
Texture[0] and Texture[1] not 1 and 2.
glGenTextures(1,&Textures[1]); should be glGenTextures(1,&Textures[0]);
glGenTextures(1,&Textures[2]); should be glGenTextures(1,&Textures[1]);
Edited by - Load Runner on November 30, 2001 4:28:28 PM
Edited by - Load Runner on November 30, 2001 4:30:00 PM
Romance is dead,it was bougth by Disney and Hallmark and sold to the public in small portions.
Oh...in the for instruction it's :
"glBindTexture(GL_TEXTURE_2D,name[j]);"
yes and GLuint Image[1];
Gluint name[1];
Edited by - Major on November 30, 2001 4:19:07 PM
"glBindTexture(GL_TEXTURE_2D,name[j]);"
yes and GLuint Image[1];
Gluint name[1];
Edited by - Major on November 30, 2001 4:19:07 PM
Thnx 4 the help Major & Load Runner... I've tryed what u've said, but it still does the same... Equally puzzling... If i try to bind to a non existant texture before drawing a quad( for example texture[5], yet only load 2) it still draws the texture loaded second?
Edited by - TheSyan on November 30, 2001 4:30:46 PM
Edited by - TheSyan on November 30, 2001 4:30:46 PM
ok i see your problem now
only call glGenTextures once, like this
glGenTextures(2, &Textures[0]); this creates 2 textures
and since you use the same filtering etc you can create a for loop instead of writing the code twise, like this
AUX_RGBImageRec *Image[2]; //you have to use an array
for (int loop=0; loop<2; loop++)
{
glBindTexture(GL_TEXTURE_2D, Textures[loop]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, Image[loop]->sizeX,Image[loop]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE,Image[loop]->data);
}
Edited by - Load Runner on November 30, 2001 4:45:27 PM
only call glGenTextures once, like this
glGenTextures(2, &Textures[0]); this creates 2 textures
and since you use the same filtering etc you can create a for loop instead of writing the code twise, like this
AUX_RGBImageRec *Image[2]; //you have to use an array
for (int loop=0; loop<2; loop++)
{
glBindTexture(GL_TEXTURE_2D, Textures[loop]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, Image[loop]->sizeX,Image[loop]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE,Image[loop]->data);
}
Edited by - Load Runner on November 30, 2001 4:45:27 PM
Romance is dead,it was bougth by Disney and Hallmark and sold to the public in small portions.
Then it would seem to me that the glBindTexture call is the culprit. As Fruny suggested:
My version of your code would be:
quote:
Does TXT_BRICK == Textures[1] and TXT_BOARD == Textures[2] ?
My version of your code would be:
|
Kippesoep
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement