Why are SDL and OpenGL related?

39,156

Solution 1

SDL is a cross-platform multimedia library designed to provide low level access to audio, keyboard, mouse, joystick, etc. It also supports 3D hardware via OpenGL.

OpenGL is a standard specification defining a cross-language, cross-platform API for writing applications that produce 2D and 3D computer graphics. The interface consists of over 250 different function calls which can be used to draw complex three-dimensional scenes from simple primitives. OpenGL was developed by Silicon Graphics Inc. (SGI) in 1992[4] and is widely used in CAD, virtual reality, scientific visualization, information visualization, and flight simulation. It is also used in video games, where it competes with Direct3D on Microsoft Windows platforms (see OpenGL vs. Direct3D).

Solution 2

SDL is a layer above OpenGL; in fact it uses GDI on Windows by default and also has a DirectX backend. People are probably saying you can use OpenGL to get around limitations of SDL on platforms that by default use OpenGL (ahem, Linux) because the higher level abstraction doesn't expose that functionality. However, then your code is "less" portable to Windows (or at least Windows using the GDI backend).

Also, SDL does a lot of other things besides graphics - audio, input, etc. that OpenGL doesn't do.

Solution 3

SDL uses OpenGL as a hardware renderer for content that wants hardware rendering on some platforms. If you have such a platform, then OpenGL is the underlying API over which SDL is an abstraction.

Solution 4

About your example about rotating graphics: it is better to do it with OpenGL (i.e. hardware accelerated) than with SDL itself (i.e. on the CPU) because it is generally computionally intensive (especially if you have a lot of bitmaps to rotate every frame and you want the effect to be smooth).

However, nothing (besides reason) keeps you from using the SDL_gfx package which has the module SDL_rotozoom responsible for rotating and scaling bitmaps.

Solution 5

SDL handles input, window creation, image loading and several other functionality that OpenGL doesn't handle.

Share:
39,156
Devan Buggay
Author by

Devan Buggay

Currently a front-end developer at Microsoft, focused on react/redux and browser performance. In my free time I play a lot of Counter-Strike and DotA2.

Updated on July 09, 2022

Comments

  • Devan Buggay
    Devan Buggay almost 2 years

    I was messing around with SDL and found out that you cannot rotate images with SDL. Everywhere the question was asked, people said to use OpenGL to do rotation. I always thought that SDL was completely separate from OpenGL, am I wrong in thinking this? I even found tutorials for using OpenGL within SDL, which confused me even further. What exactly is the relationship between SDL and OpenGL? Why not just use OpenGL if its more powerful and allows you to do more (this is from what I've read)?

  • SerG
    SerG over 10 years
    Is any proofs in documentation or somewhere else about using of GDI by SDL on Windows?
  • J Trana
    J Trana over 10 years
    Wikipedia states that GDI is the default backend for Windows under the "Ports" section.
  • Jason Doucette
    Jason Doucette over 5 years
    I believe the key question here to answer is: "What exactly is the relationship between SDL and OpenGL?" From a beginner's standpoint, textbook definitions of the two technologies is likely confusing.