• Advertisement
Sign in to follow this  

SDL_Surface keeps pixels from before

This topic is 1795 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 everyone,

 

I'm trying to load a few textures using this function:

int LoadTexture( const char* filename, GLuint textures[], int textureIndex, GLint textureFilter )
{
	// temporarily store the image as a surface
	SDL_Surface *surface = SDL_LoadBMP( filename );

	// if the image didn't load
	if ( surface == NULL )
	{
		return 0;
	}

	// create 1 texture
	glGenTextures( 1, &textures[textureIndex] );

	// bind texture so we can modify or use it
	glBindTexture( GL_TEXTURE_2D, textures[textureIndex] );

	// apply the texture filter
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, textureFilter );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, textureFilter );

	// if we need mipmaps created
	if ( textureFilter == GL_LINEAR_MIPMAP_NEAREST )
	{
		// generate bitmaps
		gluBuild2DMipmaps( GL_TEXTURE_2D, 3, surface->w, surface->h, GL_BGR_EXT, GL_UNSIGNED_BYTE, surface->pixels );
	}

	else
	{
		// generate the texture normally
		glTexImage2D ( GL_TEXTURE_2D, 0, 3, surface->w, surface->h, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, surface->pixels );
	}

	// free the surface
	SDL_FreeSurface( surface );

	// return ok
	return 1;
}

 

 

Every time I call this function with different images the surface->pixels pointer remains the same ( while other surface members change ), so I end up getting the same texture from the first call.

 

see:

[sharedmedia=core:attachments:13660]

 

I want the pixel data to change according to the image i'm loading. Any help appreciated

 

arigatou ^^

Share this post


Link to post
Share on other sites
Advertisement

yup! its correct.

 

it's the latest version ( 1.2.15 )

Edited by hikarihe

Share this post


Link to post
Share on other sites

solved ^.^'

 

the code is correct, but I had glBindTexture inside a glBegin...glEnd block, I guess you can't do that (^_^ ;)

Edited by hikarihe

Share this post


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

  • Advertisement