I know that SDL 1.2 does software rendering (CPU) and not hardware rendering (GPU). My question is, how do I use SDL but with hardware rendering? How do I not use its rendering API (software) and rather a hardware rendering API like OpenGL?


1 Answer 1


SDL supports OpenGL outright. There is a guide in the SDL documentation on how to use OpenGL (This is mainly a SDL tutorial, not an OpenGL one [it uses a lot of deprecated functionality]).

You probably also want to change the SDL_GL_SetAttribute( SDL_GL_RED/GREEN/BLUE_SIZE, 5 ); from 5 to 8 bits per pixel, and also add an alpha channel (SDL_GL_ALPHA_SIZE).

After that, you can start using OpenGL like you normally do. Here's a good tutorial - you only need to replace the glutSomething functions with their SDL equivalents.

Note that if you use OpenGL with SDL, you can't blit onto the screen surface anymore (it works if you use the right flags, but even then it's deprecated functionality). But you can still use SDL_image to load images and use the SDL_Surface data to create textures.

  • \$\begingroup\$ Thanks for the reply. This was what I was looking for! Also, would you recommend SFML over SDL? I know C++ is more OO and a modern interface for C++ but besides that, it seems to have better features although SDL is more mature. I'm not quite sure what I should use. \$\endgroup\$
    – hullot
    Mar 31, 2012 at 19:37
  • \$\begingroup\$ I've never used SFML. Basically, I know that it exists. SDL has always been "good enough" for me. Your mileage may vary. \$\endgroup\$
    – Raphael R.
    Mar 31, 2012 at 19:58
  • 1
    \$\begingroup\$ If you're using C++, there's literally zero reason to use SDL instead of SFML (unless you want to target FreeBSD or something). Just rememeber to use the latest SFML 2.0 snapshot instead of SFML 1.6. \$\endgroup\$
    – TravisG
    Mar 31, 2012 at 22:39
  • 1
    \$\begingroup\$ Use whatever gets the job done. If you already know all the little nooks and crannies of SDL, then SDL is likely to remain a better choice. Switching to a different platform just because it's more modern or more OO is a really really bad reason. Choose your platform based on what you know and what does the job you need done first. \$\endgroup\$ Mar 31, 2012 at 23:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .