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
glVertex, but it also contains “glfw” functions like
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 (
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?
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
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.