Initialization, version and error reference

Overview

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.

// typedefs

typedef void (*GLFWerrorfun)(
    int,
    const char *
    );

// global functions

GLFWAPI int glfwInit(void);
GLFWAPI void glfwTerminate(void);
GLFWAPI void glfwGetVersion(int* major, int* minor, int* rev);
GLFWAPI const char* glfwGetVersionString(void);
GLFWAPI GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun cbfun);

// macros

#define GLFW_VERSION_MAJOR
#define GLFW_VERSION_MINOR
#define GLFW_VERSION_REVISION

Typedefs

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

The function signature for error callbacks.

This is the function signature for error callback functions.

Added in version 3.0.

Parameters:

error

An error code.

description

A UTF-8 encoded string describing the error.

See also:

error_handling

glfwSetErrorCallback

Global Functions

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.

@errors Possible errors include GLFW_PLATFORM_ERROR.

@osx 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 a compile-time option.

@thread_safety This function must only be called from the main thread.

Added in version 1.0.

Returns:

GLFW_TRUE if successful, or GLFW_FALSE if an error occurred.

See also:

intro_init

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.

@errors Possible errors include GLFW_PLATFORM_ERROR.

This function may be called before glfwInit.

The contexts of any remaining windows must not be current on any other thread when this function is called.

@reentrancy This function must not be called from a callback.

@thread_safety This function must only be called from the main thread.

Added in version 1.0.

See also:

intro_init

glfwInit

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.

@errors None.

This function may be called before glfwInit.

@thread_safety This function may be called from any thread.

Added in version 1.0.

Parameters:

major

Where to store the major version number, or NULL.

minor

Where to store the minor version number, or NULL.

rev

Where to store the revision number, or NULL.

See also:

intro_version

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.

@errors None.

This function may be called before glfwInit.

@pointer_lifetime The returned string is static and compile-time generated.

@thread_safety This function may be called from any thread.

Added in version 3.0.

Returns:

The ASCII encoded GLFW version string.

See also:

intro_version

glfwGetVersion

GLFWAPI GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun cbfun)

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 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.

@errors None.

This function may be called before glfwInit.

@thread_safety This function must only be called from the main thread.

Added in version 3.0.

Parameters:

cbfun

The new callback, or NULL to remove the currently set callback.

Returns:

The previously set callback, or NULL if no callback was set.

See also:

error_handling

Macros

#define GLFW_VERSION_MAJOR

The major version number of the GLFW library.

This is incremented when the API is changed in non-compatible ways.

#define GLFW_VERSION_MINOR

The minor version number of the GLFW library.

This is incremented when features are added to the API but it remains backward-compatible.

#define GLFW_VERSION_REVISION

The revision number of the GLFW library.

This is incremented when a bug fix release is made that does not contain any API changes.