Skip to main content
GameDev.net gamedev.net
🔒 Locked

texture and linked lists

Started by knobby67 Mar 22, 2007 at 4:37 AM 1 replies 1k views
Original Post
knobby67
knobby67
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

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;
}
 
can anyone advise? [Edited by - knobby67 on March 22, 2007 5:41:38 AM]
ToohrVyk
ToohrVyk
Put your code between [source][/source] statements.

OpenGL is a state machine. The texture used is the last texture set. If you want to use a texture, you have to set it again before you use it.

Also, watch out for the ownership of name: either create a copy of it, or somehow specify that the function will assume ownership of the buffer.
knobby67
knobby67
Damn found it, nothing wrong with the loader I was calling




glBegin(GL_TRIANGLES);
glBindTexture(GL_TEXTURE_2D, object->texture->id);

inside glBegin()
Has to be called before.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.