Advertisement

Loading Multiple Textures!!!!!!

Started by November 30, 2001 02:51 PM
14 comments, last by TheSyan 23 years, 2 months ago
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...
  
AUX_RGBImageRec *Image=NULL, *Image1=NULL;
	Image = auxDIBImageLoad("D:/My Documents/SIMON/PROGRAMMING/C++/Textures/Brick.bmp");
	glGenTextures(1,&Textures[1]);
	glBindTexture(GL_TEXTURE_2D, TXT_BRICK);
	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);
	if (Image)
	{
		if (Image->data)
		{
			free(Image->data);
		}
		free(Image);
	}
	
	Image1 = auxDIBImageLoad("D:/My Documents/SIMON/PROGRAMMING/C++/Textures/BackGround.bmp");
	glGenTextures(1,&Textures[2]);
	glBindTexture(GL_TEXTURE_2D, TXT_BOARD);
	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,Image1->sizeX, Image1->sizeY,0,GL_RGB,GL_UNSIGNED_BYTE, Image1->data);
	if (Image1)
	{
		if (Image1->data)
		{
			free(Image1->data);
		}
		free(Image1);
	}
  
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
Advertisement
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
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
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
Advertisement
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
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
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:
quote:

Does TXT_BRICK == Textures[1] and TXT_BOARD == Textures[2] ?


My version of your code would be:

  //Load imagesAUX_RGBImageRec *Image [2];Image [0] = auxDIBImageLoad("D:/My Documents/SIMON/PROGRAMMING/C++/Textures/Brick.bmp");Image [1] = auxDIBImageLoad("D:/My Documents/SIMON/PROGRAMMING/C++/Textures/BackGround.bmp");//Generate texture namesGLuint Textures [2];glGenTextures(2, Textures);for (int i = 0; i < 2; i++){    //Check image    if (!Image [i] || !Image [i]->data)    {        cout << "Error!";        if (Image [i]) free (Image [i]);        continue;    }    //Bind appropriate texture image    glBindTexture (GL_TEXTURE_2D, Textures [i]);    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);    //Release texture data    free(Image->data);    free(Image);}  
Kippesoep
Oh i make an other change to my example...
as said Load Runner I have to change my for instruction and I do this: for(int i=0;i<=2;i++); ....
and in fact it''s for(int i=0;i<=1;i++);
sorry for this

This topic is closed to new replies.

Advertisement