61

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)?

1

6 Answers 6

32

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.

2
  • 3
    Is any proofs in documentation or somewhere else about using of GDI by SDL on Windows?
    – SerG
    Jan 2, 2014 at 12:48
  • 2
    Wikipedia states that GDI is the default backend for Windows under the "Ports" section.
    – J Trana
    Jan 2, 2014 at 22:44
28

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).

1
  • 24
    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. Dec 30, 2018 at 9:05
14

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.

8

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.

7

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

6

As many people have stated, SDL handles more than just rendering. Besides handling audio, input, and other nice stuff, it makes the use of graphics simpler by giving you access to many functions which you would otherwise need to implement yourself.

So yes, SDL is an abstraction layer above OpenGL. However, you are still able to access OpenGL in your application and therefore use its full power.

A simple addition, since you seem to be new to this kind of API: If you want an API which is similar to SDL (for 2D graphics), I recommend having a look at SFML. It's based on C++ instead of C and has functions for things like rotation. It's also based on OpenGL. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.