Advertisement

GLFW or GLEW? Which OpenGL library should I use

Started by July 22, 2015 12:36 AM
1 comment, last by wintertime 9 years, 5 months ago

There are a lot of libraries out there, and I would imagine their functionality is basically the same. . .

Being as it is that I have no experience, which one would you suggest?

I'm a directX guy but touched a but of ogl too.
Glew and glfw are not mutually exclusive as their purpose is different.

Excerpt from the following page:
http://stackoverflow.com/questions/15613978/difference-of-freeglut-vs-glew

The OpenGL Extension Wrangler (GLEW) is used to access the modern OpenGL API functions(version 3.2 up to latest version).If we use an ancient version of OpenGL then we can access the OpenGL functions simply including as #include <GL/gl.h>.But in modern OpenGL, the API functions are determined at run time, not compile time. GLEW will handle the run time loading of the OpenGL API.About GLEW see here

GLFW or freeglut will allow us to create a window, and receive mouse and keyboard input in a cross-platform way. OpenGL does not handle window creation or input, so we have to use these library for handling window, keyboard, mouse, joysticks, input and other purpose.

GLFW and freeglut are alternative for us according to our need we can choose any one but GLEW is different from them which is used for run time loading of the OpenGL API.
Advertisement

Yeah, you basically need 1 library to abstract the ugly wgl/glx calls and collect input (GLFW, SDL, SFML, GLUT(ancient and unsupported), FreeGLUT(oldfashioned)), another to load the function pointers (glad, glloadgen, GL3W, GLEW, GLee, ...) where the newer ones allow you to generate their C code tuned to your needs (choose GL version, core/compatibility and which extensions to avoid always loading a thousand functions and extensions you never use).

http://www.glfw.org/faq.html#why-doesnt-your-glh-have-the-functions-i-need

See also this recent, similar question.

In summary, GLFW is what its name says ("GL Frame Work"), a framework. That is, it enforces a kind of structure on your program. Rather than deciding what to do when, you call some initialization functions and tell the framework more or less what you expect, and then the framework calls you back at the appropriate times (for example when the user presses a key or moves the mouse, resizes the window). All you need to do is write handlers for that, the logic behind it is already written. In addition, GLFW comes with a set of useful utility functions. You still write GL code to do the drawing, though.

GLEW on the other hand handles the loading of extensions ("GL Extension Wrangler"). What does that mean? Unlike another well-known graphics API from Microsoft, OpenGL does not come as a set of distinct, entirely different, incompatible versions with different libraries which on the other hand have exactly defined functionality and specs. Instead, OpenGL is a somewhat blurry "everything at the same time, and none" and built in an extendable and heavily extended manner, which is not at all obvious or intuitive to a beginner.

In addition to the base functionality, you can use extensions, if they are supported (there are well over 300 extensions, and the average graphics card driver supports well over a hundred). Additionally, all versions after 1.2 technically work as-if extensions. That is, you cannot just link with opengl32.dll and expect that everything will magically work for OpenGL 3.0 or OpenGL 4.4.

Instead, after creating a context (GLFW will do that for you!) you need to query your context for the supported version and for supported extensions that you may wish to use. Then you must set up a lot of function pointers and initialize them. This is a lot of nasty and error-prone work even for someone reasonably experienced, lest a beginner.

GLEW does all that.

So basically, with GLEW, you call one function to init everything, and then you can very comfortably check what you have available, and use it right away... without having to deal with that nasty stuff.

To answer the question "Which one should I use?" -- in any case you want to use GLEW (or an alternative, but GLEW works fine), but you most likely want to use both GLEW and GLFW since it makes your life easier.

This topic is closed to new replies.

Advertisement