我在使用 SDL2 进行 C 语言编程时遇到了问题。我已将中心透明的正方形的简单图像渲染为纹理。但是当我绘制渲染它们的纹理时,它们并不透明。我什至尝试使用 SDL_SetTextureAlphaMod() 更改渲染纹理的透明度,但它没有改变任何内容。如果我更改正在渲染的纹理(方块)的 alpha 值。它们变得更暗,但它们仍然覆盖了它们后面的任何东西。所以我愿意接受建议。
这是一张图像,我降低了正方形纹理上的 alpha: https: //i.stack.imgur.com/46HAz.jpg
如果你想要透明图像,在 SDL2 中有两种方法:
(静态方法)
使用图像编辑软件并直接更改其中的alpha值,它将继续到SDL2。
(动态法)
// This sets the texture in blendmode.
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
// This section should be where you alter the alpha.
// You can make fade in-fade out effects, etc... Just put the changes here.
Uint8 alpha = 0x7F;
// Sets the alpha into the texture.
SDL_SetTextureAlphaMod(texture, alpha);
// Redraws the image with a fresh, new alpha.
SDL_RenderCopy(renderer, texture, NULL, &rect);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3025 次 |
| 最近记录: |