GtkGLArea: How to create GL resources outside of signal callback functions?

,

Hello.

When going through GtkGLArea examples, I noticed that all of them use the “realize” signal callback function for resource creation (vertex buffers, etc.).
However, I am programming a level editor and nothing about the level contents are known during the call to “realize”, so I cannot create any GL resources here. It would be practical to create such resources outside of that function, more specifically when the user open a level file.

So, is it possible to create GL resources outside of the GtkGLArea signal callbacks? If so, how?

I tried calling GL functions outside of the signal callback functions, but it simply does not work. Looks like it is colliding with a different internal-to-GTK4 GL context.

You must call gtk_gl_area_make_current first to use the context from that area outside the render signal.

If you’re loading a lot of data and find that it stalls the main thread, there are some other ways to create GL resources from other threads using context sharing but I don’t have a good example of this at the moment.

It is working properly now, thank you!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.