Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've been working on a 2D game using SDL. I've noticed the objects look blurry and glitchy when they're moving, so I was thinking about using OpenGL to render the graphics. Would this help? What are the pros and cons of using OpenGL for a 2D game?

share|improve this question
up vote 5 down vote accepted

If you're having slowdowns and glitches with SDL software rendering in a 2D game, chances are very slim that OpenGL is going to do anything for you. SDL can run 2D games quickly on a Pentium II or even lower spec machine. In other words, there are problems inherent to how you are making your draw calls. I've had no problems with speed in SDL rendering, and I've written a pure scanline renderer, which is far more intensive than working with sprites.

Two approaches I suggest:

  • Pull out bits of your rendering code, methodically, until you see a speed increase. If you pull out one section and see a drastic speed increase, then pull out smaller pieces within that code section (where possible). If you pull out all of your rendering code (i.e. it's rendering nothing), and it's still slow, then you have problems with your game loop timing. In that case, see Fix Your Timestep.

  • Profile your code. If you are running under Linux, you can happily take advantage of the Valgrind suite of profiling and debugging tools. If you're under Windoze with MinGW or Cygwin, and you really want to profile, you can run your app with gdb and interrupt it, to manually take stack samples (leading you to see in which functions most of your time is being spent) -- see this for more info. This is because gprof, the profiler that comes with gcc/g++, is not very good... at least for real-time games it's next to useless.

share|improve this answer
In that case, it's probably an issue with my timing since I haven't done much work on the timing code aside from a simple framerate cap...I'm also working on an older laptop with a 1.6ghz processor and 512mb of RAM, so maybe it's just my computer. I haven't really done much research on the debugging tools available for Linux aside from GDB...So I'll definitely look into the Valgrind suite. – Adam Jan 21 '12 at 23:01
@Adam Don't worry about your system specs; again, I can guarantee you that won't impact the renderer performance - SDL was written more than a decade ago when many games still used software rendering. It has comparable performance to Allegro, which was written for the 16-bit Atari ST of the late 80's/early 90's. See this list of games written using SDL's renderer. Also, an upvote would be nice if you found this answer helpful. – Arcane Engineer Jan 21 '12 at 23:05
I did attempt to upvote, and it told me that I needed to be logged in...Which is odd considering that I'm pretty sure I'm logged in. – Adam Jan 21 '12 at 23:12
@Adam Hehe, no worries. Thanks for the accept. – Arcane Engineer Jan 21 '12 at 23:15
No problem...Thanks for the quick help and insight. – Adam Jan 21 '12 at 23:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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