vtk in gtk

Langer, Stephen A. (Fed) stephen.langer at nist.gov
Mon Oct 16 21:34:59 UTC 2017


Hi --

I'm using vtk in a program that has a gtk2 GUI.   To embed the vtk window in gtk, on Linux I can do this:
    vtkRenderWindow *render_win = vtkRenderWindow::New();
    GtkWidget *drawing_area = gtk_drawing_area_new();
    Display *disp = GDK_DISPLAY();
    render_win->SetDisplayId(disp);
followed eventually by 
     XID wid = GDK_WINDOW_XID(drawing_area->window);
     render_win->SetWindowId(wid);
after receiving the gtk "realize" signal on the drawing_area.

This seems to work, on Linux.   However when using the vtk from macports on macOS,  vtkRenderWindow::New creates a vtkCocoaRenderWindow, which doesn't implement SetDisplayId.  I rebuilt vtk with VTK_USE_X instead of VTK_USE_COCOA, but the version of OpenGL in /System/Library/Frameworks/OpenGL.framework doesn't seem to support X.  So I changed the OPENGL_* values in the vtk configuration to point to /opt/local/* and installed macports' mesa package.  Now the program compiles and links, but when the window is created it warns
       VTK is designed to work with OpenGL version 3.2 but it appears it has been given a context that does not support 3.2. VTK will run in a compatibility mode designed to work with earlier versions of OpenGL but some features may not work.

Indeed, on the first attempt to draw in the window, I'm told
  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

So,  what's the right way to link to a modern X11 version of OpenGL?  Mesa says it's version 17.1.6, which is recent (assuming that the macports and mesa version numbers agree).

Would it be easier if I stopped trying to use X11 on the Mac and switched to the Quartz variant of gtk2 and the Cocoa version of vtk?   Would upgrading to gtk3 help?  I'm really hoping not to have to do that right now.

Many thanks for any suggestions.

 -- Steve



More information about the macports-users mailing list