SDL HUD Problem

Anything related in any way to game development as a whole is welcome here. Tell us about your game, grace us with your project, show us your new YouTube video, etc.

Moderator: PC Supremacists

Post Reply
RandomDever
Chaos Rift Regular
Chaos Rift Regular
Posts: 198
Joined: Thu Mar 26, 2009 8:42 pm
Current Project: My Engine
Programming Language of Choice: C++

SDL HUD Problem

Post 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. :)
User avatar
hurstshifter
ES Beta Backer
ES Beta Backer
Posts: 713
Joined: Mon Jun 08, 2009 8:33 pm
Favorite Gaming Platforms: SNES
Programming Language of Choice: C/++
Location: Boston, MA
Contact:

Re: SDL HUD Problem

Post 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.
"Time is an illusion. Lunchtime, doubly so."
http://www.thenerdnight.com
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: SDL HUD Problem

Post 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.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
RandomDever
Chaos Rift Regular
Chaos Rift Regular
Posts: 198
Joined: Thu Mar 26, 2009 8:42 pm
Current Project: My Engine
Programming Language of Choice: C++

Re: SDL HUD Problem

Post 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.
Hyppo
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 11
Joined: Wed Dec 03, 2008 5:51 am

Re: SDL HUD Problem

Post 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
RandomDever
Chaos Rift Regular
Chaos Rift Regular
Posts: 198
Joined: Thu Mar 26, 2009 8:42 pm
Current Project: My Engine
Programming Language of Choice: C++

Re: SDL HUD Problem

Post 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.
Post Reply