如何在 SDL2 中连接多个纹理?

How to connect multiple textures in the one in SDL2?

在我的代码中,我想将多个 SDL_Texture 或数组连接(或合并)为一个 SDL_Texture,其中将包含每张图片放在另一张下面的图片。

它可能看起来像这样

SDL_Texture* t1 = SDL_CreateTextureFromSurface(my_renderer, someSurface);
SDL_Texture* t2 = SDL_CreateTextureFromSurface(my_renderer, someOtherSurface);
//Some SDL code manipulations to make one SDL_Texture wich contains t1 and t2

有什么建议吗?

您需要创建您的 target_texture 或类似这样的内容:

SDL_Texture* target_tex =SDL_CreateTexture(.....); //Add arg according to you
SDL_SetRenderTarget(my_renderer, target_tex);

SDL_Texture* t1 = SDL_CreateTextureFromSurface(my_renderer, someSurface);
SDL_Texture* t2 = SDL_CreateTextureFromSurface(my_renderer, someOtherSurface);
.
.
.
.
SDL_RenderCopy(my_renderer, t1, NULL, NULL);
SDL_RenderCopy(my_renderer, t2, NULL, NULL);
SDL_RenderCopy(my_renderer, t3, NULL, NULL);
.
.
.
SDL_SetRenderTarget(my_renderer, NULL);
SDL_RendererPresent(my_renderer);


SDL_RenderClear(my_renderer);
SDL_RenderCopy(my_renderer, target_tex, NULL, NULL);
SDL_RendererPresent(my_renderer);