SDL and OpenGL

Member
Posts: 321
Joined: 2004.10
Post: #1
I've only used OpenGL and GLUT since I've started game programming
but I feel like I've outgrown GLUT and would like to move up to SDL. with OpenGL.

From what I've gleamed so far off the internet is that it is not completely
trivial?.All I've been able to find so far is pure SDL programs.

Can someone point me to an example of a combined SDL/OpenGL program?

thanks.
Quote this message in a reply
Apprentice
Posts: 5
Joined: 2009.03
Post: #2
Using OpenGL in conjunction with SDL is actually quite simple. Have a look at the tutorials at
http://nehe.gamedev.net

At the end of each tutorial you can download the source for several platforms including "Linux/SDL". Have a look at it. Creating an OpenGL/SDL app for Mac OS is very similar. IIRC there will even be OpenGL/SDL template for XCode, once you installed the sdl framework.
Quote this message in a reply
Moderator
Posts: 508
Joined: 2002.09
Post: #3
There's an example on the SDL framework. In Xcode use SDL/OpenGL project and you're set.

"When you dream, there are no rules..."
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #4
I recommend you avoid SDL like the plauge and use Cocoa.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Moderator
Posts: 1,562
Joined: 2003.10
Post: #5
unknown Wrote:I recommend you avoid SDL like the plauge and use Cocoa.
This sort of statement is completely useless if you don't provide any justification.
Quote this message in a reply
Member
Posts: 321
Joined: 2004.10
Post: #6
Thanks all!

I'll learn Cocoa someday but right now I want portability.
Quote this message in a reply
Moderator
Posts: 508
Joined: 2002.09
Post: #7
I agree with unknown and I'll provide some justification:

SDL+OpenGL

+ easy setup
+ platform independent
- performance not so good

Cocoa+OpenGL

+ super easy setup
+ great performance
+ can do more with an NSOpenGLView
- Mac only

"When you dream, there are no rules..."
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #8
Ill give a few reasons why I think this then,

SDL is a cross platform library but its difficult to set it up right for Mac, the menus don't do what they should and you have to implement CMD-Q for quit yourself.

You get a lot less control over things like window management with SDL, for example i've found it very useful in some projects to make a debug panel in IB with some sliders on it so I can test various games constants.
You can also integrate the game with the system better using Cocoa NSUserDefaults for saving pref's.

The libraries are supposed to come as compiled libs (.a, .dylib etc) but they are usually used as SDL frameworks on OS X which makes compiling most of the SDL code a real pain, involving searching through all files replacing #includes and editing the compile line. Compiling as static libs on os x is a lengthy and painful process.

Cocoa would be the next stage after SDL In terms of making a professional game and its not much more difficult to learn how to setup, so I think its worthwhile to just skip SDL and of course whatever you learn about the Cocoa API along the way will be more useful to you than the knowledge of SDL (if you ever want to write an Application in future for example).

I disliked using the SDL API and felt is was rather clumsy (especially in comparison to the AppKit API) and it limits you to C/C++, whereas with Cocoa/AppKit you can use C/C++ or ObjectiveC (or any mix of the three).

You would need to deal with also if you used SDL, the problems of either forcing users to install the SDL frameworks or bundling it with the app and setting the @executable_path for the framework with install_name_tool (which will also increase the size of the final program bundle).

Overall, I think its a lot more work with SDL. While you will probably get something on screen faster, if you create a decent Cocoa OpenGL template you would have something more solid to work from and improve, and will provide a better user experience.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #9
SDL's performance is no less than a standard Cocoa/OpenGL application (in fact, it *is* a standard Cocoa/OpenGL application).

The biggest argument against SDL is, as Unknown points out, the un-mac-ness of the result. The biggest argument for it is the complete cross-platform portability of well-written SDL code.
Quote this message in a reply
Member
Posts: 320
Joined: 2003.06
Post: #10
One thing that I have found impossible to do using SDL is to allow for the user to resize the window/openGLview. The only ways of doing it appear to be to either reload all of the textures each resize or to hack at the SDL source. Neither is an option for me.

Just something else to consider. I would follow Taxxodium's advice and start with the built in example. The SDL Docs are fine for modifying the example, not so fine for figuring out how to start from scratch.

Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
Quote this message in a reply
Post Reply