Basics

Guides

API Reference

Menu

Basics

Guides

API Reference

class: GLAreaMeta

[784:14] static extends: object

Generated metadata helpers for GLArea class surfaces.

Methods

  • properties ()

    Returns property metadata for GLArea.

    • @r A list.
  • signals ()

    Returns signal metadata for GLArea.

    • @r A list.

class: GLAreaResizeCallback

[714:7] extends: object

Generated low-level callback wrapper for GIR callback resize.

Members

  • callbackObj
  • userFn
  • userData
  • hasUserData

Methods

  • GLAreaResizeCallback (callback Fn, UserData = null)

    Creates one native callback wrapper. The wrapper owns a trampoline that converts native pointers into generated wrapper objects before invoking Fn.

    • @p Fn is the Aussom callback implementation.
    • @p UserData is retained and passed through to Fn on each invocation when provided.
  • trampoline (nativeSelf, width, height, nativeUserData)

    Internal trampoline. Converts native pointer arguments into generated wrapper instances, then invokes the user's callback.

  • callback ()

    Returns the wrapped NativeCallback.

  • handle ()

    Returns the callback as a NativeHandle.

  • close ()

    Closes the underlying NativeCallback.

  • isClosed ()

    Returns true when the callback has been closed.

class: GLAreaCreatecontextCallback

[573:7] extends: object

Generated low-level callback wrapper for GIR callback create-context.

Members

  • callbackObj
  • userFn
  • userData
  • hasUserData

Methods

  • GLAreaCreatecontextCallback (callback Fn, UserData = null)

    Creates one native callback wrapper. The wrapper owns a trampoline that converts native pointers into generated wrapper objects before invoking Fn.

    • @p Fn is the Aussom callback implementation.
    • @p UserData is retained and passed through to Fn on each invocation when provided.
  • trampoline (nativeSelf, nativeUserData)

    Internal trampoline. Converts native pointer arguments into generated wrapper instances, then invokes the user's callback.

  • callback ()

    Returns the wrapped NativeCallback.

  • handle ()

    Returns the callback as a NativeHandle.

  • close ()

    Closes the underlying NativeCallback.

  • isClosed ()

    Returns true when the callback has been closed.

class: GLArea

[60:7] extends: object

Allows drawing with OpenGL. An example GtkGLArea GtkGLArea sets up its own [class@Gdk.GLContext], and creates a custom GL framebuffer that the widget will do GL rendering onto. It also ensures that this framebuffer is the default GL rendering target when rendering. The completed rendering is integrated into the larger GTK scene graph as a texture. In order to draw, you have to connect to the [signal@Gtk.GLArea::render] signal, or subclass GtkGLArea and override the GtkGLAreaClass.render virtual function. The GtkGLArea widget ensures that the GdkGLContext is associated with the widget's drawing area, and it is kept updated when the size and position of the drawing area changes. ## Drawing with GtkGLArea The simplest way to draw using OpenGL commands in a GtkGLArea is to create a widget instance and connect to the [signal@Gtk.GLArea::render] signal: The render() function will be called when the GtkGLArea is ready for you to draw its content: The initial contents of the framebuffer are transparent. c static gboolean render (GtkGLArea *area, GdkGLContext *context) { // inside this function it's safe to use GL; the given // GdkGLContext has been made current to the drawable // surface used by the `GtkGLArea` and the viewport has // already been set to be the size of the allocation // we can start by clearing the buffer glClearColor (0, 0, 0, 0); glClear (GL_COLOR_BUFFER_BIT); // record the active framebuffer ID, so we can return to it // with `glBindFramebuffer (GL_FRAMEBUFFER, screen_fb)` should // we, for instance, intend on utilizing the results of an // intermediate render texture pass GLuint screen_fb = 0; glGetIntegerv (GL_FRAMEBUFFER_BINDING, &screen_fb); // draw your object // draw_an_object (); // we completed our drawing; the draw commands will be // flushed at the end of the signal emission chain, and // the buffers will be drawn on the window return TRUE; } void setup_glarea (void) { // create a GtkGLArea instance GtkWidget *gl_area = gtk_gl_area_new (); // connect to the "render" signal g_signal_connect (gl_area, "render", G_CALLBACK (render), NULL); } If you need to initialize OpenGL state, e.g. buffer objects or shaders, you should use the [signal@Gtk.Widget::realize] signal; you can use the [signal@Gtk.Widget::unrealize] signal to clean up. Since the GdkGLContext creation and initialization may fail, you will need to check for errors, using [method@Gtk.GLArea.get_error]. An example of how to safely initialize the GL state is: c static void on_realize (GtkGLArea *area) { // We need to make the context current if we want to // call GL API gtk_gl_area_make_current (area); // If there were errors during the initialization or // when trying to make the context current, this // function will return a GError for you to catch if (gtk_gl_area_get_error (area) != NULL) return; // You can also use gtk_gl_area_set_error() in order // to show eventual initialization errors on the // GtkGLArea widget itself GError *internal_error = NULL; init_buffer_objects (&error); if (error != NULL) { gtk_gl_area_set_error (area, error); g_error_free (error); return; } init_shaders (&error); if (error != NULL) { gtk_gl_area_set_error (area, error); g_error_free (error); return; } } If you need to change the options for creating the GdkGLContext you should use the [signal@Gtk.GLArea::create-context] signal.

