Package org.gnome.gdk

Class GLContext

java.lang.Object
All Implemented Interfaces:
Proxy
Direct Known Subclasses:
GLContext.GLContextImpl

@Generated("io.github.jwharm.JavaGI") public abstract class GLContext extends DrawContext
GdkGLContext is an object representing a platform-specific OpenGL draw context.

GdkGLContexts are created for a surface using Surface.createGlContext(), and the context will match the characteristics of the surface.

A GdkGLContext is not tied to any particular normal framebuffer. For instance, it cannot draw to the surface back buffer. The GDK repaint system is in full control of the painting to that. Instead, you can create render buffers or textures and use Gdk.cairoDrawFromGl(org.freedesktop.cairo.Context, org.gnome.gdk.Surface, int, int, int, int, int, int, int) in the draw function of your widget to draw them. Then GDK will handle the integration of your rendering with that of other widgets.

Support for GdkGLContext is platform-specific and context creation can fail, returning null context.

A GdkGLContext has to be made "current" in order to start using it, otherwise any OpenGL call will be ignored.

Creating a new OpenGL context
In order to create a new GdkGLContext instance you need a GdkSurface, which you typically get during the realize call of a widget.

A GdkGLContext is not realized until either makeCurrent() or realize() is called. It is possible to specify details of the GL context like the OpenGL version to be used, or whether the GL context should have extra state validation enabled after calling Surface.createGlContext() by calling realize(). If the realization fails you have the option to change the settings of the GdkGLContext and try again.

Using a GdkGLContext
You will need to make the GdkGLContext the current context before issuing OpenGL calls; the system sends OpenGL commands to whichever context is current. It is possible to have multiple contexts, so you always need to ensure that the one which you want to draw with is the current one before issuing commands:

gdk_gl_context_make_current (context);
 

You can now perform your drawing using OpenGL commands.

You can check which GdkGLContext is the current one by using getCurrent(); you can also unset any GdkGLContext that is currently set by calling clearCurrent().