SDL_RenderPresent vs SDL_UpdateWindowSurface

Good day!

  1. I can not understand what the difference is, SDL_RenderPresent and
    SDL_UpdateWindowSurface.

Example 1:
SDL_Window *window = SDL_CreateWindow(“Test 1”, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN);
SDL_Renderer *renderer = SDL_CreateSoftwareRenderer(SDL_GetWindowSurface(window));

It will only work this function: SDL_UpdateWindowSurface(window);

Example 2:
SDL_Window window = SDL_CreateWindow(“Test 2”, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN);
SDL_Renderer
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_SOFTWARE);

It will only work this function: SDL_RenderPresent(renderer);
What are the differences in performance (example1 vs example2)?

  1. For the old version SDL1.2, I often used this code: SDL_BlitSurface(SDL_GetVideoSurface(), dstsf, …).
    Do I understand correctly that the new version should use this code:
    SDL_CreateTextureFromSurface(renderer, SDL_GetWindowSurface(window)); + SDL_SetRenderTarget + SDL_RenderCopy?

  2. SDL_CreateWindowAndRenderer - What type of rendering will be created (software or accelerated)?

Thanks you!

UpdateWindowSurface works with software renderer only since it modifies window surface which is in RAM, while RenderPresent works with hardware renderer and it sends the frame to the GPU.

Good day!

  1. I can not understand what the difference is, SDL_RenderPresent and
    SDL_UpdateWindowSurface.

You should use SDL_RenderPresent() in almost every case, with something
you created with SDL_CreateRenderer().

SDL_UpdateWindowSurface() is only useful in extremely unusual cases (the
most common being that the software renderer uses it internally when you
call SDL_RenderPresent()).

If you definitely want a software renderer, still use
SDL_CreateRenderer(), and look at some pixel-oriented ways to draw to
the screen here:

https://wiki.libsdl.org/MigrationGuide#If_your_game_just_wants_to_get_fully-rendered_frames_to_the_screen

  1. For the old version SDL1.2, I often used this code: SDL_BlitSurface(SDL_GetVideoSurface(), dstsf, …).
    Do I understand correctly that the new version should use this code:
    SDL_CreateTextureFromSurface(renderer, SDL_GetWindowSurface(window)); + SDL_SetRenderTarget + SDL_RenderCopy?

Just create a texture once, copy into it once a frame from a buffer of
pixels (which might literally be an SDL_Surface::pixels buffer) using
SDL_UpdateTexture(), and then call SDL_RenderCopy() to draw that with
that texture, and finally SDL_RenderPresent() to put it on the screen.

SDL_GetWindowSurface() is much the same as
SDL_UpdateWindowSurface()…don’t ever use it, unless you know exactly
what you’re doing. It’s not the interface you think it is.

  1. SDL_CreateWindowAndRenderer - What type of rendering will be created (software or accelerated)?

By default: probably a Direct3D renderer on Windows, and OpenGL (or
OpenGL ES) in most other places. Only platforms with no GPU support at
all will default to the software renderer. Even if you plan to
software-render your game to a buffer of pixels, you shouldn’t force the
software renderer: on many platforms, OpenGL and Direct3D will be able
to get your prerendered buffer of pixels to the screen faster, even if
you aren’t explicitly doing 3D rendering.

(you can force the software renderer with SDL_SetHint(), or by using
SDL_CreateRenderer() directly, but really…you probably shouldn’t.)

–ryan.On 12/11/2013 09:02 PM, Afletdinov A. wrote: