Class GL
- Loads the OpenGL native library into the JVM process.
- Creates instances of
GLCapabilitiesclasses. AGLCapabilitiesinstance contains flags for functionality that is available in an OpenGL context. Internally, it also contains function pointers that are only valid in that specific OpenGL context. - Maintains thread-local state for
GLCapabilitiesinstances, corresponding to OpenGL contexts that are current in those threads.
Library lifecycle
The OpenGL library is loaded automatically when this class is initialized. Set the Configuration.OPENGL_EXPLICIT_INIT option to override this
behavior. Manual loading/unloading can be achieved with the create() and destroy() functions. The name of the library loaded can be overridden
with the Configuration.OPENGL_LIBRARY_NAME option. The maximum OpenGL version loaded can be set with the Configuration.OPENGL_MAXVERSION
option. This can be useful to ensure that no functionality above a specific version is used during development.
GLCapabilities creation
Instances of GLCapabilities can be created with the createCapabilities() method. An OpenGL context must be current in the current thread
before it is called. Calling this method is expensive, so the GLCapabilities instance should be associated with the OpenGL context and reused as
necessary.
Thread-local state
Before a function for a given OpenGL context can be called, the corresponding GLCapabilities instance must be passed to the
setCapabilities(org.lwjgl.opengl.GLCapabilities) method. The user is also responsible for clearing the current GLCapabilities instance when the context is destroyed or made
current in another thread.
Note that the createCapabilities() method implicitly calls setCapabilities(org.lwjgl.opengl.GLCapabilities) with the newly created instance.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidcreate()Loads the OpenGL native library, using the default library name.static voidLoads the OpenGL native library, using the specified library name.static voidcreate(FunctionProvider functionProvider) Initializes OpenGL with the specifiedFunctionProvider.static GLCapabilitiesCreates a newGLCapabilitiesinstance for the OpenGL context that is current in the current thread.static GLCapabilitiescreateCapabilities(boolean forwardCompatible) Creates a newGLCapabilitiesinstance for the OpenGL context that is current in the current thread.static GLCapabilitiescreateCapabilities(boolean forwardCompatible, @Nullable IntFunction<PointerBuffer> bufferFactory) Creates a newGLCapabilitiesinstance for the OpenGL context that is current in the current thread.static GLCapabilitiescreateCapabilities(@Nullable IntFunction<PointerBuffer> bufferFactory) Creates a newGLCapabilitiesinstance for the OpenGL context that is current in the current thread.static GLXCapabilitiescreateCapabilitiesGLX(long display) Creates aGLXCapabilitiesinstance for the default screen of the specified X connection.static GLXCapabilitiescreateCapabilitiesGLX(long display, int screen) Creates aGLXCapabilitiesinstance for the specified screen of the specified X connection.static WGLCapabilitiesCreates aWGLCapabilitiesinstance for the context that is current in the current thread.static voiddestroy()Unloads the OpenGL native library.static GLCapabilitiesReturns theGLCapabilitiesof the OpenGL context that is current in the current thread.static GLXCapabilitiesReturns the GLX capabilities.static WGLCapabilitiesReturns the WGL capabilities.static @Nullable FunctionProviderReturns theFunctionProviderfor the OpenGL native library.static voidsetCapabilities(@Nullable GLCapabilities caps) Sets theGLCapabilitiesof the OpenGL context that is current in the current thread.
-
Method Details
-
create
public static void create()Loads the OpenGL native library, using the default library name. -
create
Loads the OpenGL native library, using the specified library name.- Parameters:
libName- the native library name
-
create
Initializes OpenGL with the specifiedFunctionProvider. This method can be used to implement custom OpenGL library loading.- Parameters:
functionProvider- the provider of OpenGL function addresses
-
destroy
public static void destroy()Unloads the OpenGL native library. -
getFunctionProvider
Returns theFunctionProviderfor the OpenGL native library. -
setCapabilities
Sets theGLCapabilitiesof the OpenGL context that is current in the current thread.This
GLCapabilitiesinstance will be used by any OpenGL call in the current thread, untilsetCapabilitiesis called again with a different value. -
getCapabilities
Returns theGLCapabilitiesof the OpenGL context that is current in the current thread.- Throws:
IllegalStateException- ifsetCapabilities(org.lwjgl.opengl.GLCapabilities)has never been called in the current thread or was last called with anullvalue
-
getCapabilitiesWGL
Returns the WGL capabilities.This method may only be used on Windows.
-
getCapabilitiesGLX
Returns the GLX capabilities.This method may only be used on Linux.
-
createCapabilities
Creates a newGLCapabilitiesinstance for the OpenGL context that is current in the current thread.Depending on the current context, the instance returned may or may not contain the deprecated functionality removed since OpenGL version 3.1.
This method calls
setCapabilities(GLCapabilities)with the new instance before returning.- Returns:
- the GLCapabilities instance
-
createCapabilities
Creates a newGLCapabilitiesinstance for the OpenGL context that is current in the current thread.Depending on the current context, the instance returned may or may not contain the deprecated functionality removed since OpenGL version 3.1.
This method calls
setCapabilities(GLCapabilities)with the new instance before returning.- Parameters:
bufferFactory- a function that allocates aPointerBuffergiven a size. The buffer must be filled with zeroes. Ifnull, LWJGL will allocate a GC-managed buffer internally.- Returns:
- the GLCapabilities instance
-
createCapabilities
Creates a newGLCapabilitiesinstance for the OpenGL context that is current in the current thread.Depending on the current context, the instance returned may or may not contain the deprecated functionality removed since OpenGL version 3.1. The
forwardCompatibleflag will force LWJGL to not load the deprecated functions, even if the current context exposes them.This method calls
setCapabilities(GLCapabilities)with the new instance before returning.- Parameters:
forwardCompatible- if true, LWJGL will create forward compatible capabilities- Returns:
- the GLCapabilities instance
-
createCapabilities
public static GLCapabilities createCapabilities(boolean forwardCompatible, @Nullable IntFunction<PointerBuffer> bufferFactory) Creates a newGLCapabilitiesinstance for the OpenGL context that is current in the current thread.Depending on the current context, the instance returned may or may not contain the deprecated functionality removed since OpenGL version 3.1. The
forwardCompatibleflag will force LWJGL to not load the deprecated functions, even if the current context exposes them.This method calls
setCapabilities(GLCapabilities)with the new instance before returning.- Parameters:
forwardCompatible- if true, LWJGL will create forward compatible capabilitiesbufferFactory- a function that allocates aPointerBuffergiven a size. Ifnull, LWJGL will allocate a GC-managed buffer internally.- Returns:
- the GLCapabilities instance
-
createCapabilitiesWGL
Creates aWGLCapabilitiesinstance for the context that is current in the current thread.This method may only be used on Windows.
-
createCapabilitiesGLX
Creates aGLXCapabilitiesinstance for the default screen of the specified X connection.This method may only be used on Linux.
- Parameters:
display- the X connection handle (DISPLAY)
-
createCapabilitiesGLX
Creates aGLXCapabilitiesinstance for the specified screen of the specified X connection.This method may only be used on Linux.
- Parameters:
display- the X connection handle (DISPLAY)screen- the screen index
-