SDL 纹理透明背景
SDL Texture transparent background
这可能是一个相当简单的问题,但是经过一个小时的搜索和尝试,我仍然无法解决它。我有两个 png 文件。一个是背景图像,第二个是前景。前景有一个 alpha 通道。我想在背景顶部显示前景。
我正在使用以下内容加载前台:
SDL_Surface *clip = SDL_CreateRGBSurface(0, SCREEN_WIDTH, SCREEN_HEIGHT, 32, 0, 0, 0, 0xff);
SDL_Rect rect = { x, 0, SCREEN_WIDTH, SCREEN_HEIGHT };
SDL_BlitSurface(map, &rect, clip, NULL);
*block = SDL_CreateTextureFromSurface(gRenderer, clip);
地图是一些SDL_Surface。
我正在使用以下内容加载背景:
SDL_Surface* loadedSurface = IMG_Load(path);
//Create texture from surface pixels
SDL_Texture* newTexture = SDL_CreateTextureFromSurface(gRenderer, loadedSurface);
SDL_FreeSurface(loadedSurface);
然后我尝试连接它们:
SDL_RenderCopy(gRenderer, background, NULL, &cur);
SDL_RenderCopy(gRenderer, map, NULL, &cur);
但它会产生带有黑色背景的前景图像。我做错了什么?
你应该添加这 2 行,
Uint32 colorkey = SDL_MapRGB(loadedSurface->format, 0, 0, 0);
SDL_SetColorKey(loadedSurface, SDL_TRUE, colorkey);
在代码中的此行之前
SDL_Texture* newTexture = SDL_CreateTextureFromSurface(gRenderer, loadedSurface);
相关文章:
- 如何在全屏模式下(在OpenGL中)使背景透明
- SDL2 透明背景
- 一个标签,其背景一方面是透明的,另一方面是上部窗口
- 调整HBITMAP的大小,同时保持透明背景
- 当我使用 DirectWrite 在 GDI hdc 上绘制文本时,如何设置透明背景
- 通过使用alpha混合opengl实现具有透明背景的纹理
- 如何使用 c++/WinAPI 绘制具有透明背景的文本
- Qt透明QWebView:过去的页面停留在新页面的背景中
- OpenFrameworks中的透明背景窗口
- C++libPng 编写一个具有透明背景的 PNG
- QWebEngine页面中的透明背景
- SDL 纹理透明背景
- ID2D1HwndRenderTarget始终具有黑色背景而不是透明
- 使用C++/OpenCV或Matlab将图像的白色背景替换为透明背景
- 透明背景的C++按钮
- MFC显示具有透明背景的png
- 如何在QT中使背景半透明
- 如何使我的纹理背景透明?(我的图像已经没有背景了)
- Q获取背景透明
- 如何使分组框文本背景透明