11

I am new to SDL and I've been following some tutorials; in one tutorial he used Surfaces (a window surface and image surface) and a BlitSurface function to draw images without using any renderer (used SDL Image library for JPG, PNG etc.).

And in another tutorial, he used a Renderer.

What's the difference between those two? It seemed to me they do the same thing but I'm assuming if they were the same, one wouldn't exist.

Vaillancourt
  • 16,325
  • 17
  • 55
  • 61
alexmoran
  • 111
  • 1
  • 3

1 Answers1

15

This is fairly well documented in the SDL1 to SDL2 Migration Guide.

Essentially, SDL_Surface is a tool for CPU side blit rendering, where as SDL_Renderer takes advantage of hardware acceleration, and performs the rendering on the GPU. SDL_Renderer provides an abstraction over several APIs and even offers a fallback CPU-side implementation if no other implementation suits your platform (unlikely).

There are very few reasons for using SDL_Surfaces for rendering these days, except if you 100% know what you are doing (and are perhaps writing a low resolution raytracer that runs on the CPU?). SDL_Renderer and its SDL_Texture is a much better performing choice if you don't need CPU side access to individual pixels.