Skip to main content
GameDev.net gamedev.net
🔒 Locked

SDL Transparent Rectangle

Started by distortion Feb 13, 2007 at 7:35 PM 0 replies 4.2k views
Original Post
distortion
distortion
I want to draw a transparent rectangle to the screen over what's already there. I set the alpha value of the color to 0xCC, but the rectangle still shows up solid.

// Set the system color's RGBA value.
void sys_set_color(uint r, uint g, uint b, uint a) {
	g = g << 8;
	b = b << 16;
	a = a << 24;
	Working_color = (r | g | b | a);
}

// Draw a rectangle in the current system color.
void sys_draw_rect(uint x, uint y, uint w, uint h)
{
	SDL_Rect rect;
	rect.x = x;
	rect.y = y;
	rect.w = w;
	rect.h = h;
	SDL_FillRect(Main_screen, ▭, Working_color);
}

Does anyone know how I can draw a alpha'd rectangle to the screen so it doesn't cover everything underneath?
distortion
distortion
As it turns out, "If the color value contains an alpha value then the destination is simply "filled" with that alpha information, no blending takes place."

Devised an alternate solution. If anyone's interested, I changed sys_draw_rect as follows:

// Draw a rectangle in the current system color.void sys_draw_rect(uint x, uint y, uint w, uint h){	uint alpha = (Working_color >> 24);	SDL_Surface *sfc = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_ANYFORMAT, w, h, Main_screen->format->BitsPerPixel, 0, 0, 0, 0);	SDL_FillRect(sfc, NULL, Working_color);	SDL_SetAlpha(sfc, SDL_SRCALPHA, alpha);	SDL_Rect rect;	rect.x = x;	rect.y = y;	rect.w = w;	rect.h = h;	SDL_BlitSurface(sfc, NULL, Main_screen, ▭);	SDL_FreeSurface(sfc);}

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.