我实际上试图在一个完全透明的窗口上显示一个.png图像(带有透明背景)但是当我执行我的程序时,我的图像是黑色背景。
不知道如何移除这个黑色层。
提前致谢
int main(void)
{
bool quit = false;
SDL_Event event;
SDL_Window *window;
SDL_Renderer *renderer;
SDL_Surface *image;
SDL_Texture *texture;
struct dirent **fileslist;
char **state;
char locationimg[15];
checkfiles();
scandir("img/", &fileslist, 0, alphasort);
states(&state);
if (SDL_Init(SDL_INIT_VIDEO) != 0)
{
fprintf(stdout, "Initialisation of SDL failed (%s)\n", SDL_GetError());
return (-1);
}
window = SDL_CreateWindow("test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 128, 128, SDL_WINDOW_BORDERLESS);
if (!window)
fprintf(stderr, "Error in creation of window: %s\n", SDL_GetError());
renderer = SDL_CreateRenderer(window, -1, 0);
strcpy(locationimg, "img/");
image = IMG_Load(strcat(locationimg, fileslist[state[0][0]]->d_name));
texture = SDL_CreateTextureFromSurface(renderer, image);
if (!image)
{
fprintf(stderr, "IMG_Load: %s\n", IMG_GetError());
return (-1);
}
while (!quit)
{
SDL_WaitEvent(&event);
switch (event.type)
{
case SDL_MOUSEBUTTONDOWN:
quit = true;
break;
}
SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderPresent(renderer);
}
SDL_DestroyTexture(texture);
SDL_FreeSurface(image);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return (0);
}