Sign in to follow this  
cbreiny

C++ SDL Image Alpha Problem

Recommended Posts

cbreiny    327
[font="Arial"][size="3"][size="2"][font="arial, verdana, tahoma, sans-serif"][size="2"][font="Arial"][size="3"][size="3"][size=2]
Okay so I am making an old school RPG-like game. For the map background I am using a tile engine that I wrote myself. Every frame it blits only the tiles that are around the player to the screen, but when I try to blit the tiles that need to have transparency around them (such as a tree), it slows the game down and it lags horribly, but when I blit the same tiles without transparency, the games runs perfectly smooth. Here is my image loading function:

[code]
SDL_Surface *load_image( std::string filename, bool ALPHA=false ) {

SDL_Surface *get_img = IMG_Load( filename.c_str() );
SDL_Surface *loaded_img;

if( ALPHA )
loaded_img = SDL_DisplayFormatAlpha( get_img );
else
loaded_img = SDL_DisplayFormat( get_img );
SDL_FreeSurface( get_img );

return loaded_img;

}
[/code]

So if I put 'true' in for the second argument, then it will load the image with its transparency, and slows the game down. But if I put 'false', then it doesn't load with transparency and my game runs perfectly. Why is this? And what can I do to solve this? Thanks in advance.[/size][/size][/size][/font][/size][/font][/size][/size][/font]

Share this post


Link to post
Share on other sites
Wooh    1088
Using alpha is slower so it's nothing strange that you experiencing slow down. To speed it up you could try to use hardware surfaces if you not already does that. You can consider using some kind of dirty rectangle system so that you only draw what has to be updated. Or you could use OpenGL

If you don't need a full alpha channel you can use a colorkey which is much faster.

Share this post


Link to post
Share on other sites
BeerNutts    4400
You may want to look into SFML instead of SDL for graphics. SFML is integrated with OpenGL, so it implicilty uses HW acceleration, whereas SDL implicitly does it in SW.

It shouldn't be a hard change assuming you've abstracted out your graphics properly.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this