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

时间:2016-11-30 10:47:24

标签: c++ c image textures sdl

在我的代码中,我想将多个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

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

你需要创建你的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);