<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Title" content="">
<meta name="Keywords" content="">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
span.msoIns
        {mso-style-type:export-only;
        mso-style-name:"";
        text-decoration:underline;
        color:teal;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style>
</head>
<body bgcolor="white" lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">HI David --<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks for the suggestions, which got me started on the right track.
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">What seems to work is this (somewhat simplified to eliminate some infrastructure):<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">// Create gtk widget and vtk window<o:p></o:p></p>
<p class="MsoNormal">GtkWidget *drawing_area = gtk_drawing_area_new();<o:p></o:p></p>
<p class="MsoNormal">vtkSmartPointer<vtkCocoaRenderWindow> render_window = vtkSmartPointer<vtkCocoaRenderWindow>::New();<o:p></o:p></p>
<p class="MsoNormal">// Connect to gtk signals.  <o:p></o:p></p>
<p class="MsoNormal">g_signal_connect(drawing_area, "realize", realize_callback, ..)<o:p></o:p></p>
<p class="MsoNormal">g_signal_connect(drawing_area, "configure_event", configure_callback, …)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">// in realize_callback<o:p></o:p></p>
<p class="MsoNormal">gtk_widget_realize(drawing_area);<o:p></o:p></p>
<p class="MsoNormal">render_window->SetRootWindow(gtk_widget_get_root_window(drawing_area));<o:p></o:p></p>
<p class="MsoNormal">GdkWindow gparent = gtk_widget_get_parent_window(drawing_area);<o:p></o:p></p>
<p class="MsoNormal">NSView *pid = gdk_quartz_window_get_nsview(gparent);<o:p></o:p></p>
<p class="MsoNormal">render_window->SetParentId((void*) pid);<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">// in configure_callback  <o:p></o:p></p>
<p class="MsoNormal">// event is a GdkEventConfigure* that's passed in as an argument<o:p></o:p></p>
<p class="MsoNormal">// Unlike David's  QWidget example, I do not use the superclass versions of SetSize and SetPosition<o:p></o:p></p>
<p class="MsoNormal">render_window->SetSize(event->width, event->height);<o:p></o:p></p>
<p class="MsoNormal">render_window->SetPosition(drawing_area->allocation.x, drawing_area->allocation.y);<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I also added an expose event callback which just called render_window->Render(), but it doesn't seem to be necessary.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">-- Steve<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:12.0pt;color:black">From: </span></b><span style="font-size:12.0pt;color:black">David Gobbi <david.gobbi@gmail.com><br>
<b>Date: </b>Tuesday, October 24, 2017 at 2:56 PM<br>
<b>To: </b>"Langer, Stephen A. (Fed)" <stephen.langer@nist.gov><br>
<b>Cc: </b>"vtkusers@vtk.org" <vtkusers@vtk.org><br>
<b>Subject: </b>Re: [vtkusers] vtk and gtk on macOS<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<p class="MsoNormal">Hi Steve,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Here is some code that I use to bind a VTK window to a QWidget.  My guess is that something similar should work with GTK.  I have been using this on OS X with vtkCocoaRenderWindow.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">void BindRenderWindow(vtkRenderWindow *window, QWidget *widget)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">{<o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal">  // Unmap the window if it is already mapped somewhere else.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">  if (window->GetMapped()) {<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">    window->Finalize();<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">  }<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal">  // Create the connection<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">  window->SetWindowId(reinterpret_cast<void *>(widget->winId()));<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">  // Note that we must call the superclass SetSize()/SetPosition()<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">  // (we just want to set the member variables, with no side-effects)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">  window->vtkRenderWindow::SetSize(widget->width(), widget->height());<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">  window->vtkRenderWindow::SetPosition(widget->x(), widget->y());<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">  // Prepare for rendering<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">  if (widget->isVisible()) {<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">    window->Start();<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">  }<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">  // Call SetSize() again, to synchronize the window to the widget<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">  window->SetSize(widget->width(), widget->height());<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">}<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Some further notes:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">1) I disable Qt's paint engine, so that Qt itself doesn't draw in the window.  GTK may be similar.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">2) You probably will not need GtkGLExt (for Qt, I didn't have to use QGLWidget).<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"> - David<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On Tue, Oct 24, 2017 at 12:12 PM, Langer, Stephen A. (Fed) <<a href="mailto:stephen.langer@nist.gov" target="_blank">stephen.langer@nist.gov</a>> wrote:<o:p></o:p></p>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">Hi --<br>
<br>
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?<br>
<br>
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:<br>
    vtkRenderWindow *render_win = vtkRenderWindow::New();<br>
    GtkWidget *drawing_area = gtk_drawing_area_new();<br>
    Display *disp = GDK_DISPLAY();<br>
    render_win->SetDisplayId(disp);<br>
followed eventually by<br>
     XID wid = GDK_WINDOW_XID(drawing_area->window);<br>
     render_win->SetWindowId(wid);<br>
after receiving the gtk "realize" signal on the drawing_area.<br>
<br>
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.<br>
<br>
GtkGLExt might be applicable, but it doesn't look like it's being maintained.<br>
<br>
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:<br>
  ERROR: In /Users/langer/UTIL/VTK/VTK-7.1.1/Rendering/OpenGL2/vtkTextureObject.cxx, line 440<br>
  vtkTextureObject (0x7f9eafdb1690): failed at glGenTextures 1 OpenGL errors detected<br>
    0 : (1280) Invalid enum<br>
<br>
Thanks,<br>
     Steve<o:p></o:p></p>
</blockquote>
</div>
</div>
</div>
</div>
</body>
</html>