raygui-widget
Modules | Classes | Macros | Typedefs | Functions
Initialization, version and error reference

Functions and types related to initialization and error handling. More...

Collaboration diagram for Initialization, version and error reference:

Modules

 Error codes
 Error codes.
 

Classes

struct  GLFWallocator
 Custom heap memory allocator. More...
 

Macros

#define GLFW_TRUE   1
 One. More...
 
#define GLFW_FALSE   0
 Zero. More...
 
#define GLFW_JOYSTICK_HAT_BUTTONS   0x00050001
 Joystick hat buttons init hint. More...
 
#define GLFW_COCOA_CHDIR_RESOURCES   0x00051001
 macOS specific init hint. More...
 
#define GLFW_COCOA_MENUBAR   0x00051002
 macOS specific init hint. More...
 
#define GLFW_TRUE   1
 One. More...
 
#define GLFW_FALSE   0
 Zero. More...
 
#define GLFW_JOYSTICK_HAT_BUTTONS   0x00050001
 Joystick hat buttons init hint. More...
 
#define GLFW_ANGLE_PLATFORM_TYPE   0x00050002
 ANGLE rendering backend init hint. More...
 
#define GLFW_PLATFORM   0x00050003
 Platform selection init hint. More...
 
#define GLFW_COCOA_CHDIR_RESOURCES   0x00051001
 macOS specific init hint. More...
 
#define GLFW_COCOA_MENUBAR   0x00051002
 macOS specific init hint. More...
 
#define GLFW_X11_XCB_VULKAN_SURFACE   0x00052001
 X11 specific init hint. More...
 
#define GLFW_WAYLAND_LIBDECOR   0x00053001
 Wayland specific init hint. More...
 
#define GLFW_ANY_PLATFORM   0x00060000
 Hint value that enables automatic platform selection. More...
 
#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(* GLFWerrorfun) (int error_code, const char *description)
 The function pointer type for error callbacks. More...
 
typedef void *(* GLFWallocatefun) (size_t size, void *user)
 The function pointer type for memory allocation callbacks. More...
 
typedef void *(* GLFWreallocatefun) (void *block, size_t size, void *user)
 The function pointer type for memory reallocation callbacks. More...
 
typedef void(* GLFWdeallocatefun) (void *block, void *user)
 The function pointer type for memory deallocation callbacks. More...
 
typedef void(* GLFWerrorfun) (int error_code, const char *description)
 The function pointer type for error callbacks. More...
 
typedef struct GLFWallocator GLFWallocator
 Custom heap memory allocator. More...
 

Functions

GLFWAPI int glfwInit (void)
 Initializes the GLFW library. More...
 
GLFWAPI void glfwTerminate (void)
 Terminates the GLFW library. More...
 
GLFWAPI void glfwInitHint (int hint, int value)
 Sets the specified init hint to the desired value. More...
 
GLFWAPI void glfwGetVersion (int *major, int *minor, int *rev)
 Retrieves the version of the GLFW library. More...
 
GLFWAPI const char * glfwGetVersionString (void)
 Returns a string describing the compile-time configuration. More...
 
GLFWAPI int glfwGetError (const char **description)
 Returns and clears the last error for the calling thread. More...
 
GLFWAPI GLFWerrorfun glfwSetErrorCallback (GLFWerrorfun callback)
 Sets the error callback. More...
 
GLFWAPI void glfwInitAllocator (const GLFWallocator *allocator)
 Sets the init allocator to the desired value. More...
 
GLFWAPI int glfwGetPlatform (void)
 Returns the currently selected platform. More...
 
GLFWAPI int glfwPlatformSupported (int platform)
 Returns whether the library includes support for the specified platform. More...
 

GLFW version macros

#define GLFW_VERSION_MAJOR   3
 The major version number of the GLFW header. More...
 
#define GLFW_VERSION_MINOR   3
 The minor version number of the GLFW header. More...
 
