This is the reference documentation for initialization and termination of the library, version management and error handling. For more task-oriented information, see the Introduction to the API.
Modules | |
Error codes | |
Error codes. | |
Macros | |
#define | GLFW_TRUE 1 |
One. | |
#define | GLFW_FALSE 0 |
Zero. | |
#define | GLFW_JOYSTICK_HAT_BUTTONS 0x00050001 |
Joystick hat buttons init hint. | |
#define | GLFW_ANGLE_PLATFORM_TYPE 0x00050002 |
ANGLE rendering backend init hint. | |
#define | GLFW_PLATFORM 0x00050003 |
Platform selection init hint. | |
#define | GLFW_COCOA_CHDIR_RESOURCES 0x00051001 |
macOS specific init hint. | |
#define | GLFW_COCOA_MENUBAR 0x00051002 |
macOS specific init hint. | |
#define | GLFW_X11_XCB_VULKAN_SURFACE 0x00052001 |
X11 specific init hint. | |
#define | GLFW_ANY_PLATFORM 0x00060000 |
Hint value that enables automatic platform selection. | |
#define | GLFW_PLATFORM_WIN32 0x00060001 |
#define | GLFW_PLATFORM_COCOA 0x00060002 |
#define | GLFW_PLATFORM_WAYLAND 0x00060003 |
#define | GLFW_PLATFORM_X11 0x00060004 |
#define | GLFW_PLATFORM_NULL 0x00060005 |
Typedefs | |
typedef void *(* | GLFWallocatefun) (size_t size, void *user) |
The function pointer type for memory allocation callbacks. | |
typedef void *(* | GLFWreallocatefun) (void *block, size_t size, void *user) |
The function pointer type for memory reallocation callbacks. | |
typedef void(* | GLFWdeallocatefun) (void *block, void *user) |
The function pointer type for memory deallocation callbacks. | |
typedef void(* | GLFWerrorfun) (int error_code, const char *description) |
The function pointer type for error callbacks. | |
typedef struct GLFWallocator | GLFWallocator |
Functions | |
int | glfwInit (void) |
Initializes the GLFW library. | |
void | glfwTerminate (void) |
Terminates the GLFW library. | |
void | glfwInitHint (int hint, int value) |
Sets the specified init hint to the desired value. | |
void | glfwInitAllocator (const GLFWallocator *allocator) |
Sets the init allocator to the desired value. | |
void | glfwInitVulkanLoader (PFN_vkGetInstanceProcAddr loader) |
Sets the desired Vulkan vkGetInstanceProcAddr function. | |
void | glfwGetVersion (int *major, int *minor, int *rev) |
Retrieves the version of the GLFW library. | |
const char * | glfwGetVersionString (void) |
Returns a string describing the compile-time configuration. | |
int | glfwGetError (const char **description) |
Returns and clears the last error for the calling thread. | |
GLFWerrorfun | glfwSetErrorCallback (GLFWerrorfun callback) |
Sets the error callback. | |
int | glfwGetPlatform (void) |
Returns the currently selected platform. | |
int | glfwPlatformSupported (int platform) |
Returns whether the library includes support for the specified platform. | |
#define GLFW_VERSION_MAJOR 3 |
The major version number of the GLFW header. This is incremented when the API is changed in non-compatible ways.
#define GLFW_VERSION_MINOR 4 |
The minor version number of the GLFW header. This is incremented when features are added to the API but it remains backward-compatible.
#define GLFW_VERSION_REVISION 0 |
The revision number of the GLFW header. This is incremented when a bug fix release is made that does not contain any API changes.
#define GLFW_TRUE 1 |
This is only semantic sugar for the number 1. You can instead use 1
or true
or _True
or GL_TRUE
or VK_TRUE
or anything else that is equal to one.
#define GLFW_FALSE 0 |
This is only semantic sugar for the number 0. You can instead use 0
or false
or _False
or GL_FALSE
or VK_FALSE
or anything else that is equal to zero.
#define GLFW_JOYSTICK_HAT_BUTTONS 0x00050001 |
Joystick hat buttons init hint.
#define GLFW_ANGLE_PLATFORM_TYPE 0x00050002 |
ANGLE rendering backend init hint.
#define GLFW_PLATFORM 0x00050003 |
Platform selection init hint.
#define GLFW_COCOA_CHDIR_RESOURCES 0x00051001 |
macOS specific init hint.
#define GLFW_COCOA_MENUBAR 0x00051002 |
macOS specific init hint.
#define GLFW_X11_XCB_VULKAN_SURFACE 0x00052001 |
X11 specific init hint.
#define GLFW_ANY_PLATFORM 0x00060000 |
Hint value for GLFW_PLATFORM that enables automatic platform selection.
#define GLFW_PLATFORM_WIN32 0x00060001 |
#define GLFW_PLATFORM_COCOA 0x00060002 |
#define GLFW_PLATFORM_WAYLAND 0x00060003 |
#define GLFW_PLATFORM_X11 0x00060004 |
#define GLFW_PLATFORM_NULL 0x00060005 |
typedef void *(* GLFWallocatefun) (size_t size, void *user) |
This is the function pointer type for memory allocation callbacks. A memory allocation callback function has the following signature:
This function must return either a memory block at least size
bytes long, or NULL
if allocation failed. Note that not all parts of GLFW handle allocation failures gracefully yet.
This function may be called during glfwInit but before the library is flagged as initialized, as well as during glfwTerminate after the library is no longer flagged as initialized.
Any memory allocated by this function will be deallocated during library termination or earlier.
The size will always be greater than zero. Allocations of size zero are filtered out before reaching the custom allocator.
[in] | size | The minimum size, in bytes, of the memory block. |
[in] | user | The user-defined pointer from the allocator. |
NULL
if an error occurred.typedef void *(* GLFWreallocatefun) (void *block, size_t size, void *user) |
This is the function pointer type for memory reallocation callbacks. A memory reallocation callback function has the following signature:
This function must return a memory block at least size
bytes long, or NULL
if allocation failed. Note that not all parts of GLFW handle allocation failures gracefully yet.
This function may be called during glfwInit but before the library is flagged as initialized, as well as during glfwTerminate after the library is no longer flagged as initialized.
Any memory allocated by this function will be deallocated during library termination or earlier.
The block address will never be NULL
and the size will always be greater than zero. Reallocations of a block to size zero are converted into deallocations. Reallocations of NULL
to a non-zero size are converted into regular allocations.
[in] | block | The address of the memory block to reallocate. |
[in] | size | The new minimum size, in bytes, of the memory block. |
[in] | user | The user-defined pointer from the allocator. |
NULL
if an error occurred.typedef void(* GLFWdeallocatefun) (void *block, void *user) |
This is the function pointer type for memory deallocation callbacks. A memory deallocation callback function has the following signature:
This function may deallocate the specified memory block. This memory block will have been allocated with the same allocator.
This function may be called during glfwInit but before the library is flagged as initialized, as well as during glfwTerminate after the library is no longer flagged as initialized.
The block address will never be NULL
. Deallocations of NULL
are filtered out before reaching the custom allocator.
[in] | block | The address of the memory block to deallocate. |
[in] | user | The user-defined pointer from the allocator. |
typedef void(* GLFWerrorfun) (int error_code, const char *description) |
This is the function pointer type for error callbacks. An error callback function has the following signature:
[in] | error_code | An error code. Future releases may add more error codes. |
[in] | description | A UTF-8 encoded string describing the error. |
typedef struct GLFWallocator GLFWallocator |
int glfwInit | ( | void | ) |
This function initializes the GLFW library. Before most GLFW functions can be used, GLFW must be initialized, and before an application terminates GLFW should be terminated in order to free any resources allocated during or after initialization.
If this function fails, it calls glfwTerminate before returning. If it succeeds, you should call glfwTerminate before the application exits.
Additional calls to this function after successful initialization but before termination will return GLFW_TRUE
immediately.
The GLFW_PLATFORM init hint controls which platforms are considered during initialization. This also depends on which platforms the library was compiled to support.
GLFW_TRUE
if successful, or GLFW_FALSE
if an error occurred.Contents/Resources
subdirectory of the application's bundle, if present. This can be disabled with the GLFW_COCOA_CHDIR_RESOURCES init hint.MainMenu.nib
it is loaded and assumed to contain a menu bar. Otherwise a minimal menu bar is created manually with common commands like Hide, Quit and About. The About entry opens a minimal about dialog with information from the application's bundle. The menu bar and dock icon can be disabled entirely with the GLFW_COCOA_MENUBAR init hint.LC_CTYPE
category of the application locale according to the current environment if that category is still "C". This is because the "C" locale breaks Unicode text input.void glfwTerminate | ( | void | ) |
This function destroys all remaining windows and cursors, restores any modified gamma ramps and frees any other allocated resources. Once this function is called, you must again call glfwInit successfully before you will be able to use most GLFW functions.
If GLFW has been successfully initialized, this function should be called before the application exits. If initialization fails, there is no need to call this function, as it is called by glfwInit before it returns failure.
This function has no effect if GLFW is not initialized.
void glfwInitHint | ( | int | hint, |
int | value | ||
) |
This function sets hints for the next initialization of GLFW.
The values you set hints to are never reset by GLFW, but they only take effect during initialization. Once GLFW has been initialized, any values you set will be ignored until the library is terminated and initialized again.
Some hints are platform specific. These may be set on any platform but they will only affect their specific platform. Other platforms will ignore them. Setting these hints requires no platform specific headers or functions.
[in] | hint | The init hint to set. |
[in] | value | The new value of the init hint. |
void glfwInitAllocator | ( | const GLFWallocator * | allocator | ) |
To use the default allocator, call this function with a NULL
argument.
If you specify an allocator struct, every member must be a valid function pointer. If any member is NULL
, this function emits GLFW_INVALID_VALUE and the init allocator is unchanged.
[in] | allocator | The allocator to use at the next initialization, or NULL to use the default one. |
void glfwInitVulkanLoader | ( | PFN_vkGetInstanceProcAddr | loader | ) |
This function sets the vkGetInstanceProcAddr
function that GLFW will use for all Vulkan related entry point queries.
This feature is mostly useful on macOS, if your copy of the Vulkan loader is in a location where GLFW cannot find it through dynamic loading, or if you are still using the static library version of the loader.
If set to NULL
, GLFW will try to load the Vulkan loader dynamically by its standard name and get this function from there. This is the default behavior.
The standard name of the loader is vulkan-1.dll
on Windows, libvulkan.so.1
on Linux and other Unix-like systems and libvulkan.1.dylib
on macOS. If your code is also loading it via these names then you probably don't need to use this function.
The function address you set is never reset by GLFW, but it only takes effect during initialization. Once GLFW has been initialized, any updates will be ignored until the library is terminated and initialized again.
[in] | loader | The address of the function to use, or NULL . |
void glfwGetVersion | ( | int * | major, |
int * | minor, | ||
int * | rev | ||
) |
This function retrieves the major, minor and revision numbers of the GLFW library. It is intended for when you are using GLFW as a shared library and want to ensure that you are using the minimum required version.
Any or all of the version arguments may be NULL
.
[out] | major | Where to store the major version number, or NULL . |
[out] | minor | Where to store the minor version number, or NULL . |
[out] | rev | Where to store the revision number, or NULL . |
const char * glfwGetVersionString | ( | void | ) |
This function returns the compile-time generated version string of the GLFW library binary. It describes the version, platforms, compiler and any platform or operating system specific compile-time options. It should not be confused with the OpenGL or OpenGL ES version string, queried with glGetString
.
Do not use the version string to parse the GLFW library version. The glfwGetVersion function provides the version of the running library binary in numerical format.
Do not use the version string to parse what platforms are supported. The glfwPlatformSupported function lets you query platform support.
int glfwGetError | ( | const char ** | description | ) |
This function returns and clears the error code of the last error that occurred on the calling thread, and optionally a UTF-8 encoded human-readable description of it. If no error has occurred since the last call, it returns GLFW_NO_ERROR (zero) and the description pointer is set to NULL
.
[in] | description | Where to store the error description pointer, or NULL . |
GLFWerrorfun glfwSetErrorCallback | ( | GLFWerrorfun | callback | ) |
This function sets the error callback, which is called with an error code and a human-readable description each time a GLFW error occurs.
The error code is set before the callback is called. Calling glfwGetError from the error callback will return the same value as the error code argument.
The error callback is called on the thread where the error occurred. If you are using GLFW from multiple threads, your error callback needs to be written accordingly.
Because the description string may have been generated specifically for that error, it is not guaranteed to be valid after the callback has returned. If you wish to use it after the callback returns, you need to make a copy.
Once set, the error callback remains set even after the library has been terminated.
[in] | callback | The new callback, or NULL to remove the currently set callback. |
NULL
if no callback was set.int glfwGetPlatform | ( | void | ) |
This function returns the platform that was selected during initialization. The returned value will be one of GLFW_PLATFORM_WIN32
, GLFW_PLATFORM_COCOA
, GLFW_PLATFORM_WAYLAND
, GLFW_PLATFORM_X11
or GLFW_PLATFORM_NULL
.
int glfwPlatformSupported | ( | int | platform | ) |
This function returns whether the library was compiled with support for the specified platform. The platform must be one of GLFW_PLATFORM_WIN32
, GLFW_PLATFORM_COCOA
, GLFW_PLATFORM_WAYLAND
, GLFW_PLATFORM_X11
or GLFW_PLATFORM_NULL
.
[in] | platform | The platform to query. |
GLFW_TRUE
if the platform is supported, or GLFW_FALSE
otherwise.Last update on Thu Mar 2 2023 for GLFW 3.4.0