Jump to content

  • Log In with Google      Sign In   
  • Create Account

C++ SDL Image Alpha Problem


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
2 replies to this topic

#1 shadowgamesco   Members   -  Reputation: 326

Like
0Likes
Like

Posted 10 February 2011 - 07:37 PM


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:

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;
	
}

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.


Sponsor:

#2 Wooh   Members   -  Reputation: 627

Like
1Likes
Like

Posted 10 February 2011 - 08:05 PM

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.

#3 BeerNutts   Crossbones+   -  Reputation: 2950

Like
1Likes
Like

Posted 11 February 2011 - 10:46 AM

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.
My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)




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.



PARTNERS