This is a transition guide for moving from GLFW 2 to 3. It describes what has changed or been removed, but does not include new features unless they are required when moving an existing code base onto the new API. For example, the new multi-monitor functions are required to create full screen windows with GLFW 3.
The GLFW 3 header is named glfw3.h and moved to the
GLFW directory, to avoid collisions with the headers of other major versions. Similarly, the GLFW 3 library is named
glfw3, except when it's installed as a shared library on Unix-like systems, where it uses the soname
The threading functions have been removed, including the per-thread sleep function. They were fairly primitive, under-used, poorly integrated and took time away from the focus of GLFW (i.e. context, input and window). There are better threading libraries available and native threading support is available in both C++11 and C11, both of which are gaining traction.
If you wish to use the C++11 or C11 facilities but your compiler doesn't yet support them, see the TinyThread++ and TinyCThread projects created by the original author of GLFW. These libraries implement a usable subset of the threading APIs in C++11 and C11, and in fact some GLFW 3 test programs use TinyCThread.
However, GLFW 3 has better support for use from multiple threads than GLFW 2 had. Contexts can be made current on any thread, although only a single thread at a time, and the documentation explicitly states which functions may be used from any thread and which must only be used from the main thread.
The image and texture loading functions have been removed. They only supported the Targa image format, making them mostly useful for beginner level examples. To become of sufficiently high quality to warrant keeping them in GLFW 3, they would need not only to support other formats, but also modern extensions to OpenGL texturing. This would either add a number of external dependencies (libjpeg, libpng, etc.), or force GLFW to ship with inline versions of these libraries.
As there already are libraries doing this, it is unnecessary both to duplicate the work and to tie the duplicate to GLFW. The resulting library would also be platform-independent, as both OpenGL and stdio are available wherever GLFW is.
GLFWCALL macro, which made callback functions use __stdcall on Windows, has been removed. GLFW is written in C, not Pascal. Removing this macro means there's one less thing for application programmers to remember, i.e. the requirement to mark all callback functions with
GLFWCALL. It also simplifies the creation of DLLs and DLL link libraries, as there's no need to explicitly disable
@n entry point suffixes.
Because GLFW 3 supports multiple windows, window handle parameters have been added to all window-related GLFW functions and callbacks. The handle of a newly created window is returned by glfwCreateWindow (formerly
glfwOpenWindow). Window handles are pointers to the opaque type GLFWwindow.
GLFW 3 provides support for multiple monitors. To request a full screen mode window, instead of passing
GLFW_FULLSCREEN you specify which monitor you wish the window to use. The glfwGetPrimaryMonitor function returns the monitor that GLFW 2 would have selected, but there are many other monitor functions. Monitor handles are pointers to the opaque type GLFWmonitor.
glfwOpenWindow have been turned into window hints, but as they have been given sane defaults you rarely need to set these hints.
GLFW 3 does not automatically poll for events in glfwSwapBuffers, meaning you need to call glfwPollEvents or glfwWaitEvents yourself. Unlike buffer swap, which acts on a single window, the event processing functions act on all windows at once.
Each GLFW 3 window has its own OpenGL context and only you, the application programmer, can know which context should be current on which thread at any given time. Therefore, GLFW 3 leaves that decision to you.
This means that you need to call glfwMakeContextCurrent after creating a window before you can call any OpenGL functions.
Window positions and sizes now use screen coordinates, which may not be the same as pixels on machines with high-DPI monitors. This is important as OpenGL uses pixels, not screen coordinates. For example, the rectangle specified with
glViewport needs to use pixels. Therefore, framebuffer size functions have been added. You can retrieve the size of the framebuffer of a window with glfwGetFramebufferSize function. A framebuffer size callback has also been added, which can be set with glfwSetFramebufferSizeCallback.
A user attempting to close a window is now just an event like any other. Unlike GLFW 2, windows and contexts created with GLFW 3 will never be destroyed unless you choose them to be. Each window now has a close flag that is set to
GLFW_TRUE when the user attempts to close that window. By default, nothing else happens and the window stays visible. It is then up to you to either destroy the window, take some other action or ignore the request.
The close callback no longer returns a value. Instead, it is called after the close flag has been set, so it can optionally override its value, before event processing completes. You may however not call glfwDestroyWindow from the close callback (or any other window related callback).
GLFW_FALSE, meaning you can use it for other reasons to close the window as well, for example the user choosing Quit from an in-game menu.
glfwOpenWindowHint function has been renamed to glfwWindowHint.
Window hints are no longer reset to their default values on window creation, but instead retain their values until modified by glfwWindowHint or glfwDefaultWindowHints, or until the library is terminated and re-initialized.
Video mode enumeration is now per-monitor. The glfwGetVideoModes function now returns all available modes for a specific monitor instead of requiring you to guess how large an array you need. The
glfwGetDesktopMode function, which had poorly defined behavior, has been replaced by glfwGetVideoMode, which returns the current mode of a monitor.
The action parameter of the character callback has been removed. This was an artefact of the origin of GLFW, i.e. being developed in English by a Swede. However, many keyboard layouts require more than one key to produce characters with diacritical marks. Even the Swedish keyboard layout requires this for uncommon cases like ü.
The cursor position is now
double instead of
int, both for the direct functions and for the callback. Some platforms can provide sub-pixel cursor movement and this data is now passed on to the application where available. On platforms where this is not provided, the decimal part is zero.
GLFW 3 only allows you to position the cursor within a window using glfwSetCursorPos (formerly
glfwSetMousePos) when that window is active. Unless the window is active, the function fails silently.
glfwGetMouseWheel function has been removed. Scrolling is the input of offsets and has no absolute position. The mouse wheel callback has been replaced by a scroll callback that receives two-dimensional floating point scroll offsets. This allows you to receive precise scroll data from for example modern touchpads.
GLFW_KEY_REPEAT enable has been removed and key repeat is always enabled for both keys and characters. A new key action,
GLFW_REPEAT, has been added to allow the key callback to distinguish an initial key press from a repeat. Note that glfwGetKey still returns only
GLFW 3 key tokens map to physical keys, unlike in GLFW 2 where they mapped to the values generated by the current keyboard layout. The tokens are named according to the values they would have in the standard US layout, but this is only a convenience, as most programmers are assumed to know that layout. This means that (for example)
GLFW_KEY_LEFT_BRACKET is always a single key and is the same key in the same place regardless of what keyboard layouts the users of your program have.
The key input facility was never meant for text input, although using it that way worked slightly better in GLFW 2. If you were using it to input text, you should be using the character callback instead, on both GLFW 2 and 3. This will give you the characters being input, as opposed to the keys being pressed.
GLFW 3 has key tokens for all keys on a standard 105 key keyboard, so instead of having to remember whether to check for
A, you now check for GLFW_KEY_A.
glfwGetJoystickPos function has been renamed to glfwGetJoystickAxes.
glfwGetJoystickParam function and the
GLFW_BUTTONS tokens have been replaced by the glfwJoystickPresent function as well as axis and button counts returned by the glfwGetJoystickAxes and glfwGetJoystickButtons functions.
The Win32 port of GLFW 3 will not compile in MBCS mode. However, because the use of the Unicode version of the Win32 API doesn't affect the process as a whole, but only those windows created using it, it's perfectly possible to call MBCS functions from other parts of the same application. Therefore, even if an application using GLFW has MBCS mode code, there's no need for GLFW itself to support it.
All explicit support for version of Windows older than XP has been removed. There is no code that actively prevents GLFW 3 from running on these earlier versions, but it uses Win32 functions that those versions lack.
Windows XP was released in 2001, and by now (January 2015) it has not only replaced almost all earlier versions of Windows, but is itself rapidly being replaced by Windows 7 and 8. The MSDN library doesn't even provide documentation for version older than Windows 2000, making it difficult to maintain compatibility with these versions even if it was deemed worth the effort.
The Win32 API has also not stood still, and GLFW 3 uses many functions only present on Windows XP or later. Even supporting an OS as new as XP (new from the perspective of GLFW 2, which still supports Windows 95) requires runtime checking for a number of functions that are present only on modern version of Windows.
The ability to disable and capture system-wide hotkeys like Alt+Tab has been removed. Modern applications, whether they're games, scientific visualisations or something else, are nowadays expected to be good desktop citizens and allow these hotkeys to function even when running in full screen mode.
GLFW 3 does not register glfwTerminate with
atexit at initialization, because
exit calls registered functions from the calling thread and while it is permitted to call
exit from any thread, glfwTerminate must only be called from the main thread.
To release all resources allocated by GLFW, you should call glfwTerminate yourself, from the main thread, before the program terminates. Note that this destroys all windows not already destroyed with glfwDestroyWindow, invalidating any window handles you may still have.
GLFW 3 does not by default include the GLU header and GLU itself has been deprecated by Khronos. New projects should not use GLU, but if you need it for legacy code that has been moved to GLFW 3, you can request that the GLFW header includes it by defining GLFW_INCLUDE_GLU before the inclusion of the GLFW header.
There are many libraries that offer replacements for the functionality offered by GLU. For the matrix helper functions, see math libraries like GLM (for C++), linmath.h (for C) and others. For the tessellation functions, see for example libtess2.
|All channel bit depths are now hints
|Now accepts all
|Accepts two-dimensional scroll offsets as doubles
|Returns the current mode of a monitor
|The axis and button counts are provided by glfwGetJoystickAxes and glfwGetJoystickButtons
|Renamed as it applies to OpenGL ES as well
|Renamed as it applies to OpenGL ES as well
|Renamed to match the OpenGL API
|Renamed to match the window focus callback
|The default has been inverted
|Used with glfwSetInputMode
Last update on Wed Feb 21 2024 for GLFW 3.3.10