Why are SDL and OpenGL related?

C++COpenglSdl

C++ Problem Overview


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

C++ Solutions


Solution 1 - C++

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 2 - C++

> 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 3 - C++

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 - C++

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 - C++

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

Solution 6 - C++

As many people have stated. SDL handles more than just the rendering. Besides handling audio, input and all the other nice stuff it makes the use of graphics simplier by giving you access to many functions which you would need to implement by yourself otherwise.
So ys, SDL is an abstraction layer above OpenGL. You are still able to access OpenGL in your application and therefore use it's 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 can recommend having a look at SFML. It's based on C++ instead of C has functions for things like rotation. It's also based on OpenGL. :)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDevan BuggayView Question on Stackoverflow
Solution 1 - C++J TranaView Answer on Stackoverflow
Solution 2 - C++karlphillipView Answer on Stackoverflow
Solution 3 - C++PuppyView Answer on Stackoverflow
Solution 4 - C++KosView Answer on Stackoverflow
Solution 5 - C++SurvivalMachineView Answer on Stackoverflow
Solution 6 - C++SkalliView Answer on Stackoverflow