0
컬러 키잉을 사용하여 SDL에서 투명성을 얻으려고합니다. BMP 파일에서는 작동하지만 PNG 파일에서는 작동하지 않습니다. 내가 코드와 이미지를 모두 업로드 한SDL_image 및 PNG 파일에서 색상 키 투명도가 작동하지 않습니다.
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
int main(int argc, char *argv[])
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Surface *displaySurface = SDL_SetVideoMode(200, 100, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
SDL_Surface *tmpSurface = NULL;
SDL_Surface *backgroundSurface = NULL;
SDL_Surface *bmpSurface = NULL;
SDL_Surface *pngSurface = NULL;
tmpSurface = IMG_Load("background.png");
backgroundSurface = SDL_DisplayFormat(tmpSurface);
SDL_FreeSurface(tmpSurface);
tmpSurface = SDL_LoadBMP("bmpImage.bmp");
bmpSurface = SDL_DisplayFormat(tmpSurface);
SDL_FreeSurface(tmpSurface);
SDL_SetColorKey(bmpSurface, SDL_SRCCOLORKEY | SDL_RLEACCEL, SDL_MapRGB(bmpSurface->format, 255, 0, 255));
tmpSurface = IMG_Load("pngImage.png");
pngSurface = SDL_DisplayFormat(tmpSurface);
SDL_FreeSurface(tmpSurface);
SDL_SetColorKey(pngSurface, SDL_SRCCOLORKEY | SDL_RLEACCEL, SDL_MapRGB(pngSurface->format, 255, 0, 255));
SDL_Rect dest;
dest.x = 0;
dest.y = 0;
SDL_BlitSurface(backgroundSurface, NULL, displaySurface, &dest);
SDL_BlitSurface(bmpSurface, NULL, displaySurface, &dest);
dest.x = 50;
SDL_BlitSurface(pngSurface, NULL, displaySurface, &dest);
SDL_Flip(displaySurface);
SDL_Event event;
while (1) {
while (SDL_PollEvent(&event)) {
;
}
SDL_Delay(1);
}
return 0;
}
내가 여기에 사용하고 있습니다 :
http://tobias.braun-abstatt.de/files/forums/transparency_test.zip
버전 1.2.15를 사용하고 있습니다. – tajmahal
SDL과 SDL_image는 다른 라이브러리입니다 (적어도 Linux에서는). 최신 SDL은 1.2.15이고 최신 SDL_image는 1.2.12입니다. 내 대답의 소스 코드를 컴퓨터에서 성공적으로 컴파일 할 수 있습니까? –
어, 네 말이 맞아. 실수로 SDL_image 버전 대신 SDL 버전을 확인했지만 코드를 시도하지 않았습니다. 물론 시스템의 SDL_image 버전은 1.2.10이었습니다. 이제 1.2.12로 업그레이드 했으므로 작동 중입니다. 고맙습니다! – tajmahal