[SDL] fastest way to draw transparent box
Loren Osborn
linux_dr at yahoo.com
Wed Oct 2 10:13:01 PDT 2002
actually, if it is a SDL_SWSURFACE, the wastest thing to do if you want
a gray-alpha box is probably:
for 50%
Uint32 mask = (surface->format->Rmask & (surface->format->Rmask >> 1))
| (surface->format->Gmask & (surface->format->Gmask >> 1))
| (surface->format->Bmask & (surface->format->Bmask >> 1));
then for each pixel:
pixel = (pixel >> 1) & mask;
for 75%
Uint32 mask1 =
(surface->format->Rmask & (surface->format->Rmask >> 1))
| (surface->format->Gmask & (surface->format->Gmask >> 1))
| (surface->format->Bmask & (surface->format->Bmask >> 1));
Uint32 mask2 =
(surface->format->Rmask & (surface->format->Rmask >> 2))
| (surface->format->Gmask & (surface->format->Gmask >> 2))
| (surface->format->Bmask & (surface->format->Bmask >> 2));
then for each pixel:
pixel = ((pixel >> 1) & mask1)+((pixel >> 2) & mask2);
For an SDL_HWSURFACE, the blitting a surface with a surface alpha is
probably fastest...
Cheers,
-Loren
On Tue, 2002-10-01 at 23:20, patrick at 2dgame-tutorial.com wrote:
> Yes it is, because alphablending is often hardware-supported on video-cards. Make sure however
> that no conversion has to be done by making the surface' format equal to the screens' Call
> SDL_CreateRGBsurface wisely...
>
> Patrick.
>
> Chris Thielen chris at luethy.net schreef:
>
> >hey sdlers,
> > i want to draw a simple transparent grey box, at like, 25%-50%
> >transparency on my main screen surface and was wondering what the
> >fastest way to do this is? the program runs on a 16bpp display, is
> >creating a surface, filling it grey, and setting the alpha the fastest
> >way to do it? wouldn't this be slow to blit 40-50 times per second? is
> >there a faster way to do it, maybe do the pixel calculations myself
> >since it's just a solid color i want?
> >
> >-- chris (chris at luethy.net)
> >
> >
> >_______________________________________________
> >SDL mailing list
> >SDL at libsdl.org
> >http://www.libsdl.org/mailman/listinfo/sdl
>
>
>
> _______________________________________________
> SDL mailing list
> SDL at libsdl.org
> http://www.libsdl.org/mailman/listinfo/sdl
More information about the SDL
mailing list