## GdkGLContext

GdkGLContext — OpenGL context

## Functions

GdkDisplay * | gdk_gl_context_get_display ()
GdkWindow * | gdk_gl_context_get_window ()
GdkGLContext * | gdk_gl_context_get_shared_context ()
void | gdk_gl_context_get_version ()
void | gdk_gl_context_set_required_version ()
void | gdk_gl_context_get_required_version ()
void | gdk_gl_context_set_debug_enabled ()
gboolean | gdk_gl_context_get_debug_enabled ()
void | gdk_gl_context_set_forward_compatible ()
gboolean | gdk_gl_context_get_forward_compatible ()
gboolean | gdk_gl_context_realize ()
void | gdk_gl_context_make_current ()
GdkGLContext * | gdk_gl_context_get_current ()
void | gdk_gl_context_clear_current ()

## Properties

GdkDisplay * | display | Read / Write / Construct Only
GdkGLContext * | shared-context | Read / Write / Construct Only
GdkWindow * | window | Read / Write / Construct Only

## Types and Values

| GdkGLContext
enum | GdkGLError

## Object Hierarchy

        GObject
        ╰── GdkGLContext

## Includes

    #include <gdk/gdk.h>

## Description

GdkGLContext is an object representing the platform-specific OpenGL drawing context.

GdkGLContexts are created for a GdkWindow using `gdk_window_create_gl_context()`, and the context will match the GdkVisual of the window.

A GdkGLContext is not tied to any particular normal framebuffer. For instance, it cannot draw to the GdkWindow 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_cairo_draw_from_gl()` 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, 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 GdkWindow, which you typically get during the realize call of a widget.

A GdkGLContext is not realized until either `gdk_gl_context_make_current()`, or until it is realized using `gdk_gl_context_realize()`. 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 `gdk_window_create_gl_context()` by calling `gdk_gl_context_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 `gdk_gl_context_get_current()`; you can also unset any GdkGLContext that is currently set by calling `gdk_gl_context_clear_current()`.

## Functions

### gdk_gl_context_get_display ()

    GdkDisplay *
    gdk_gl_context_get_display (GdkGLContext *context);

Retrieves the GdkDisplay the `context` is created for

#### Parameters

context | a GdkGLContext |

#### Returns

a GdkDisplay or `NULL`.

[transfer none]

Since: 3.16

### gdk_gl_context_get_window ()

    GdkWindow *
    gdk_gl_context_get_window (GdkGLContext *context);

Retrieves the GdkWindow used by the `context` .

#### Parameters

context | a GdkGLContext |

#### Returns

a GdkWindow or `NULL`.

[transfer none]

Since: 3.16

### gdk_gl_context_get_shared_context ()

    GdkGLContext *
    gdk_gl_context_get_shared_context (GdkGLContext *context);

Retrieves the GdkGLContext that this `context` share data with.

#### Parameters

context | a GdkGLContext |

#### Returns

a GdkGLContext or `NULL`.

[transfer none]

Since: 3.16

### gdk_gl_context_get_version ()

    void
    gdk_gl_context_get_version (GdkGLContext *context,
                                int *major,
                                int *minor);

Retrieves the OpenGL version of the `context` .

The `context` must be realized prior to calling this function.

#### Parameters

context | a GdkGLContext |
major | return location for the major version. | [out]
minor | return location for the minor version. | [out]

Since: 3.16

### gdk_gl_context_set_required_version ()

    void
    gdk_gl_context_set_required_version (GdkGLContext *context,
                                         int major,
                                         int minor);

Sets the major and minor version of OpenGL to request.

Setting `major` and `minor` to zero will use the default values.

The GdkGLContext must not be realized or made current prior to calling this function.

#### Parameters

context | a GdkGLContext |
major | the major version to request |
minor | the minor version to request |

Since: 3.16

### gdk_gl_context_get_required_version ()

    void
    gdk_gl_context_get_required_version (GdkGLContext *context,
                                         int *major,
                                         int *minor);

Retrieves the major and minor version requested by calling `gdk_gl_context_set_required_version()`.

