diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index 820004e01..6fcd6ad9f 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -1554,6 +1554,8 @@ typedef struct GLFWgamepadstate * Additional calls to this function after successful initialization but before * termination will return `GLFW_TRUE` immediately. * + * To check whether GLFW has been initialized, call @ref glfwIsInit. + * * @return `GLFW_TRUE` if successful, or `GLFW_FALSE` if an * [error](@ref error_handling) occurred. * @@ -1568,6 +1570,7 @@ typedef struct GLFWgamepadstate * * @sa @ref intro_init * @sa @ref glfwTerminate + * @sa @ref glfwIsInit * * @since Added in version 1.0. * @@ -1575,6 +1578,26 @@ typedef struct GLFWgamepadstate */ GLFWAPI int glfwInit(void); + +/*! @brief Checks if GLFW has been initialized + * + * This function checks the state of GLFW and returns whether it is initalized. + * Before most GLFW functions, GLFW must be initialized via @ref glfwInit. @ref glfwTerminate + * frees any remaining resources by GLFW and should be called at the end of the application. + * + * @return `GLFW_TRUE` if initialized, `GLFW_FALSE` otherwise + * + * @sa @ref intro_init + * @sa @ref glfwInit + * @sa @ref glfwTerminate + * @since Added in version 3.2.1 + * + * @thread_safety This function must only be called from the main thread. + * + * @ingroup init +*/ +GLFWAPI int glfwIsInit(void); + /*! @brief Terminates the GLFW library. * * This function destroys all remaining windows and cursors, restores any @@ -1600,6 +1623,7 @@ GLFWAPI int glfwInit(void); * * @sa @ref intro_init * @sa @ref glfwInit + * @sa @ref glfwIsInit * * @since Added in version 1.0. * diff --git a/src/init.c b/src/init.c index 7f7d87eab..5a066306a 100644 --- a/src/init.c +++ b/src/init.c @@ -220,6 +220,11 @@ GLFWAPI int glfwInit(void) return GLFW_TRUE; } +GLFWAPI int glfwIsInit(void) +{ + return _glfw.initialized; +} + GLFWAPI void glfwTerminate(void) { if (!_glfw.initialized)