Page 1 of 1
SDL HUD Problem
Posted: Thu Aug 26, 2010 3:07 am
by RandomDever
So I'm making a little GUI box that holds an integer and based on that integer it blits a certain amount of images.
However i want all the images to be applied to a SDL_Surface *buffer before being blitted to the screen.
But every time I do that it gives me some random access violation.
Is what i'm trying to do possible?
If so how?
Thanks in advance for any provided help.
Re: SDL HUD Problem
Posted: Thu Aug 26, 2010 8:56 am
by hurstshifter
RandomDever wrote:
Is what i'm trying to do possible?
If so how?
Everything is possible...
Post some code dude, we need a little more to help you out with this.
Re: SDL HUD Problem
Posted: Thu Aug 26, 2010 9:35 am
by dandymcgee
RandomDever wrote:However i want all the images to be applied to a SDL_Surface *buffer before being blitted to the screen.
Just out of curiosity, why would want this? The only two reasons I can think of is to either save the intermediate surface if it won't change in the future, or you're attempting double buffering. In the case of the former, we definitely need to see some code before we can attempt to troubleshoot. In the case of the latter, SDL has double buffering built in, just enable it.
Re: SDL HUD Problem
Posted: Thu Aug 26, 2010 4:25 pm
by RandomDever
Well i will post some code but first an explanation of why.
I want to have images display a count of for instance bullets that the player has in his clip.
But I also want it centered within an SDL_Rect and I already have a function for getting a surface centered withing a Rect.
And the only way I can think of doing that is blitting as many images I need to a buffer and then center blitting the buffer.
But here's the problem:
Code: Select all
//SDL_Rect temp;
//SDL_Surface *dataType;
//SDL_Surface *dataBuffer;
//int dataNum;
//dataType is loaded with the image to display and dataNum is passed a number in the update function.
for( int i = 0; i < dataNum - 1; i++ )
{
temp.x = 0 + ( dataType->w * i );
temp.y = 0;
SDL_BlitSurface( dataType, NULL, dataBuffer, temp );
}
When I try to do that it fives me some error.
I hope my response was adequate.
Re: SDL HUD Problem
Posted: Fri Aug 27, 2010 3:47 pm
by Hyppo
Simple, dataBuffer is never initialized
use:
Code: Select all
dataBuffer=SDL_CreateRGBSurface(SDL_SWSURFACE,width,height,bpp,0,0,0,0);
before any function calls to dataBuffer
Re: SDL HUD Problem
Posted: Sun Aug 29, 2010 1:06 am
by RandomDever
Code: Select all
dataBuffer = SDL_CreateRGBSurface( SDL_SWSURFACE | SDL_SRCCOLORKEY, ( dataType->w * data ), dataType->h, 32, 0, 0, 0, 0 );
SDL_FillRect( dataBuffer, NULL, SDL_MapRGB( video->screen->format, 255, 0, 255 ) );
SDL_SetColorKey( dataBuffer, SDL_SRCCOLORKEY, SDL_MapRGB( video->screen->format, 255, 0, 255 ) );
Thank you for your help Hyppo.
Yeah I don't know why I thought I could blit to a null pointer but yeah. Thanks.