What are the benefits of using OpenGL in SDL 2?

14,138

Solution 1

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.

Solution 2

http://wiki.libsdl.org/MigrationGuide

Simple 2D rendering API that can use Direct3D, OpenGL, OpenGL ES, or software rendering behind the scenes

SDL2 just give you easy start with 2D graphics (and other matters) but you can't do "real 3D" only with SDL. (or i don't know about something?)

I don't know what SDL do "behind the scenes" but if you use directly OpenGL (or other API like Direct3D) you have full control over the code and rendering process and you aren't limited to SDL graphics API.

I use SDL only for creating window, graphics context and using input devices like mouse.

Share:
14,138

Related videos on Youtube

Zammalad
Author by

Zammalad

All round computer geek with a passion for games and programming in general.

Updated on July 23, 2022

Comments

  • Zammalad
    Zammalad almost 2 years

    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?

  • this
    this over 10 years
    you can't do "real 3D" only with SDL that's right but with c you can :)
  • trebor
    trebor over 10 years
    heh yes but you know what I mean :)
  • Zammalad
    Zammalad over 10 years
    Cool thank you. So is OpenGL only worth delving in to for 3D graphics etc where as if I am just doing basic 2D stuff SDL is sufficient?
  • Appleshell
    Appleshell over 10 years
    @Zammalad Thats basically it, yes
  • Cubic
    Cubic about 10 years
    @Zammalad This is a bit late, but note that there are some shader tricks that you can't really replicate with the SDL renderer API but that are useful in 2D graphics - for example, if you want to render a tilemap, you can do this efficiently in a single draw call with a specialized shader, compared to the thousands you'd need if you rendered it as separate sprites.