4

Now this question might sound (/ is) stupid, but I'm just getting into OpenGL. So I installed GLFW source and I'm looking at some easy examples. What I'm noticing is, that the code still contains "typical" OpenGL functions, like glColor or glVertex, but it also contains "glfw" functions like glfwSetErrorCallback.

I don't really understand how OpenGL and GLFW (or something like GLUT) relate to each other. Khronos owns OpenGL, but do they program a library for people to use, or do they just specify an API, like for example there are several C++ libraries (libc++ and libstdc++) which implement the same API specified by the C++ Consortium?

I'm going to make an assumption and going to ask if it is right:

Khronos programs the OpenGL library and specifies an API for it. GLUT, GLFW and freeglut wrap around (or better extend) that OpenGL library and offer additional behavior (I read that OpenGL doesn't offer much for support for sound or dealing with input).

Which means that you could use OpenGL on its own, but it would make several things quite difficult. But it also means that you wrote something with GLFW, you could "port" it to using, e.g., freeglut, and you would only have to replace the functionality provided by glfw(...) functions, but the gl(...) woul stay the same. Is that right?

2

Yes. you are right

The OpenGL is the base layer, and is an API.

But it's a difficult (or , may better, low level) API.

So, using any library build on top of it will make things easier for you.

Of course, there are things that don't need to be made "better" or easier, so you still use now and then the base function calls, or the base declarations.

And yes, changing to another library won't affect those low level (or direct) calls

  • 1
    IMO this answer is almost completely incorrect. GLFW and OpenGL serve distinct purposes. GLFW isn't there to make OpenGL easier. OpenGL isn't a base layer for OpenGL. If anything, GLFW looks like a base layer for OpenGL as it provides the contexts for OpenGL. – user27539 Mar 30 '17 at 15:02
5

OpenGL is a library that provides services like 3D rendering but doesn't do anything like creating a window that you can render into. OpenGL doesn't know anything about windows, or mouse events, or keyboards, or fonts and so on. It only knows about rendering. Because you probably want to render things visible on the screen you can't "use OpenGL on its own" because you wouldn't have anywhere to render. In fact, in order to do anything with OpenGL you need what is called an OpenGL context. The OpenGL library itself has no mechanism to create such contexts. Think of an OpenGL context as some internal data that represents the current state of the OpenGL system.

Different platforms (such as Windows, Linux/X, OSX, iOS, Android) provide different mechanisms for creating contexts. For example Windows has its own function calls that allow the creation of OpenGL contexts that are very different from how OSX creates a context. Additionally Windows provides functions to support things like mouse events. This is where GLFW comes in: it provides a cross-platform library to handle the things that OpenGL doesn't handle, like creating contexts and handling mouse events. By and large it's not a wrapper library on top of OpenGL though it does provide some a small amount of functionality like this: like automatically building mip-map levels.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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