Sign in to follow this  
Replicon

SDL + OpenGL vs. just OpenGL

Recommended Posts

I'm thinking of dabbing into OpenGL sometime soon. My one question right now is, why is special attention given to "openGL WITH SDL"? Is it because you need to hook it in somehow, cause otherwise you can't use the rest of SDL on the side (e.g. event handling, input, audio and so on)?

Share this post


Link to post
Share on other sites
OpenGL has no capacity for creating a window, getting input, playing sounds, loading images or anything else besides graphics. Because these are all rather useful, you have to augment OpenGL with some other library.

SDL was invented partly to serve as an easy cross-platform way to add all of the above to OpenGL. It is given special attention because it is really nice [wink].

Share this post


Link to post
Share on other sites
Two of the main reasons to use OpenGL with SDL is for window creation and the event handling. If you are working on the Windows platform, setting all that up with the Win32 API can be a major pain. Even if you do manage to get through all that, you'll still have to worry about doing it on the other platforms you want to support. SDL handles all of it for you, rather painlessly, and it works on multiple platforms. There is very little reason not to use it.

When you create a new window with SDL, you can tell the API to set up an OpenGL window, rather than an SDL one. After that, you can render with OpenGL, and the rest of the SDL API is available to you, if you want to use it. I have also used OpenAL (an API similar to OpenGL for audio) with SDL and OpenGL without any problems.

Share this post


Link to post
Share on other sites
There are other libraries which will do this without SDL. My favourite is GLFW, which is a very simple library which provides a base code for OpenGL applications. It effectively hides most of the OS-specific and/or complicated stuff (setting up windows etc) behind a very simple layer which means you can start coding straight away.

Apparently GLFW works on Windows, Linux and Mac - but I've only used it under Linux and Windows.

Most of SDL's functionality is either old or not very useful, e.g. the software rendering / DirectDraw based stuff. GLFW has none of that, it's just a framework to set up GL.

Mark

Share this post


Link to post
Share on other sites
[edit]
I get up to grab a bite to eat while posting and there are 4 posts ahead of me saying the same thing.
[/edit]

OpenGL is a graphics library only. The graphics library still needs to know how to talk to the underlying operating system like Windows, MacOS(?), Linux etc. Libraries like SDL, FLTK, Allegro etc. offer a platform independent way to let OpenGL know how to talk to the OS.

More specific to your question however is that you can use SDL for setting up your window, input and audio but use OpenGL for the rendering. The setup is slightly different for using OpenGL to do the rendering which causes the special case you speak of.

Using a 3rd party library to get away from the OS layer has both ups and downs. On windows for example the code for setting up the window is unnecessarily long whereas the SDL code to do the same thing is only a handful of lines. On the flip side of that, when you use SDL you don't have access to the multiwindow support, controls and features of the windows API which depending on your application may or may not be an issue(*note that you have access to these subsystems however it negates the portability that SDL provides so that may be a poor example but you get the idea*).

Share this post


Link to post
Share on other sites
Quote:
Original post by evillive2
OpenGL is a graphics library only. The graphics library still needs to know how to talk to the underlying operating system like Windows, MacOS(?), Linux etc. Libraries like SDL, FLTK, Allegro etc. offer a platform independent way to let OpenGL know how to talk to the OS.


I see, I guess I overestimated the scope of OpenGL then. As a cross-platform API, I would have thought the various OpenGL libraries for the various OS' would include "knowing how to talk to the OS" :-).

Thanks for the quick responses as usual!

Share this post


Link to post
Share on other sites
It's not that OpenGL needs something like SDL to run. It's fine to use OpenGL on its own with no other libraries at all. It's just that you then have to write platform-specific code for window creation, input handling, sound playing, etc.

Share this post


Link to post
Share on other sites
Given that openGL is a windowing system, of course, you need
window creation software, whether one uses SDL, X or
windows, or whatever. However, framebuffer objects do not depend
on the windowing system. Here is what I'd like to do:

Create an openGL program that draws into a framebuffer object.
Then retrieve the information, and send it elsewhere using TCP or
some other protocol. I should be able to run this program from a remote
computer. In summary: I am not interested in creating a window.

Is this possible? If not, why not?

Thanks,

Gordon

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this