gpt4 book ai didi

textures - 从多个纹理创建新纹理 SDL-2

转载 作者:行者123 更新时间:2023-12-02 18:57:53 28 4
gpt4 key购买 nike

我有几个纹理将在屏幕上保持静止。我不想在渲染时单独渲染每个纹理,而是希望将它们全部渲染为一个纹理。到目前为止我的代码如下所示:

SDL_Texture* target_texture = NULL;
SDL_SetRenderTarget(renderer, target_texture);
SDL_RenderCopy(renderer, texture1, NULL, &dst1);
SDL_RenderCopy(renderer, texture2, NULL, &dst2);
SDL_RenderCopy(renderer, texture3, NULL, &dst3);
.
.
.
SDL_SetRenderTarget(renderer, NULL);
SDL_RendererPresent(renderer);
// Here the screen displays as I want
SDL_Delay(2000);
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, target_texture, NULL, NULL);
SDL_RendererPresent(renderer);
// Here the screen is black as though target_texture is still NULL

最佳答案

您必须创建您的 target_texture,目前它始终为 NULL。将第一行替换为:

target_texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, target_width, target_height);

关于textures - 从多个纹理创建新纹理 SDL-2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20730900/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com