Class GL
- java.lang.Object
-
- org.lwjgl.opengl.GL
-
public final class GL extends java.lang.ObjectThis class must be used before any OpenGL function is called. It has the following responsibilities:- 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_INIToption to override this behavior. Manual loading/unloading can be achieved with theGL.create()andGL.destroy()functions. The name of the library loaded can be overridden with theConfiguration.OPENGL_LIBRARY_NAMEoption. The maximum OpenGL version loaded can be set with theConfiguration.OPENGL_MAXVERSIONoption. This can be useful to ensure that no functionality above a specific version is used during development.GLCapabilities creation
Instances of
GLCapabilitiescan be created with theGL.createCapabilities()method. An OpenGL context must be current in the current thread before it is called. Calling this method is expensive, so theGLCapabilitiesinstance 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
GLCapabilitiesinstance must be passed to theGL.setCapabilities(org.lwjgl.opengl.GLCapabilities)method. The user is also responsible for clearing the currentGLCapabilitiesinstance when the context is destroyed or made current in another thread.Note that the
GL.createCapabilities()method implicitly callsGL.setCapabilities(org.lwjgl.opengl.GLCapabilities)with the newly created instance.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static voidcreate()Loads the OpenGL native library, using the default library name.static voidcreate(org.lwjgl.system.FunctionProvider functionProvider)Initializes OpenGL with the specifiedFunctionProvider.static voidcreate(java.lang.String libName)Loads the OpenGL native library, using the specified library name.static GLCapabilitiescreateCapabilities()Creates 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 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 WGLCapabilitiescreateCapabilitiesWGL()Creates aWGLCapabilitiesinstance for the context that is current in the current thread.static voiddestroy()Unloads the OpenGL native library.static GLCapabilitiesgetCapabilities()Returns theGLCapabilitiesof the OpenGL context that is current in the current thread.static GLXCapabilitiesgetCapabilitiesGLX()Returns the GLX capabilities.static WGLCapabilitiesgetCapabilitiesWGL()Returns the WGL capabilities.static org.lwjgl.system.FunctionProvidergetFunctionProvider()Returns theFunctionProviderfor the OpenGL native library.static voidsetCapabilities(GLCapabilities caps)Sets theGLCapabilitiesof the OpenGL context that is current in the current thread.
-
-
-
Method Detail
-
create
public static void create()
Loads the OpenGL native library, using the default library name.
-
create
public static void create(java.lang.String libName)
Loads the OpenGL native library, using the specified library name.- Parameters:
libName- the native library name
-
create
public static void create(org.lwjgl.system.FunctionProvider functionProvider)
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
public static org.lwjgl.system.FunctionProvider getFunctionProvider()
Returns theFunctionProviderfor the OpenGL native library.
-
setCapabilities
public static void setCapabilities(GLCapabilities caps)
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
public static GLCapabilities getCapabilities()
Returns theGLCapabilitiesof the OpenGL context that is current in the current thread.- Throws:
java.lang.IllegalStateException- ifGL.setCapabilities(org.lwjgl.opengl.GLCapabilities)has never been called in the current thread or was last called with anullvalue
-
getCapabilitiesWGL
public static WGLCapabilities getCapabilitiesWGL()
Returns the WGL capabilities.This method may only be used on Windows.
-
getCapabilitiesGLX
public static GLXCapabilities getCapabilitiesGLX()
Returns the GLX capabilities.This method may only be used on Linux.
-
createCapabilities
public static GLCapabilities 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
GL.setCapabilities(GLCapabilities)with the new instance before returning.- Returns:
- the GLCapabilities instance
-
createCapabilities
public static GLCapabilities createCapabilities(boolean forwardCompatible)
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
GL.setCapabilities(GLCapabilities)with the new instance before returning.- Parameters:
forwardCompatible- if true, LWJGL will create forward compatible capabilities- Returns:
- the GLCapabilities instance
-
createCapabilitiesWGL
public static WGLCapabilities createCapabilitiesWGL()
Creates aWGLCapabilitiesinstance for the context that is current in the current thread.This method may only be used on Windows.
-
createCapabilitiesGLX
public static GLXCapabilities createCapabilitiesGLX(long display)
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
public static GLXCapabilities createCapabilitiesGLX(long display, int screen)
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
-
-