What are the benefits of using OpenGL in SDL 2?

Zammalad picture Zammalad · Sep 15, 2013 · Viewed 13.7k times · Source

I assume that SDL 2 uses OpenGL rendering in the background (or perhaps DirectX if on Windows) and this decision is made by SDl itself.

I have seen tutorials which show the use of OpenGL directly in SDL and wondered what benefit, if any would you get from using OpenGL direct? Are there things which SDL would not be able to achieve natively?

Answer

Appleshell picture Appleshell · Sep 16, 2013

If you completely rely on SDL functionality for graphic purposes, you only have access to simple image and buffer functions.

Accelerated 2D render API: Supports easy rotation, scaling and alpha blending, all accelerated using modern 3D APIs

But what SDL also does is providing an OpenGL context. This means you also have full access to OpenGL functionality including 3D objects, shaders, etc.

You can use SDL simply to create your context and provide you with sound, input, and file i/o, and use OpenGL to bring color to the screen, or use the SDL video API to draw sprites and images.