Jump to content
  • Advertisement
Sign in to follow this  
knobby67

OpenGL texture and linked lists

This topic is 4232 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!