Members

  • handleObj
  • lib
  • retainedCallbacks
  • signalHandlerNames
  • signalSetterHandlers

Methods

  • GLArea ()

    Creates a new GtkGLArea widget.

  • toNativeHandle (Source)

    Normalizes a constructor argument into a raw pointer carrier. Accepts a raw NativeHandle, a raw NativeBuffer returned from fn.call(...), another generated wrapper exposing handle(), or null. Returns null when the argument carries no pointer.

    • @p Source is the raw handle, raw buffer, wrapper, or null.
    • @r A raw pointer carrier or null when no pointer is present.
  • getLib ()

    Returns the opened native library for this generated wrapper.

    • @r The opened native library.
  • handle ()

    Returns the wrapped NativeHandle.

    • @r The wrapped NativeHandle.
  • isNull ()

    Returns true when the wrapped handle is null.

    • @r A bool.
  • describe ()

    Returns a small string for debugging generated wrappers.

    • @r A string.
  • asWidget ()

    Wraps this handle as Widget.

    • @r A Widget object.
  • asAccessible ()

    Wraps this handle as Accessible.

    • @r A Accessible object.
  • asBuildable ()

    Wraps this handle as Buildable.

    • @r A Buildable object.
  • asConstraintTarget ()

    Wraps this handle as ConstraintTarget.

    • @r A ConstraintTarget object.
  • connectSignal (string Name, CallbackObj)

    Connects one generated callback wrapper to a named signal.

    • @p Name is the signal name.
    • @p CallbackObj is the generated callback wrapper to connect.
    • @r The connected handler id.
  • disconnectSignalHandler (int HandlerId)

    Disconnects one retained signal handler id.

    • @p HandlerId is the signal handler id to disconnect.
    • @r None.
  • setOnCreatecontext (callback Fn, UserData = null)

    Emitted when the widget is being realized. This allows you to override how the GL context is created. This is useful when you want to reuse an existing GL context, or if you want to try creating different kinds of GL options. If context creation fails then the signal handler can use [method@Gtk.GLArea.set_error] to register a more detailed error of how the construction failed.

    • @p Fn is the Aussom callback.
    • @p Fn is called with (GLArea Self).
    • @p UserData is retained and passed through to the generated callback wrapper when provided.
    • @r The connected handler id.
  • setOnRender (callback Fn, UserData = null)

    Emitted every time the contents of the GtkGLArea should be redrawn. The

    • @context is bound to the @area prior to emitting this function, and the buffers are painted to the window once the emission terminates.
    • @p Fn is the Aussom callback.
    • @p Fn is called with (GLArea Self, GLContext Context).
    • @p UserData is retained and passed through to the generated callback wrapper when provided.
    • @r The connected handler id.
  • setOnResize (callback Fn, UserData = null)

    Emitted once when the widget is realized, and then each time the widget is changed while realized. This is useful in order to keep GL state up to date with the widget size, like for instance camera properties which may depend on the width/height ratio. The GL context for the area is guaranteed to be current when this signal is emitted. The default handler sets up the GL viewport.

    • @p Fn is the Aussom callback.
    • @p Fn is called with (GLArea Self, int Width, int Height).
    • @p UserData is retained and passed through to the generated callback wrapper when provided.
    • @r The connected handler id.
  • getProperty (string Name)

    Reads one generated property by name.

  • setProperty (string Name, Value)

    Writes one generated property by name.

  • setAllowedapis (string Value)

    The allowed APIs.

    • @p Value is the new property value.
    • @r None.
  • setAutorender (bool Value)

    If set to %TRUE the ::render signal will be emitted every time the widget draws. This is the default and is useful if drawing the widget is faster. If set to %FALSE the data from previous rendering is kept around and will be used for drawing the widget the next time, unless the window is resized. In order to force a rendering [method@Gtk.GLArea.queue_render] must be called. This mode is useful when the scene changes seldom, but takes a long time to redraw.

    • @p Value is the new property value.
    • @r None.
  • setHasdepthbuffer (bool Value)

    If set to %TRUE the widget will allocate and enable a depth buffer for the target framebuffer. Setting this property will enable GL's depth testing as a side effect. If you don't need depth testing, you should call glDisable(GL_DEPTH_TEST) in your GtkGLArea::render handler.

    • @p Value is the new property value.
    • @r None.
  • setHasstencilbuffer (bool Value)

    If set to %TRUE the widget will allocate and enable a stencil buffer for the target framebuffer.

    • @p Value is the new property value.
    • @r None.
  • setUsees (bool Value)

    If set to %TRUE the widget will try to create a GdkGLContext using OpenGL ES instead of OpenGL.

    • @p Value is the new property value.
    • @r None.
  • attach_buffers ()

    Binds buffers to the framebuffer. Ensures that the @area framebuffer object is made the current draw and read target, and that all the required buffers for the @area are created and bound to the framebuffer. This function is automatically called before emitting the [signal@Gtk.GLArea::render] signal, and doesn't normally need to be called by application code.

    • @r None.
  • get_allowed_apis ()

    Gets the allowed APIs. See [method@Gtk.GLArea.set_allowed_apis].

  • get_api ()

    Gets the API that is currently in use. If the GL area has not been realized yet, 0 is returned.

  • get_auto_render ()

    Returns whether the area is in auto render mode or not.

  • get_context ()

    Retrieves the GdkGLContext used by @area.

  • get_error ()

    Gets the current error set on the @area.

  • get_has_depth_buffer ()

    Returns whether the area has a depth buffer.

  • get_has_stencil_buffer ()

    Returns whether the area has a stencil buffer.

  • get_use_es ()

    Returns whether the GtkGLArea should use OpenGL ES. See [method@Gtk.GLArea.set_use_es].

  • make_current ()

    Ensures that the GdkGLContext used by @area is associated with the GtkGLArea. This function is automatically called before emitting the [signal@Gtk.GLArea::render] signal, and doesn't normally need to be called by application code.

    • @r None.
  • queue_render ()

    Marks the currently rendered data (if any) as invalid, and queues a redraw of the widget. This ensures that the [signal@Gtk.GLArea::render] signal is emitted during the draw. This is only needed when [method@Gtk.GLArea.set_auto_render] has been called with a %FALSE value. The default behaviour is to emit [signal@Gtk.GLArea::render] on each draw.

    • @r None.
  • set_allowed_apis (string apis)

    Sets the allowed APIs to create a context with. You should check [property@Gtk.GLArea:api] before drawing with either API. By default, all APIs are allowed.

    • @p apis is the allowed APIs.
    • @r None.
  • set_auto_render (bool auto_render)

    Sets whether the GtkGLArea is in auto render mode. If @auto_render is %TRUE the [signal@Gtk.GLArea::render] signal will be emitted every time the widget draws. This is the default and is useful if drawing the widget is faster. If @auto_render is %FALSE the data from previous rendering is kept around and will be used for drawing the widget the next time, unless the window is resized. In order to force a rendering [method@Gtk.GLArea.queue_render] must be called. This mode is useful when the scene changes seldom, but takes a long time to redraw.

    • @p auto_render is a boolean.
    • @r None.
  • set_error (object error)

    Sets an error on the area which will be shown instead of the GL rendering. This is useful in the [signal@Gtk.GLArea::create-context] signal if GL context creation fails.

    • @p error is a new GError, or %NULL to unset the error.
    • @r None.
  • set_has_depth_buffer (bool has_depth_buffer)

    Sets whether the GtkGLArea should use a depth buffer. If

    • @has_depth_buffer is %TRUE the widget will allocate and enable a depth buffer for the target framebuffer. Otherwise there will be none.
    • @p has_depth_buffer is %TRUE to add a depth buffer.
    • @r None.
  • set_has_stencil_buffer (bool has_stencil_buffer)

    Sets whether the GtkGLArea should use a stencil buffer. If

    • @has_stencil_buffer is %TRUE the widget will allocate and enable a stencil buffer for the target framebuffer. Otherwise there will be none.
    • @p has_stencil_buffer is %TRUE to add a stencil buffer.
    • @r None.
  • set_required_version (int major, int minor)

    Sets the required version of OpenGL to be used when creating the context for the widget. This function must be called before the area has been realized.

    • @p major is the major version.
    • @p minor is the minor version.
    • @r None.
  • set_use_es (bool use_es)

    Sets whether the @area should create an OpenGL or an OpenGL ES context. You should check the capabilities of the GdkGLContext before drawing with either API.

    • @p use_es is whether to use OpenGL or OpenGL ES.
    • @r None.

class: GLAreaRenderCallback

[643:7] extends: object

Generated low-level callback wrapper for GIR callback render.

Members

  • callbackObj
  • userFn
  • userData
  • hasUserData

Methods

  • GLAreaRenderCallback (callback Fn, UserData = null)

    Creates one native callback wrapper. The wrapper owns a trampoline that converts native pointers into generated wrapper objects before invoking Fn.

    • @p Fn is the Aussom callback implementation.
    • @p UserData is retained and passed through to Fn on each invocation when provided.
  • trampoline (nativeSelf, context, nativeUserData)

    Internal trampoline. Converts native pointer arguments into generated wrapper instances, then invokes the user's callback.

  • callback ()

    Returns the wrapped NativeCallback.

  • handle ()

    Returns the callback as a NativeHandle.

  • close ()

    Closes the underlying NativeCallback.

  • isClosed ()

    Returns true when the callback has been closed.