#define GLFW_VERSION_REVISION   8
 The revision number of the GLFW header. More...
 

GLFW version macros

#define GLFW_VERSION_MAJOR   3
 The major version number of the GLFW header. More...
 
#define GLFW_VERSION_MINOR   4
 The minor version number of the GLFW header. More...
 
#define GLFW_VERSION_REVISION   0
 The revision number of the GLFW header. More...
 

Detailed Description

Functions and types related to initialization and error handling.

This is the reference documentation for initialization and termination of the library, version management and error handling. For more task-oriented information, see the intro_guide.

Macro Definition Documentation

◆ GLFW_ANGLE_PLATFORM_TYPE

#define GLFW_ANGLE_PLATFORM_TYPE   0x00050002

ANGLE rendering backend init hint.

ANGLE rendering backend init hint.

◆ GLFW_ANY_PLATFORM

#define GLFW_ANY_PLATFORM   0x00060000

Hint value that enables automatic platform selection.

Hint value for GLFW_PLATFORM that enables automatic platform selection.

◆ GLFW_COCOA_CHDIR_RESOURCES [1/2]

#define GLFW_COCOA_CHDIR_RESOURCES   0x00051001

macOS specific init hint.

macOS specific init hint.

◆ GLFW_COCOA_CHDIR_RESOURCES [2/2]

#define GLFW_COCOA_CHDIR_RESOURCES   0x00051001

macOS specific init hint.

macOS specific init hint.

◆ GLFW_COCOA_MENUBAR [1/2]

#define GLFW_COCOA_MENUBAR   0x00051002

macOS specific init hint.

macOS specific init hint.

◆ GLFW_COCOA_MENUBAR [2/2]

#define GLFW_COCOA_MENUBAR   0x00051002

macOS specific init hint.

macOS specific init hint.

◆ GLFW_FALSE [1/2]

#define GLFW_FALSE   0

Zero.

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.

◆ GLFW_FALSE [2/2]

#define GLFW_FALSE   0

Zero.

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.

◆ GLFW_JOYSTICK_HAT_BUTTONS [1/2]

#define GLFW_JOYSTICK_HAT_BUTTONS   0x00050001

Joystick hat buttons init hint.

Joystick hat buttons init hint.

◆ GLFW_JOYSTICK_HAT_BUTTONS [2/2]

#define GLFW_JOYSTICK_HAT_BUTTONS   0x00050001

Joystick hat buttons init hint.

Joystick hat buttons init hint.

◆ GLFW_PLATFORM

#define GLFW_PLATFORM   0x00050003

Platform selection init hint.

Platform selection init hint.

◆ GLFW_TRUE [1/2]

#define GLFW_TRUE   1

One.

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.

◆ GLFW_TRUE [2/2]

#define GLFW_TRUE   1

One.

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.

◆ GLFW_VERSION_MAJOR [1/2]

#define GLFW_VERSION_MAJOR   3

The major version number of the GLFW header.

The major version number of the GLFW header. This is incremented when the API is changed in non-compatible ways.

◆ GLFW_VERSION_MAJOR [2/2]

#define GLFW_VERSION_MAJOR   3

The major version number of the GLFW header.

The major version number of the GLFW header. This is incremented when the API is changed in non-compatible ways.

◆ GLFW_VERSION_MINOR [1/2]

#define GLFW_VERSION_MINOR   3

The minor version number of the GLFW header.

The minor version number of the GLFW header. This is incremented when features are added to the API but it remains backward-compatible.

◆ GLFW_VERSION_MINOR [2/2]

#define GLFW_VERSION_MINOR   4

The minor version number of the GLFW header.

The minor version number of the GLFW header. This is incremented when features are added to the API but it remains backward-compatible.

◆ GLFW_VERSION_REVISION [1/2]

#define GLFW_VERSION_REVISION   0

The revision number of the GLFW header.

The revision number of the GLFW header. This is incremented when a bug fix release is made that does not contain any API changes.

