OCCT + GTK4 not working

I tried to replicate this sample: https://github.com/gkv311/occt-samples-gtk/

While the original (which used GTK+-3.0) didn't start due to an old version of GTK+-3.0 being installed, my own implementation (using GTK4) did. However, I can't see anything on the blank GtkGlArea window, and I get:

TKOpenGl | Type: Other | ID: 0 | Severity: Medium | Message: OpenGl_Window::CreateWindow: window Visual is incomplete: no depth buffer, no stencil buffer

... despite having checked that gtk_gl_area_set_has_depth_buffer() and gtk_gl_area_set_has_stencil_buffer() are called. This is my code:


static void viewer_realize_callback(GtkWidget *self, gpointer user_data) { gtk_gl_area_make_current(GTK_GL_AREA(self)); int width = gtk_widget_get_width(self); int height = gtk_widget_get_height(self); int scale_factor = gtk_widget_get_scale_factor(self); gtk_gl_area_set_has_depth_buffer(GTK_GL_AREA(self), 1); gtk_gl_area_set_has_stencil_buffer(GTK_GL_AREA(self), 1); gtk_gl_area_attach_buffers(GTK_GL_AREA(self)); //gtk_gl_area_set_auto_render(GTK_GL_AREA(self), 0); EGLContext egl_context = eglGetCurrentContext(); if(egl_context != EGL_NO_CONTEXT) { EGLContext egl_display = eglGetCurrentDisplay(); EGLContext egl_surface = eglGetCurrentSurface(EGL_DRAW); EGLint egl_config_id = 0; EGLint num_configs = 0; eglQuerySurface(egl_display, egl_surface, EGL_CONFIG_ID, &egl_config_id); const EGLint config_attributes[] = {EGL_CONFIG_ID, egl_config_id, EGL_NONE}; void* egl_config = NULL; eglChooseConfig(egl_display, config_attributes, &egl_config, 1, &num_configs); run_at_viewer_realize( width, height, scale_factor, (void *) egl_context, (void *) egl_display, (void *) egl_config ); } else { GdkGLContext* gdk_gl_context = gdk_gl_context_get_current(); GdkDisplay* display = gdk_gl_context_get_display(gdk_gl_context); GdkSurface* surface = gdk_gl_context_get_surface(gdk_gl_context); Display *xdisplay = gdk_x11_display_get_xdisplay(display); Window gl_window = gdk_x11_surface_get_xid(surface); run_at_viewer_realize( width, height, scale_factor, (void *) NULL, (void *) xdisplay, (void *) gl_window ); } }

void backend_init_graphics(void) { display_connection = new Aspect_DisplayConnection(); viewer_driver = new OpenGl_GraphicDriver(display_connection, false); viewer_driver->ChangeOptions().buffersNoSwap = true; viewer_driver->ChangeOptions().buffersOpaqueAlpha = true; viewer_driver->ChangeOptions().useSystemBuffer = false; viewer = new V3d_Viewer(viewer_driver); viewer->SetDefaultBackgroundColor(Quantity_Color(Quantity_NOC_WHEAT)); viewer->SetDefaultLights(); viewer->SetLightOn(); viewer->ActivateGrid(Aspect_GT_Rectangular, Aspect_GDM_Lines); ais_context = new AIS_InteractiveContext(viewer); ais_controller = new AIS_ViewController(); view = viewer->CreateView(); view->SetImmediateUpdate(false); } void backend_realize_graphics( int width, int height, int scale_factor, void *context, void *display, void *config ) { Graphic3d_Vec2i logical_size(width, height); Graphic3d_Vec2i view_size = logical_size * scale_factor; opencascade::handle<OpenGl_Context> gl_context = new OpenGl_Context(); opencascade::handle<OcctGtkWindow> custom_window = dynamic_cast<OcctGtkWindow *>(view.get()); if(context != nullptr) { if(custom_window.get() == nullptr) { custom_window = new OcctGtkWindow(); } opencascade::handle<OpenGl_GraphicDriver> gl_driver = dynamic_cast<OpenGl_GraphicDriver *>( ais_context->CurrentViewer()->Driver().get() ) ; gl_driver->InitEglContext(display, context, config); custom_window->SetSize(view_size.x(), view_size.y()); custom_window->SetDevicePixelRatio(scale_factor); view->SetWindow(custom_window, gl_context->RenderingContext()); } else { opencascade::handle<OpenGl_GraphicDriver> gl_driver = dynamic_cast<OpenGl_GraphicDriver *>( ais_context->CurrentViewer()->Driver().get() ) ; //gl_driver.get()->GetDisplayConnection().get()->Init((Aspect_XDisplay *) display); //custom_window->SetNativeHandle((Aspect_Drawable) config); opencascade::handle<Xw_Window> xw_window = new Xw_Window(display_connection, (Aspect_Drawable) config); view->SetWindow(xw_window, gl_context->RenderingContext()); } // initPixelScaleRatio(); view->ChangeRenderingParams().Resolution = (unsigned int )(96.0 * scale_factor + 0.5); ais_context->SetPixelTolerance(int(scale_factor * 6.0)); /*TopoDS_Solid *undef_solid = new TopoDS_Solid(); opencascade::handle<AIS_Shape> interactive_shape = opencascade::handle<AIS_Shape>(new AIS_Shape(*undef_solid)); ais_context->Display(interactive_shape, 0);*/ }

Any ideas on what could be going wrong?

Kirill Gavrilov's picture

TKOpenGl | Type: Other | ID: 0 | Severity: Medium | Message:
OpenGl_Window::CreateWindow: window Visual is incomplete: no depth buffer, no stencil buffer

... despite having checked that gtk_gl_area_set_has_depth_buffer() and gtk_gl_area_set_has_stencil_buffer() are called. This is my code:

This is a warning message not an error. It usually doesn't lead to rendering issues.

Please use "Insert Code Snippet" (HTML editor) or ``` Markdown syntax while pasting code snippets - they are difficult to read.

aerkiaga's picture

Sorry, I wasn't aware I could use Markdown. The fact is, it doesn't work, and I'm not entirely sure why...

Kirill Gavrilov's picture

libgtk-4-dev isn’t available in Ubuntu 20.04 as far as I know. How did you installed it?

aerkiaga's picture

From source. Most of its dependencies are already there, so just a matter of compiling and installing. Same for OCCT (bc no debug symbols apparently).

Kirill Gavrilov's picture

Have you been able to build / run any GLArea samples using GTK4?

aerkiaga's picture

Haven't tried... Where can I get them? Are they bundled with the GTK4 sources?

aerkiaga's picture

Confirmed. All of the GTK4 demos build and run perfectly. Is there any way to build your code to run with gtkmm4? CMake only seems to accept gtkmm3... That way I'd be able to test! (well, it doesn't work with GTK+-3.0, because of the implementation bugs you mention, I assume).

Kirill Gavrilov's picture

Is there any way to build your code to run with gtkmm4? CMake only seems to accept gtkmm3...

You need to change gtkmm version in CMakeLists.txt and update sample based on changes in GTK API. Don't know if they have any dedicated upgrade guide describing these changes.

find_package (PkgConfig REQUIRED)
pkg_check_modules (GTKMM REQUIRED gtkmm-3.0)
aerkiaga's picture

Unfortunately I can't manage to build it on my system :(

I'm getting some interesting messages though, it looks like a GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT is being produced somewhere... Probably unrelated, but anyway.

aerkiaga's picture

This may be an old thread, but while looking at this I found a possible bug (as in, a concrete piece of code that appears to be wrong) in OpenGl_TextureFormat.hxx. I'll try a fix and see if this GTK4 issue gets fixed as well.

Basically, it's an instance where pixel formats like GL_RGBA are getting mixed up with internal formats like GL_RGBA8, which are constants defined with different numerical values.

Edit: OpenGl_TextureFormat.cxx has another instance of this, but I believe that one isn't the cause.