从几个纹理SDL-2创建新纹理

时间:2013-12-22 15:24:03

标签: textures render render-to-texture sdl-2

我有几种纹理会在我的屏幕上保持静止。我不是在渲染时单独渲染每个渲染,而是将它们全部渲染为一个纹理。到目前为止我的代码看起来像:

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

1 个答案:

答案 0 :(得分:5)

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

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