◆ GLFW_VERSION_REVISION [2/2]

#define GLFW_VERSION_REVISION   8

The revision number of the GLFW header.

The revision number of the GLFW header. This is incremented when a bug fix release is made that does not contain any API changes.

◆ GLFW_WAYLAND_LIBDECOR

#define GLFW_WAYLAND_LIBDECOR   0x00053001

Wayland specific init hint.

Wayland specific init hint.

◆ GLFW_X11_XCB_VULKAN_SURFACE

#define GLFW_X11_XCB_VULKAN_SURFACE   0x00052001

X11 specific init hint.

X11 specific init hint.

Typedef Documentation

◆ GLFWallocatefun

typedef void*(* GLFWallocatefun) (size_t size, void *user)

The function pointer type for memory allocation callbacks.

This is the function pointer type for memory allocation callbacks. A memory allocation callback function has the following signature:

void* function_name(size_t size, void* user)

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 must support being 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 via this function will be deallocated via the same allocator during library termination or earlier.

Any memory allocated via this function must be suitably aligned for any object type. If you are using C99 or earlier, this alignment is platform-dependent but will be the same as what malloc provides. If you are using C11 or later, this is the value of alignof(max_align_t).

The size will always be greater than zero. Allocations of size zero are filtered out before reaching the custom allocator.

If this function returns NULL, GLFW will emit GLFW_OUT_OF_MEMORY.

This function must not call any GLFW function.

Parameters
[in]sizeThe minimum size, in bytes, of the memory block.
[in]userThe user-defined pointer from the allocator.
Returns
The address of the newly allocated memory block, or NULL if an error occurred.

The returned memory block must be valid at least until it is deallocated.

This function should not call any GLFW function.

This function must support being called from any thread that calls GLFW functions.

See also
init_allocator
GLFWallocator
Since
Added in version 3.4.

◆ GLFWallocator

typedef struct GLFWallocator GLFWallocator

Custom heap memory allocator.

This describes a custom heap memory allocator for GLFW. To set an allocator, pass it to glfwInitAllocator before initializing the library.

See also
init_allocator
glfwInitAllocator
Since
Added in version 3.4.

◆ GLFWdeallocatefun

typedef void(* GLFWdeallocatefun) (void *block, void *user)

The function pointer type for memory deallocation callbacks.

This is the function pointer type for memory deallocation callbacks. A memory deallocation callback function has the following signature:

void function_name(void* block, void* user)

This function may deallocate the specified memory block. This memory block will have been allocated with the same allocator.

This function must support being 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.

If this function returns NULL, GLFW will emit GLFW_OUT_OF_MEMORY.

This function must not call any GLFW function.

Parameters
[in]blockThe address of the memory block to deallocate.
[in]userThe user-defined pointer from the allocator.

The specified memory block will not be accessed by GLFW after this function is called.

This function should not call any GLFW function.

This function must support being called from any thread that calls GLFW functions.

See also
init_allocator
GLFWallocator
Since
Added in version 3.4.

◆ GLFWerrorfun [1/2]

typedef void(* GLFWerrorfun) (int error_code, const char *description)

The function pointer type for error callbacks.

This is the function pointer type for error callbacks. An error callback function has the following signature:

void callback_name(int error_code, const char* description)
Parameters
[in]error_codeAn error code. Future releases may add more error codes.
[in]descriptionA UTF-8 encoded string describing the error.

The error description string is valid until the callback function returns.

See also
error_handling
glfwSetErrorCallback
Since
Added in version 3.0.

◆ GLFWerrorfun [2/2]

typedef void(* GLFWerrorfun) (int error_code, const char *description)

The function pointer type for error callbacks.

This is the function pointer type for error callbacks. An error callback function has the following signature:

void callback_name(int error_code, const char* description)
Parameters
[in]error_codeAn error code. Future releases may add more error codes.
[in]descriptionA UTF-8 encoded string describing the error.

The error description string is valid until the callback function returns.

