Class GL
- java.lang.Object
-
- org.lwjgl.opengl.GL
-
public final class GL extends java.lang.Object
This 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
GLCapabilities
classes. AGLCapabilities
instance 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
GLCapabilities
instances, 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 theGL.create()
andGL.destroy()
functions. The name of the library loaded can be overridden with theConfiguration.OPENGL_LIBRARY_NAME
option. The maximum OpenGL version loaded can be set with theConfiguration.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 theGL.createCapabilities()
method. An OpenGL context must be current in the current thread before it is called. Calling this method is expensive, so theGLCapabilities
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 theGL.setCapabilities(org.lwjgl.opengl.GLCapabilities)
method. The user is also responsible for clearing the currentGLCapabilities
instance 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 void
create()
Loads the OpenGL native library, using the default library name.static void
create(org.lwjgl.system.FunctionProvider functionProvider)
Initializes OpenGL with the specifiedFunctionProvider
.static void
create(java.lang.String libName)
Loads the OpenGL native library, using the specified library name.static GLCapabilities
createCapabilities()
Creates a newGLCapabilities
instance for the OpenGL context that is current in the current thread.static GLCapabilities
createCapabilities(boolean forwardCompatible)
Creates a newGLCapabilities
instance for the OpenGL context that is current in the current thread.static GLXCapabilities
createCapabilitiesGLX(long display)
Creates aGLXCapabilities
instance for the default screen of the specified X connection.static GLXCapabilities
createCapabilitiesGLX(long display, int screen)
Creates aGLXCapabilities
instance for the specified screen of the specified X connection.static WGLCapabilities
createCapabilitiesWGL()
Creates aWGLCapabilities
instance for the context that is current in the current thread.static void
destroy()
Unloads the OpenGL native library.static GLCapabilities
getCapabilities()
Returns theGLCapabilities
of the OpenGL context that is current in the current thread.static GLXCapabilities
getCapabilitiesGLX()
Returns the GLX capabilities.static WGLCapabilities
getCapabilitiesWGL()
Returns the WGL capabilities.static org.lwjgl.system.FunctionProvider
getFunctionProvider()
Returns theFunctionProvider
for the OpenGL native library.static void
setCapabilities(GLCapabilities caps)
Sets theGLCapabilities
of 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 theFunctionProvider
for the OpenGL native library.
-
setCapabilities
public static void setCapabilities(GLCapabilities caps)
Sets theGLCapabilities
of the OpenGL context that is current in the current thread.This
GLCapabilities
instance will be used by any OpenGL call in the current thread, untilsetCapabilities
is called again with a different value.
-
getCapabilities
public static GLCapabilities getCapabilities()
Returns theGLCapabilities
of 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 anull
value
-
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 newGLCapabilities
instance 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 newGLCapabilities
instance 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
forwardCompatible
flag 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 aWGLCapabilities
instance 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 aGLXCapabilities
instance 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 aGLXCapabilities
instance 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
-
-