I've been seeing people combine SDL2 and OpenGL (glfw.h or glut.h) for a while now, I've done some research and found out SDL2 runs on OpenGL. So why does people combine these two? Some people discussed how they use SDL2 for making the window and OpenGL for everything else, but that doesn't make sense since OpenGL can create windows as well.

GLFWwindow *window = glfwCreateWindow(WIDTH, HEIGHT, "Opengl Tutorials", NULL, NULL);
glfwMakeContextCurrent(window); // Cause OpenGL to work on this window

glfwSetKeyCallback(window, KeyCallback); // Callback to handle key events
glfwSetCursorPosCallback(window, MouseCallback); // Callback to handle mouse motion events

Some also say they use SDL2 for 2D animations, but that doesn't make sense as OpenGL can do that as well. As I said before SDL2 uses OpenGL so anything SDL2 can do, OpenGL can do, SDL2 is a wrapper of OpenGL. So why do people still add SDL2 and OpenGL together? For example these.

Is there any advantage? Is there something I'm missing? I'm so confused. Why would you combine SDL2 with OpenGL even though SDL2 is only a wrapper?

Between this is all for C/C++ so that may clear up some confusion. When I refer to OpenGL I'm referring to glut.h or/and glfw.h not OpenGL by itself since I don't know if you can do that.

  • 3
    Presumably, SDL2 can't do everything that OpenGL can do, but for those things that SDL2 can do it is easier to use than plain OpenGL. Aug 13, 2017 at 8:28
  • 3
    "but that doesn't make sense since OpenGL can create windows as well." OpenGL can't create windows. Your question boils down to "Why use a library at all when you can write all code yourself"
    – tkausl
    Aug 13, 2017 at 9:40
  • 9
    Your example code isn't OpenGL but GLFW. GLFW is just another library just like SDL2, so you could ask "Why use GLFW instead of plain OpenGL" aswell.
    – tkausl
    Aug 13, 2017 at 10:04
  • 4
    @NfagieYansaneh: "But like I said above OpenGL(glfw.h or glut.h)" No, GLFW and GLUT are not OpenGL. Aug 13, 2017 at 17:38
  • 3
    @NfagieYansaneh: "isn't glfw.h a wrapper for OpenGL" No. It initializes and manages an OpenGL-capable window. But it is not a wrapper for actually making OpenGL calls. Aug 13, 2017 at 23:46

2 Answers 2


OpenGL only has functions to work with a graphics context, nothing else. You need at least a platform integration library to get such a context. But in reality you of course need more functionality, such as input handling. GLFW, GLUT and SDL2 are just different ways of getting such additional functionality. SDL2 is nice because it also includes audio and resource loading.

  • Indeed, the Wikipedia page for GLFW says, "GLFW is by design not...a threading library...able to play back sound...GLUT or SDL." Conversely, SDLs page says, "SDL manages video, audio, input devices, CD-ROM, threads, shared object loading, networking and timers." Aug 13, 2017 at 22:43
  • +1 Thank you, I know see the reason for why someone would combine those two. Before I was spectical for why someone would add a wrapper to something that could handle anything for openGL, now I know that SDL2 has some extras like audio, cd-rom etc. that glfw.h can't handle Aug 14, 2017 at 3:52

I was also wondering why. but yes I use SDL2 because it has the best api for sound.keyboard and joysticks I could find for sound processing. but you can make a window in SDL2 and draw 3d but GLFW seems to work easyer. Im trying to draw 2d and 3d together with SDL2 but its not working well but i just began.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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