See also
error_handling
glfwSetErrorCallback
Since
Added in version 3.0.

◆ GLFWreallocatefun

typedef void*(* GLFWreallocatefun) (void *block, size_t size, void *user)

The function pointer type for memory reallocation callbacks.

This is the function pointer type for memory reallocation callbacks. A memory reallocation callback function has the following signature:

void* function_name(void* block, size_t size, void* user)

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 must support being 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 via this function will be deallocated via the same allocator during library termination or earlier.

Any memory allocated via this function must be suitably aligned for any object type. If you are using C99 or earlier, this alignment is platform-dependent but will be the same as what realloc provides. If you are using C11 or later, this is the value of alignof(max_align_t).

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 before reaching the custom allocator. Reallocations of NULL to a non-zero size are converted into regular allocations before reaching the custom allocator.

If this function returns NULL, GLFW will emit GLFW_OUT_OF_MEMORY.

This function must not call any GLFW function.

Parameters
[in]blockThe address of the memory block to reallocate.
[in]sizeThe new minimum size, in bytes, of the memory block.
[in]userThe user-defined pointer from the allocator.
Returns
The address of the newly allocated or resized memory block, or NULL if an error occurred.

The returned memory block must be valid at least until it is deallocated.

This function should not call any GLFW function.

This function must support being called from any thread that calls GLFW functions.

See also
init_allocator
GLFWallocator
Since
Added in version 3.4.

Function Documentation

◆ glfwGetError()

GLFWAPI int glfwGetError ( const char **  description)

Returns and clears the last error for the calling thread.

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.

Parameters
[in]descriptionWhere to store the error description pointer, or NULL.
Returns
The last error code for the calling thread, or GLFW_NO_ERROR (zero).

None.

The returned string is allocated and freed by GLFW. You should not free it yourself. It is guaranteed to be valid only until the next error occurs or the library is terminated.

Remarks
This function may be called before glfwInit.

This function may be called from any thread.

See also
error_handling
glfwSetErrorCallback
Since
Added in version 3.3.

◆ glfwGetPlatform()

GLFWAPI int glfwGetPlatform ( void  )

Returns the currently selected platform.

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.

Returns
The currently selected platform, or zero if an error occurred.

Possible errors include GLFW_NOT_INITIALIZED.

This function may be called from any thread.

See also
platform
glfwPlatformSupported
Since
Added in version 3.4.

◆ glfwGetVersion()

GLFWAPI void glfwGetVersion ( int *  major,
int *  minor,
int *  rev 
)

Retrieves the version of the GLFW library.

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.

Parameters
[out]majorWhere to store the major version number, or NULL.
[out]minorWhere to store the minor version number, or NULL.
[out]revWhere to store the revision number, or NULL.

None.

Remarks
This function may be called before glfwInit.

This function may be called from any thread.

See also
intro_version
glfwGetVersionString
Since
Added in version 1.0.

◆ glfwGetVersionString()

GLFWAPI const char * glfwGetVersionString ( void  )

Returns a string describing the compile-time configuration.

This function returns the compile-time generated version string of the GLFW library binary. It describes the version, platform, compiler and any platform-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.

Returns
The ASCII encoded GLFW version string.

None.

Remarks
This function may be called before glfwInit.

The returned string is static and compile-time generated.

This function may be called from any thread.

See also
intro_version
glfwGetVersion
Since
Added in version 3.0.

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.

Returns
The ASCII encoded GLFW version string.

None.

Remarks
This function may be called before glfwInit.

The returned string is static and compile-time generated.

This function may be called from any thread.

See also
intro_version
glfwGetVersion
Since
Added in version 3.0.

◆ glfwInit()

GLFWAPI int glfwInit ( void  )

Initializes the GLFW library.

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.

Returns
GLFW_TRUE if successful, or GLFW_FALSE if an error occurred.

Possible errors include GLFW_PLATFORM_ERROR.

