Jump to content
  • Advertisement
Sign in to follow this  
distortion

SDL Transparent Rectangle

This topic is 4147 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 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, &rect, Working_color);
}

Does anyone know how I can draw a alpha'd rectangle to the screen so it doesn't cover everything underneath?

Share this post


Link to post
Share on other sites
Advertisement
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, &rect);

SDL_FreeSurface(sfc);
}


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!