Loading...
Searching...
No Matches
Typedefs | Functions
Context reference

Description

This is the reference documentation for OpenGL and OpenGL ES context related functions. For more task-oriented information, see the Context guide.

Typedefs

typedef void(* GLFWglproc) (void)
 Client API function pointer type.
 

Functions

void glfwMakeContextCurrent (GLFWwindow *window)
 Makes the context of the specified window current for the calling thread.
 
GLFWwindowglfwGetCurrentContext (void)
 Returns the window whose context is current on the calling thread.
 
void glfwSwapInterval (int interval)
 Sets the swap interval for the current context.
 
int glfwExtensionSupported (const char *extension)
 Returns whether the specified extension is available.
 
GLFWglproc glfwGetProcAddress (const char *procname)
 Returns the address of the specified function for the current context.
 

Typedef Documentation

◆ GLFWglproc

typedef void(* GLFWglproc) (void)

Generic function pointer used for returning client API function pointers without forcing a cast from a regular pointer.

See also
OpenGL and OpenGL ES extensions
glfwGetProcAddress
Since
Added in version 3.0.

Function Documentation

◆ glfwMakeContextCurrent()

void glfwMakeContextCurrent ( GLFWwindow window)

This function makes the OpenGL or OpenGL ES context of the specified window current on the calling thread. It can also detach the current context from the calling thread without making a new one current by passing in NULL.

A context must only be made current on a single thread at a time and each thread can have only a single current context at a time. Making a context current detaches any previously current context on the calling thread.

When moving a context between threads, you must detach it (make it non-current) on the old thread before making it current on the new one.

By default, making a context non-current implicitly forces a pipeline flush. On machines that support GL_KHR_context_flush_control, you can control whether a context performs this flush by setting the GLFW_CONTEXT_RELEASE_BEHAVIOR hint.

The specified window must have an OpenGL or OpenGL ES context. Specifying a window without a context will generate a GLFW_NO_WINDOW_CONTEXT error.

Parameters
[in]windowThe window whose context to make current, or NULL to detach the current context.
Remarks
If the previously current context was created via a different context creation API than the one passed to this function, GLFW will still detach the previous one from its API before making the new one current.
Errors
Possible errors include GLFW_NOT_INITIALIZED, GLFW_NO_WINDOW_CONTEXT and GLFW_PLATFORM_ERROR.
Thread safety
This function may be called from any thread.
See also
Current context
glfwGetCurrentContext
Since
Added in version 3.0.

◆ glfwGetCurrentContext()

GLFWwindow * glfwGetCurrentContext ( void  )

This function returns the window whose OpenGL or OpenGL ES context is current on the calling thread.

Returns
The window whose context is current, or NULL if no window's context is current.
Errors
Possible errors include GLFW_NOT_INITIALIZED.
Thread safety
This function may be called from any thread.
See also
Current context
glfwMakeContextCurrent
Since
Added in version 3.0.

◆ glfwSwapInterval()

void glfwSwapInterval ( int  interval)

This function sets the swap interval for the current OpenGL or OpenGL ES context, i.e. the number of screen updates to wait from the time glfwSwapBuffers was called before swapping the buffers and returning. This is sometimes called vertical synchronization, vertical retrace synchronization or just vsync.

A context that supports either of the WGL_EXT_swap_control_tear and GLX_EXT_swap_control_tear extensions also accepts negative swap intervals, which allows the driver to swap immediately even if a frame arrives a little bit late. You can check for these extensions with glfwExtensionSupported.

A context must be current on the calling thread. Calling this function without a current context will cause a GLFW_NO_CURRENT_CONTEXT error.

This function does not apply to Vulkan. If you are rendering with Vulkan, see the present mode of your swapchain instead.

Parameters
[in]intervalThe minimum number of screen updates to wait for until the buffers are swapped by glfwSwapBuffers.
Errors
Possible errors include GLFW_NOT_INITIALIZED, GLFW_NO_CURRENT_CONTEXT and GLFW_PLATFORM_ERROR.
Remarks
This function is not called during context creation, leaving the swap interval set to whatever is the default for that API. This is done because some swap interval extensions used by GLFW do not allow the swap interval to be reset to zero once it has been set to a non-zero value.
Some GPU drivers do not honor the requested swap interval, either because of a user setting that overrides the application's request or due to bugs in the driver.
Thread safety
This function may be called from any thread.
See also
Buffer swapping
glfwSwapBuffers
Since
Added in version 1.0.

◆ glfwExtensionSupported()

int glfwExtensionSupported ( const char *  extension)

This function returns whether the specified API extension is supported by the current OpenGL or OpenGL ES context. It searches both for client API extension and context creation API extensions.

A context must be current on the calling thread. Calling this function without a current context will cause a GLFW_NO_CURRENT_CONTEXT error.

As this functions retrieves and searches one or more extension strings each call, it is recommended that you cache its results if it is going to be used frequently. The extension strings will not change during the lifetime of a context, so there is no danger in doing this.

This function does not apply to Vulkan. If you are using Vulkan, see glfwGetRequiredInstanceExtensions, vkEnumerateInstanceExtensionProperties and vkEnumerateDeviceExtensionProperties instead.

Parameters
[in]extensionThe ASCII encoded name of the extension.
Returns
GLFW_TRUE if the extension is available, or GLFW_FALSE otherwise.
Errors
Possible errors include GLFW_NOT_INITIALIZED, GLFW_NO_CURRENT_CONTEXT, GLFW_INVALID_VALUE and GLFW_PLATFORM_ERROR.
Thread safety
This function may be called from any thread.
See also
OpenGL and OpenGL ES extensions
glfwGetProcAddress
Since
Added in version 1.0.

◆ glfwGetProcAddress()

GLFWglproc glfwGetProcAddress ( const char *  procname)

This function returns the address of the specified OpenGL or OpenGL ES core or extension function, if it is supported by the current context.

A context must be current on the calling thread. Calling this function without a current context will cause a GLFW_NO_CURRENT_CONTEXT error.

This function does not apply to Vulkan. If you are rendering with Vulkan, see glfwGetInstanceProcAddress, vkGetInstanceProcAddr and vkGetDeviceProcAddr instead.

Parameters
[in]procnameThe ASCII encoded name of the function.
Returns
The address of the function, or NULL if an error occurred.
Errors
Possible errors include GLFW_NOT_INITIALIZED, GLFW_NO_CURRENT_CONTEXT and GLFW_PLATFORM_ERROR.
Remarks
The address of a given function is not guaranteed to be the same between contexts.
This function may return a non-NULL address despite the associated version or extension not being available. Always check the context version or extension string first.
Pointer lifetime
The returned function pointer is valid until the context is destroyed or the library is terminated.
Thread safety
This function may be called from any thread.
See also
OpenGL and OpenGL ES extensions
glfwExtensionSupported
Since
Added in version 1.0.