0
다음 코드는 검정색 배경에 녹색 사각형을 표시하기위한 것입니다. 실행되지만 녹색 사각형이 표시되지 않습니다. 그러나 SDL_DisplayFormatAlpha
을 SDL_DisplayFormat
으로 변경하면 사각형이 올바르게 렌더링됩니다.SDL_DisplayFormat는 작동하지만 SDL_DisplayFormatAlpha는 작동하지 않습니다.
그래서 이해가 안되나요? 알파 마스크를 사용하여 *surface
을 만들고 있는데 내 녹색 색상을 매핑하는 데 SDL_MapRGBA
을 사용하고 있으므로 SDL_DisplayFormatAlpha
을 사용하는 것이 일관성이 있습니다.
#include <SDL.h>
int main(int argc, const char *argv[])
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Surface *screen = SDL_SetVideoMode(
640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF
);
SDL_Surface *temp = SDL_CreateRGBSurface(
SDL_HWSURFACE, 100, 100, 32, 0, 0, 0,
(SDL_BYTEORDER == SDL_BIG_ENDIAN ? 0x000000ff : 0xff000000)
);
SDL_Surface *surface = SDL_DisplayFormatAlpha(temp);
SDL_FreeSurface(temp);
SDL_FillRect(
surface, &surface->clip_rect, SDL_MapRGBA(
screen->format, 0x00, 0xff, 0x00, 0xff
)
);
SDL_Rect r;
r.x = 50;
r.y = 50;
SDL_BlitSurface(surface, NULL, screen, &r);
SDL_Flip(screen);
SDL_Delay(1000);
SDL_Quit();
return 0;
}