1

我正在尝试获得一个透明的 SDL_Surface (在其上粘贴半透明矩形),这就是我所做的:

surface := SDL_CreateRGBSurface(SDL_SWSURFACE, XMAX*TILE_SIZE,
YMAX*TILE_SIZE, BPP, 0, 0, 0, SDL_ALPHA_TRANSPARENT);
SDL_FillRect(surface, nil, SDL_MapRGBA(surface^.format, 0, 0, 0, 0));

这仍然不起作用,我得到的表面是黑色而不是透明的。任何想法?

奖励:为了避免多个半透明矩形相互重叠,有什么办法可以删除这些矩形,然后对新的矩形进行 blit(无需再次对背景进行 blitting ...)?

4

1 回答 1

0

From looking at the docs for SDL_CreateRGBSurface, I think you need to replace SDL_SWSURFACE with SDL_SRCALPHA.

For the bonus part, you might try first to get hardware acceleration working... But if that's not an option and you're willing to spend some memory:

  • First, before drawing a rectangle, make a copy of the pixels underneath it.

  • To erase the topmost rectangle you simply re-blit the stored background image.

  • To erase any other rectangle, you re-blit its background, then redraw the overlapping portions of the rectangles on top of it from back to front.

于 2012-05-04T17:50:48.680 回答