Confuse with OpenGL, SFML, and its library

nightrobin 101 Oct 06, 2012 at 14:21 opengl

Hi guys, I am a beginning to enter the world of game development.

Lately, I researched that “OPENGL” is one of the tools to use in graphics,
then I found out about “SFML” (I think that its a library or something that uses opengl).

I am so confuse because all books/ sites said using “GLUT”,
but many people/fellow developers said that I must use a more updated one like “SFML”
but sfml has few/none tutorials.

What I am trying to say is “how to create own library or something like your own glut or sfml”,
and why does opengl has no source code? And how can I use the EXACT(not glut/sfml) opengl in my c++

I am so confuse….

3 Replies

Please log in or register to post a reply.

Reedbeta 167 Oct 06, 2012 at 17:09

There’s no source code for OpenGL because it’s not a library - it’s an interface (an API). It provides a standardized way to talk to the graphics driver no matter what platform you’re on and what kind of GPU you have. The implementation of OpenGL commands is actually provided by the graphics driver and is proprietary, as it deals with the low-level communication with your specific GPU.

Now OpenGL itself is platform-independent, but in order to use OpenGL on a given platform, you have to first somehow create a window and tell the OS that you’re going to be using OpenGL there. There are other things you’ll want to do in a game, like receiving keyboard and mouse input, playing sound effects, measuring time, networking, and multithreading, that also require talking to the OS.

GLUT, SFML and so forth are wrapper libraries that hide all the platform-specific stuff. They give you a standardized way to create an OpenGL window as well as standardized ways to receive input, play sound effects, and all that other stuff. (Well, actually GLUT is a much smaller library; it only does windowing and input, not any of that other stuff.)

If you want to make a game that runs on PC, Mac, and Linux, then SFML or something like it would be useful, otherwise you have to write a bunch of different code for each OS. If you only care about one platform, though, you could just use that platform’s own APIs. For example in Windows you could create your own window and use wglCreateContext etc. to initialize OpenGL.

fireside 141 Oct 06, 2012 at 17:53

You’re new to opengl so you don’t recognize the actual calls. Opengl is only for graphics so you can follow any tutorial by using the graphics portion of the code and it’s pretty obvious because it starts with “gl”. Just set up a window with sfml and then copy the graphics code from the tutorial and paste it into your sfml program. You can find a basic sfml tutorial on what opengl will look like by googling “sfml opengl”. You may want to start with glut until you become more familiar with opengl and what it does by following some tutorials exactly. Once you get used to it, you will know what to do to make the same program run with sfml. It will be a good programming exercise to move the code from glut to sfml and will give you more understanding.

TheNut 179 Oct 06, 2012 at 19:59

If you want to do things yourself, you can view this tutorial for setting up a window with an OpenGL context. Or as others have said, use an existing framework or game engine, which will hide all these details away from you.

As Reed said, OpenGL is an API. You can however view source code for the software implementations of OpenGL. I wouldn’t recommend this unless you’re really keen on knowing this stuff. You can download SGI’s implementation here, or you can check out MesaGL’s implementation here, which is basically the open source variant primarily used on *nix.