Original Post
Hi all :), I've been doing some code to produce a linked list of textures, so I can check for repeat textures used on models. However when I draw the model the only texture used is the last one loaded. For example if I load a model with 2 textures only texture 2 is drawn over the whole model. I know my linked list is correct as my debug gives out traverse 1 name EARTH.BMP id 1 x 512 y 256 traverse 2 name TEXT.BMP id 2 x 512 y 512 so bmp earth and text have been loaded the id is the texture number, so if I use glBindTexture(GL_TEXTURE_2D, 2); /*in real will load from list*/ it should use the text bmp? glBindTexture(GL_TEXTURE_2D, 1); should use the earth bmp ? However it only ever shows the last texture loaded. The Texture loader is a simple SDL loader which loads the data onto a lined list. A below can anyone advise? [Edited by - knobby67 on March 22, 2007 5:41:38 AM]
int TestLoadTexture(char *name)
{
texture temp; /* temp node */
SDL_Surface *surface; /* This surface will tell us the details of the image */
/************************Linked List of textures to check for repeat textures *************************/
/******************************************************************************************************/
if ((surface = IMG_Load(name)))
{
/* Check that the image's width is a power of 2 */
if ( ((surface->w & (surface->w - 1)) != 0) || ( (surface->h & (surface->h - 1)) != 0 ))
{
printf("texture incorrect size for openGL \n");
}
/**************load onto temp node****************************/
temp.x_size=surface->w;
temp.y_size=surface->h;
temp.name=name;
/* use temp node to store texture id and generate*/
glGenTextures( 1, &temp.texture_id );
/*bind object */
glBindTexture( GL_TEXTURE_2D, temp.texture_id);
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, surface->w, surface->h, 0,GL_BGR, GL_UNSIGNED_BYTE, surface->pixels );
}
else
{
printf("No Texture file avalible %s\n", SDL_GetError());
SDL_Quit();
exit(0) ;
}
/* Free the SDL_Surface only if it was successfully created */
if ( surface )
{
SDL_FreeSurface( surface );
}
/***********put on end of linked list******************************************/
addtexture_end(&TextureNode,temp);
return 1;
}