Jump to content

View more

Image of the Day

Working on an auto spawn system. #gamedev #indiedev #screenshotsaturday https://t.co/Mm2kfekz7b
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

SDL_Surface keeps pixels from before

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
3 replies to this topic

#1 hikarihe   Members   

243
Like
0Likes
Like

Posted 17 February 2013 - 01:31 AM

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:

surface.jpg

 

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

 

arigatou ^^

Attached Thumbnails

  • surface.jpg


#2 Sik_the_hedgehog   Members   

3002
Like
0Likes
Like

Posted 17 February 2013 - 02:19 AM

I don't think that's supposed to happen o_O Is the size of the second surface (the w and h values) correct, just to make sure? 1674×79 looks like a really weird size.

 

What SDL version is this?


Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.

#3 hikarihe   Members   

243
Like
0Likes
Like

Posted 17 February 2013 - 02:40 AM

yup! its correct.

 

it's the latest version ( 1.2.15 )


Edited by hikarihe, 17 February 2013 - 02:46 AM.


#4 hikarihe   Members   

243
Like
0Likes
Like

Posted 17 February 2013 - 07:57 AM

solved ^.^'

 

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


Edited by hikarihe, 17 February 2013 - 07:57 AM.





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.