设置sdl_blendmode_blend上的纹理中断渲染质量

发布于 2025-02-06 17:08:58 字数 1145 浏览 1 评论 0原文

我正在尝试创建纹理A,使其透明,然后将纹理b呈现给纹理A。问题是要使纹理成为透明的,我必须首先设置sdl_blendmode_blend the纹理上的打破纹理B渲染的方式。解决问题时,我想对纹理A呈现多种纹理。

纹理B包含一个白色的“新游戏”文本。蓝色背景分别渲染。

这是正确结果的图像,呈现纹理b直接

“

这是我没有呈现质地的图像设置SDL_BLENDMODE_BLEND。 “

这是我将渲染纹理a带有设置sdl_blendmode_blend的图像。 “

我注意到使用sdl_setrenderdrawcolor(r,255,255,255,255,0);> 如果文本为白色,则纹理b可以正确地呈现,但是当文本为黑色时,它会呈现错误。

    texA = SDL_CreateTexture(r, SDL_PIXELFORMAT_RGBA8888,
                             SDL_TEXTUREACCESS_TARGET,
                             mWidth, mHeight);

    SDL_SetRenderTarget(r, texA);

    // breaks texB rendering, necessary to make texture transparent
    SDL_SetTextureBlendMode(texA, SDL_BLENDMODE_BLEND);

    SDL_SetRenderDrawBlendMode(r, SDL_BLENDMODE_NONE);
    SDL_SetRenderDrawColor(r, 0, 0, 0, 0);
    SDL_RenderFillRect(r, NULL);

    SDL_RenderCopy(r, texB, NULL, NULL);

    SDL_SetRenderTarget(r, nullptr);

I'm trying to create a texture A, make it transparent, and then render a texture B to the texture A. The problem is that to make the texture A transparent I have to first set SDL_BLENDMODE_BLEND on the texture A, which, sadly, breaks the way the texture B is being rendered. I want to render multiple textures to the texture A, when I resolve the issue.

The texture B contains a white "New Game" text. The blue background is rendered separately.

Here is an image of the correct result, rendering texture B directly

1

Here is an image of what I get rendering texture A without setting SDL_BLENDMODE_BLEND.
2

Here is an image of what I get rendering texture A with setting SDL_BLENDMODE_BLEND.
3

I noticed that when using SDL_SetRenderDrawColor(r, 255, 255, 255, 0); the texture B renders correctly, if the text is white, but it renders incorrectly when the text is black.

    texA = SDL_CreateTexture(r, SDL_PIXELFORMAT_RGBA8888,
                             SDL_TEXTUREACCESS_TARGET,
                             mWidth, mHeight);

    SDL_SetRenderTarget(r, texA);

    // breaks texB rendering, necessary to make texture transparent
    SDL_SetTextureBlendMode(texA, SDL_BLENDMODE_BLEND);

    SDL_SetRenderDrawBlendMode(r, SDL_BLENDMODE_NONE);
    SDL_SetRenderDrawColor(r, 0, 0, 0, 0);
    SDL_RenderFillRect(r, NULL);

    SDL_RenderCopy(r, texB, NULL, NULL);

    SDL_SetRenderTarget(r, nullptr);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

离线来电— 2025-02-13 17:08:58

解决方案是创建自定义混合模式。偶然发现了这一点,所以我不确定为什么有效。

texA = SDL_CreateTexture(r, SDL_PIXELFORMAT_RGBA8888,
                         SDL_TEXTUREACCESS_TARGET,
                         mWidth, mHeight);

SDL_SetRenderTarget(r, texA);

const auto bm = SDL_ComposeCustomBlendMode(
                        SDL_BLENDFACTOR_ONE,
                        SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
                        SDL_BLENDOPERATION_ADD,

                        SDL_BLENDFACTOR_ONE,
                        SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
                        SDL_BLENDOPERATION_ADD);
SDL_SetTextureBlendMode(texA, bm);

SDL_SetRenderDrawBlendMode(r, SDL_BLENDMODE_NONE);
SDL_SetRenderDrawColor(r, 0, 0, 0, 0);
SDL_RenderFillRect(r, NULL);

SDL_RenderCopy(r, texB, NULL, NULL);

SDL_SetRenderTarget(r, nullptr);

The solution was to create a custom blend mode. Figured that out by accident, so I'm not sure why that works.

texA = SDL_CreateTexture(r, SDL_PIXELFORMAT_RGBA8888,
                         SDL_TEXTUREACCESS_TARGET,
                         mWidth, mHeight);

SDL_SetRenderTarget(r, texA);

const auto bm = SDL_ComposeCustomBlendMode(
                        SDL_BLENDFACTOR_ONE,
                        SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
                        SDL_BLENDOPERATION_ADD,

                        SDL_BLENDFACTOR_ONE,
                        SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
                        SDL_BLENDOPERATION_ADD);
SDL_SetTextureBlendMode(texA, bm);

SDL_SetRenderDrawBlendMode(r, SDL_BLENDMODE_NONE);
SDL_SetRenderDrawColor(r, 0, 0, 0, 0);
SDL_RenderFillRect(r, NULL);

SDL_RenderCopy(r, texB, NULL, NULL);

SDL_SetRenderTarget(r, nullptr);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文