GLArea GTK3-GTK4 differences

Hi,

I’m new to GTK & OpenCASCADE, but I’d say I’m a fairly competent programmer, although I haven’t done any C/C++ development in more than 10 years.

I’m trying to integrate OpenCASCADE with GTK4 usign gtkmm-4.0 bindings. I found this example demonstrating how to do it in GTK3: github.com/gkv311/occt-samples-gtk and I hit a wall trying to figure out by myself.

There are other people not understanding some of what’s happening either:

In the OpenCASCADE + GTK3 example there is some initialization done in the realize callback that fails in GTK4.

I started doing some tests, but I don’t understand the behavior.

  • https://github.com/razcore-rad/occt-gtk/tree/official-gtk in this branch I tested Gtk::GLArea.get_width() and Gtk::GLArea.get_height()using the official GLArea example from gtkmm, because like the person from How can a GtkGlArea’ size be 0 x 0 […], I don’t understand why size = 0 x 0.

  • https://github.com/razcore-rad/occt-gtk/tree/other In this branch I adapted the stackoverflow example for GTK3 & GTK4, plus made some bare-bones tests for checking out the behaviors between the two versions.

    What I can see from the stackoverflow_v4 example is that glewInit() gives an error in on_my_realize() function, but even with the error the program still runs correctly - it makes the area blue.

    The difference with stackoverflow_v3is that glewInit()doesn’t throw an error, but commenting it out also doesn’t throw any errors and the program behaves correctly - it makes the area blue.

    Although it seems that GTK3 re-renders constantly while GTK4 only on resize or some event that triggers the re-render.

The reason I’m concerned about initializing the OpenGL context is because I have no idea what are the implications with OpenCASCADE if we don’t do it (using the OpenCASCADE API).

Please help us clarify what’s happening here, thanks!


As a side note (I haven’t tried this), but I imagine a solution for the occt-samples-gtk demo is to move the code from the realize callback to the render callback, but then I’m not sure what is the purpose of the realize callback if we can’t use the OpenGL surface to set stuff like in this example, scaling for HDPI screens and such.

P.S.
Doesn’t allow me to put more than 3 links.

I made some more tests with the stackoverflow sample code and seems that I ran into this bug: GtkGLArea doesn't work with Nvidia + GTK4 + X11 (#4950) · Issues · GNOME / gtk · GitLab.

I’m also on NVidia and can confirm that:

  • GDK_DEBUG=gl-egl fails in the sense that glewInit() gives an error.
  • GDK_DEBUG=gl-glx works in the sense that glewInit() doesn’t give an error.

Can’t test gl-gles with this code, but I assume it works.

This is unrelated to the realize callback size issue though.

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