Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


SDL & Alpha Blending

This topic is 6106 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i need to be able to change the alpha value for a surface every frame. To do this i need to do SDL_SetAlpha() every frame. If i do that, however, nothing shows up. So, after doing the SetAlpha(), i have to do SDL_DisplayFormat(surface). That slows things down about 75 fps! How can i fix this? Here's the sprite class (homemade) i'm using:
	SPRIZITE() { surface=NULL; }
	SPRIZITE(const char *file) { surface=NULL; loadFromFile(file); }
	void loadFromFile(const char *file)
		out << "Loading Sprite From File - " << file << ", version " << FileVersion(file) << endl;
		SDL_Surface *stemp;
		stemp = SDL_LoadBMP(file);
		surface = SDL_DisplayFormat(stemp);
		width = surface->w;
		height = surface->h;
		currAlpha = 255;
	void Draw(int x, int y)
		if(x >= SCREEN_WIDTH || x + width <= 0 || y >= SCREEN_HEIGHT || y + height <= 0)
		SDL_Rect r;
		r.x = x;
		r.y = y;
		r.w = 0;
		r.h = 0;
		SDL_BlitSurface(surface, NULL, pSurface, &r);
	void SetColorKey(Uint8 r, Uint8 g, Uint8 b)
		SDL_SetColorKey(surface, SDL_SRCCOLORKEY, SDL_MapRGB(surface->format, r, g, b));
	void SetAlpha(Uint8 fade)
		if(currAlpha == fade)
		SDL_SetAlpha(surface, SDL_SRCALPHA, fade);
		SDL_Surface *stemp = SDL_DisplayFormat(surface);
		surface = stemp;
		currAlpha = fade;

	SDL_Surface *surface;
	int height;
	int width;
	Uint8 currAlpha;
[EDIT] Posted Wrong Code :-) Edited by - MadProgrammer on February 1, 2002 8:23:45 PM

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!