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

标签 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

有什么建议吗?

最佳答案

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

关于c++ - 如何在 SDL2 中连接多个纹理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40886350/

相关文章:

c++ - 在 Windows C++ 中使用 fileIO

c++ - 声明和初始化的问题

c - 如何在Linux环境下使用C chdir

c - 如何用C获取类似 "ls -la"的文件信息?

android - 如何在 Android SurfaceView 上制作裁剪相机 View

c++ - 如何处理 Visual Studio 2008 中的警告 C4100

c++ - GTX 970 的 CUDA 设备属性

android - 为 Android 构建 ImageMagick

c# - 如何将 Image 对象与 C# .NET 进行比较?

java - 将两个 BufferedImages 并排复制到一个图像中