5

I have several textures that will be staying stationary on my screen. Rather than rendering each one individually when I render, I would like to render them all as one texture. My code so far looks like:

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 Answer 1

6

You have to create your target_texture, currently it's always NULL. Replace your first line for:

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

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.