0
\$\begingroup\$

Is it possible to copy into a SDL_Surface what is displayed in the screen from a SDL_RendererPresent?

using SDL_GetWindowSurface just return a black surface not the rendered scene as it is not accessing directly the video ram.

using SDL_GetRendererTarget if it is the "default" (the screen) is just a NULL value.

is there any function to copy the SDL_RendererPresent result into a SDL_Surface or even a SDL_Texture?

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

It is possible using SDL_RenderReadPixels, e.g.:


// SDL_Renderer* renderer
SDL_Window* window = SDL_RenderGetWindow(renderer);
SDL_Surface* screen_surf = SDL_GetWindowSurface(window);
if (SDL_RenderReadPixels(renderer, nullptr, 0, screen_surf->pixels, screen_surf->pitch) != 0)
        {
            // error use SDL_GetError()
        }

// at this point in screen_surf there is the rendered content from the screen.
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .