Question

I was moving from SDL to SDL2, and was confused of the 'render & texture' system introduced.

Back in SDL, the most frequent operation was creating Surface's and BlitSurface them onto screen. Now there seems a trend of using renderers and textures. However, this is extremely slow (in terms of coding overhead) from my point. Why can't I just load_BMP and BlitSurface as before? What good can be introduced from this whole window-renderer-texture thing?

I have read a couple threads What is a SDL renderer? but still a little confusing.

So..

  1. Will the old Surface way work in SDL2?

  2. What is the point in Renderer & Texture? (could be about hardware-accelaration according to a little googling, but not sure what that means)

Was it helpful?

Solution

You might want to take a look at the migration guide for SDL2, it provides information on the new way of dealing with 2D graphics.

The point of using textures instead of surfaces is that textures works on the GPU and get loaded into video memory and surfaces works in system memory with the CPU and since GPUs are much better suited than CPU for handling graphics it will be faster. Also, the renderer hides the underlying system used (it could be D3D, OpenGL, or something else).

You can still load surfaces, but you'll have to convert them to textures before rendering them or use the SDL_UpdateWindowSurface and SDL_GetWindowSurface functions; the latter link includes an example on how to use them.

As for the SDL2 approach being slow, as you assert, I don't agree with you, you set up the window and renderer once, load your textures much like you loaded surfaces, copy them to the renderer instead of blitting and finally use SDL_RenderPresent instead of SDL_Flip. Not that different really :)

But, take a look at the migration guide, it has the information you're looking for.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top