Remarks
This function will change the current directory of the application to the Contents/Resources subdirectory of the application's bundle, if present. This can be disabled with the GLFW_COCOA_CHDIR_RESOURCES init hint.
This function will set the 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.

This function must only be called from the main thread.

See also
intro_init
glfwTerminate
Since
Added in version 1.0.

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.

Returns
GLFW_TRUE if successful, or GLFW_FALSE if an error occurred.

Possible errors include GLFW_PLATFORM_UNAVAILABLE and GLFW_PLATFORM_ERROR.

Remarks
This function will change the current directory of the application to the Contents/Resources subdirectory of the application's bundle, if present. This can be disabled with the GLFW_COCOA_CHDIR_RESOURCES init hint.
This function will create the main menu and dock icon for the application. If GLFW finds a 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.
Wayland, X11: If the library was compiled with support for both Wayland and X11, and the GLFW_PLATFORM init hint is set to GLFW_ANY_PLATFORM, the XDG_SESSION_TYPE environment variable affects which platform is picked. If the environment variable is not set, or is set to something other than wayland or x11, the regular detection mechanism will be used instead.
This function will set the 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.

This function must only be called from the main thread.

See also
intro_init
glfwInitHint
glfwInitAllocator
glfwTerminate
Since
Added in version 1.0.

◆ glfwInitAllocator()

GLFWAPI void glfwInitAllocator ( const GLFWallocator allocator)

Sets the init allocator to the desired value.

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 will emit GLFW_INVALID_VALUE and the init allocator will be unchanged.

The functions in the allocator must fulfil a number of requirements. See the documentation for GLFWallocatefun, GLFWreallocatefun and GLFWdeallocatefun for details.

Parameters
[in]allocatorThe allocator to use at the next initialization, or NULL to use the default one.

Possible errors include GLFW_INVALID_VALUE.

The specified allocator is copied before this function returns.

This function must only be called from the main thread.

See also
init_allocator
glfwInit
Since
Added in version 3.4.

◆ glfwInitHint()

GLFWAPI void glfwInitHint ( int  hint,
int  value 
)

Sets the specified init hint to the desired 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.

Parameters
[in]hintThe init hint to set.
[in]valueThe new value of the init hint.

Possible errors include GLFW_INVALID_ENUM and GLFW_INVALID_VALUE.

Remarks
This function may be called before glfwInit.

This function must only be called from the main thread.

See also
init_hints
glfwInit
Since
Added in version 3.3.

◆ glfwPlatformSupported()

GLFWAPI int glfwPlatformSupported ( int  platform)

Returns whether the library includes support for the specified 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.

Parameters
[in]platformThe platform to query.
Returns
GLFW_TRUE if the platform is supported, or GLFW_FALSE otherwise.

Possible errors include GLFW_INVALID_ENUM.

Remarks
This function may be called before glfwInit.

This function may be called from any thread.

See also
platform
glfwGetPlatform
Since
Added in version 3.4.

◆ glfwSetErrorCallback()

GLFWAPI GLFWerrorfun glfwSetErrorCallback ( GLFWerrorfun  callback)

Sets the error 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.

Parameters
[in]callbackThe new callback, or NULL to remove the currently set callback.
Returns
The previously set callback, or NULL if no callback was set.
void callback_name(int error_code, const char* description)

For more information about the callback parameters, see the callback pointer type.

None.

Remarks
This function may be called before glfwInit.

This function must only be called from the main thread.

See also
error_handling
glfwGetError
Since
Added in version 3.0.

◆ glfwTerminate()

GLFWAPI void glfwTerminate ( void  )

Terminates the GLFW library.

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.

Possible errors include GLFW_PLATFORM_ERROR.

Remarks
This function may be called before glfwInit.
Warning
The contexts of any remaining windows must not be current on any other thread when this function is called.

This function must not be called from a callback.

This function must only be called from the main thread.

See also
intro_init
glfwInit
Since
Added in version 1.0.