Getting GtkD working with OpenGL

Mike Wey via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Oct 6 11:14:21 PDT 2016


On 10/06/2016 05:18 PM, Chalix wrote:
> On Thursday, 6 October 2016 at 13:35:01 UTC, Mike Parker wrote:
>> So, change DerelictGL3.load to DerelictGL.load, then add a call to
>> DerelictGL.reload after creating and activating the context.
>
> Thank you! That fixed the segmentation fault problem and the crash :)
>
> But I still struggle with the right Context...
>
> if I do something like this
>
>     DerelictGL.load();
>     area.makeCurrent();
>     DerelictGL.reload();
>
> I get an (runtime) error (on the terminal where I run my application):
>
> (LibraryTest:2984): Gtk-CRITICAL **: gtk_gl_area_make_current: assertion
> 'gtk_widget_get_realized (widget)' failed
> derelict.util.exception.DerelictException at gl3.d(85): DerelictGL3.reload
> failure: An OpenGL context is not currently active.
> [...]
>
>
> After all, I really don't know, what a GLContext is, what I need it for
> and how to use it. If somebody can explain it to me, I would be happy! I
> didn't find anything about it on the Internet, but I like to know, whats
> going on behind my code...
>
> I will keep on playing around with all the context functions, maybe I
> find something by accident that works xD
>

When you don't register an callback for the createContext signal 
(addOnCreateContext), gtk does the following internally:

```
context = area.getWindow().createGlContext();
```
to get an context that renders to the GLArea.

gdk.GLContext is an platform independent abstraction for the context you 
would normally use with openGL. like the one's returned by 
wglCreateContext or glxCreateContext.

makeCurrent() sets that context as the one that is rendered to.
realize() i think makes sure the context is initialized, but 
makeCurrent() also calls realize, so makeCurrent is probably the one you 
want to use.

-- 
Mike Wey


More information about the Digitalmars-d-learn mailing list