#### Parameters

context | a GdkGLContext |
major | return location for the major version to request. | [out][nullable]
minor | return location for the minor version to request. | [out][nullable]

Since: 3.16

### gdk_gl_context_set_debug_enabled ()

    void
    gdk_gl_context_set_debug_enabled (GdkGLContext *context,
                                      gboolean enabled);

Sets whether the GdkGLContext should perform extra validations and run time checking. This is useful during development, but has additional overhead.

The GdkGLContext must not be realized or made current prior to calling this function.

#### Parameters

context | a GdkGLContext |
enabled | whether to enable debugging in the context |

Since: 3.16

### gdk_gl_context_get_debug_enabled ()

    gboolean
    gdk_gl_context_get_debug_enabled (GdkGLContext *context);

Retrieves the value set using `gdk_gl_context_set_debug_enabled()`.

#### Parameters

context | a GdkGLContext |

#### Returns

`TRUE` if debugging is enabled

Since: 3.16

### gdk_gl_context_set_forward_compatible ()

    void
    gdk_gl_context_set_forward_compatible (GdkGLContext *context,
                                           gboolean compatible);

Sets whether the GdkGLContext should be forward compatible.

Forward compatibile contexts must not support OpenGL functionality that has been marked as deprecated in the requested version; non-forward compatible contexts, on the other hand, must support both deprecated and non deprecated functionality.

The GdkGLContext must not be realized or made current prior to calling this function.

#### Parameters

context | a GdkGLContext |
compatible | whether the context should be forward compatible |

Since: 3.16

### gdk_gl_context_get_forward_compatible ()

    gboolean
    gdk_gl_context_get_forward_compatible (GdkGLContext *context);

Retrieves the value set using `gdk_gl_context_set_forward_compatible()`.

#### Parameters

context | a GdkGLContext |

#### Returns

`TRUE` if the context should be forward compatible

Since: 3.16

### gdk_gl_context_realize ()

    gboolean
    gdk_gl_context_realize (GdkGLContext *context,
                            GError **error);

Realizes the given GdkGLContext.

It is safe to call this function on a realized GdkGLContext.

#### Parameters

context | a GdkGLContext |
error | return location for a GError |

#### Returns

`TRUE` if the context is realized

Since: 3.16

### gdk_gl_context_make_current ()

    void
    gdk_gl_context_make_current (GdkGLContext *context);

Makes the `context` the current one.

#### Parameters

context | a GdkGLContext |

Since: 3.16

### gdk_gl_context_get_current ()

    GdkGLContext *
    gdk_gl_context_get_current (void);

Retrieves the current GdkGLContext.

#### Returns

the current GdkGLContext, or `NULL`.

[transfer none]

Since: 3.16

### gdk_gl_context_clear_current ()

    void
    gdk_gl_context_clear_current (void);

Clears the current GdkGLContext.

Any OpenGL call after this function returns will be ignored until `gdk_gl_context_make_current()` is called.

Since: 3.16

## Types and Values

### GdkGLContext

    typedef struct _GdkGLContext GdkGLContext;

### enum GdkGLError

Error enumeration for GdkGLContext.

#### Members

GDK_GL_ERROR_NOT_AVAILABLE | OpenGL support is not available |
GDK_GL_ERROR_UNSUPPORTED_FORMAT | The requested visual format is not supported |
GDK_GL_ERROR_UNSUPPORTED_PROFILE | The requested profile is not supported |

Since: 3.16

## Property Details

### The `“display”` property

      “display”                  GdkDisplay *

The GdkDisplay used to create the GdkGLContext.

Flags: Read / Write / Construct Only

Since: 3.16

### The `“shared-context”` property

      “shared-context”           GdkGLContext *

The GdkGLContext that this context is sharing data with, or NULL

Flags: Read / Write / Construct Only

Since: 3.16

### The `“window”` property

      “window”                   GdkWindow *

The GdkWindow the gl context is bound to.

Flags: Read / Write / Construct Only

Since: 3.16