[vtkusers] vtk and gtk on macOS

Langer, Stephen A. (Fed) stephen.langer at nist.gov
Tue Oct 24 14:12:48 EDT 2017

Hi --

Is there a simple way to get vtk to work inside a gtk+2 program on macOS?   If there isn't a simple way, is there a difficult one?

I'm trying to get a program that uses gtk+2 and vtk to work with a modern version of vtk -- I'm upgrading from 5.10.1 to 7.1.1 or 8.0.1.    On Linux, the following code creates a vtk render window and a gtk widget containing it:
    vtkRenderWindow *render_win = vtkRenderWindow::New();
    GtkWidget *drawing_area = gtk_drawing_area_new();
    Display *disp = GDK_DISPLAY();
followed eventually by
     XID wid = GDK_WINDOW_XID(drawing_area->window);
after receiving the gtk "realize" signal on the drawing_area.

On macOS, I'd like to use the Cocoa version of gtk+2 and vtkCocoaRenderWindow, but I can't figure out how to embed the render window into a gtk widget.    All the examples I've found on-line aren't really applicable. 

GtkGLExt might be applicable, but it doesn't look like it's being maintained.

An alternative would be to use X11, but native Mac OpenGL doesn't understand X11, so I tried installing mesa from macports , rebuilding vtk with VTK_USE_X instead of VTK_USE_COCOA, and linking to /opt/local/lib instead of /System/Library/Frameworks/OpenGL.framework.  Then I can use the same code as on Linux, but vtk complains about the context not supporting OpenGL 3.2, and then crashes:
  ERROR: In /Users/langer/UTIL/VTK/VTK-7.1.1/Rendering/OpenGL2/vtkTextureObject.cxx, line 440
  vtkTextureObject (0x7f9eafdb1690): failed at glGenTextures 1 OpenGL errors detected
    0 : (1280) Invalid enum


More information about the vtkusers mailing list