SDL2 Texture Render 目标没有 alpha 透明度

SDL2 Texture Render target doesn't have alpha transparency

我在使用 SDL2 在 C 上编程时遇到了问题。我已经渲染了一个纹理简单的正方形图像,这些图像在中心是透明的。但是当我绘制渲染它们的纹理时,它们不是透明的。我什至尝试用 SDL_SetTextureAlphaMod() 改变渲染纹理的透明度,但它没有改变任何东西。如果我更改正在渲染的纹理(正方形)上的 alpha。它们变暗了,但仍然遮住了身后的任何东西。所以我愿意接受建议。

这是我降低了正方形纹理上的 alpha 的图像:http://imgur.com/W8dNbBY

首先,如果你想要一个透明的图像,你在SDL2中有两种方法。


  • 方法一:(静态方法)

使用图片编辑软件,直接改变里面的alpha值,会延续到SDL2。


方法二:(动态法)

SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);//This sets the texture in blendmode

alpha = xx //this section should be where you alter the alpha value. You can make fade in-fade out effects, etc... Just put the changes here.

SDL_SetTextureAlphaMod(texture, alpha); //sets the alpha into the texture

SDL_RenderCopy(renderer, texture, NULL, &rect); //Redraws the image with a fresh, new alpha ~