<div dir="ltr" class="mw-geshi" style="text-align:left"><div class="cpp source-cpp"><pre class="de1"><span class="co2">#ifndef __APPLE_CC__</span>
<span class="co2">#include &lt;GL/glut.h&gt;</span>
<span class="co2">#else</span>
<span class="co2">#include &lt;glut.h&gt;</span>
<span class="co2">#endif</span>
<span class="co2">#include &quot;vtkConeSource.h&quot;</span>
<span class="co2">#include &quot;vtkPolyDataMapper.h&quot;</span>
<span class="co2">#include &quot;vtkRenderWindow.h&quot;</span>
<span class="co2">#include &quot;vtkCamera.h&quot;</span>
<span class="co2">#include &quot;vtkActor.h&quot;</span>
<span class="co2">#include &quot;vtkRenderer.h&quot;</span>
<span class="co2">#include &quot;vtkNew.h&quot;</span>
 
vtkNew<span class="sy1">&lt;</span>vtkRenderer<span class="sy1">&gt;</span> ren<span class="sy4">;</span>
vtkNew<span class="sy1">&lt;</span>vtkRenderWindow<span class="sy1">&gt;</span> renWin<span class="sy4">;</span>
 
<span class="kw4">void</span> Reshape<span class="br0">(</span> <span class="kw4">int</span> width, <span class="kw4">int</span> height <span class="br0">)</span>
<span class="br0">{</span>          
  renWin<span class="sy2">-</span><span class="sy1">&gt;</span>SetSize<span class="br0">(</span> width, height <span class="br0">)</span><span class="sy4">;</span>
<span class="br0">}</span>          
 
<span class="kw4">void</span> Draw<span class="br0">(</span><span class="br0">)</span>
<span class="br0">{</span>         
  renWin<span class="sy2">-</span><span class="sy1">&gt;</span>Render<span class="br0">(</span><span class="br0">)</span><span class="sy4">;</span>
  ren<span class="sy2">-</span><span class="sy1">&gt;</span>GetActiveCamera<span class="br0">(</span><span class="br0">)</span><span class="sy2">-</span><span class="sy1">&gt;</span>Azimuth<span class="br0">(</span> <span class="nu0">1</span> <span class="br0">)</span><span class="sy4">;</span>
  glutPostRedisplay<span class="br0">(</span><span class="br0">)</span><span class="sy4">;</span>
<span class="br0">}</span>
 
<span class="kw4">I write follow code,but renwin hast not member InitializeFromCurrentContext()?<br>How to solve this problem,and how to use opengl in vtk?<br>int</span> main<span class="br0">(</span> <span class="kw4">int</span> argc, <span class="kw4">char</span> <span class="sy2">**</span>argv <span class="br0">)</span>
<span class="br0">{</span>
  <span class="co1">// GLUT initialization</span>
  glutInit<span class="br0">(</span> <span class="sy3">&amp;</span>argc, argv <span class="br0">)</span><span class="sy4">;</span>
  glutInitDisplayMode<span class="br0">(</span> GLUT_RGBA <span class="sy3">|</span> GLUT_DOUBLE <span class="sy3">|</span> GLUT_DEPTH <span class="br0">)</span><span class="sy4">;</span>
  glutCreateWindow<span class="br0">(</span> <span class="st0">&quot;VTK-GLUT Example&quot;</span><span class="br0">)</span> <span class="sy4">;</span>
  glutReshapeFunc<span class="br0">(</span> Reshape <span class="br0">)</span><span class="sy4">;</span>
  glutDisplayFunc<span class="br0">(</span> Draw <span class="br0">)</span><span class="sy4">;</span>
 
  <span class="co1">// Creation of a simple VTK pipeline</span>
  vtkNew<span class="sy1">&lt;</span>vtkConeSource<span class="sy1">&gt;</span> cone<span class="sy4">;</span>
 
  vtkNew<span class="sy1">&lt;</span>vtkPolyDataMapper<span class="sy1">&gt;</span> coneMapper<span class="sy4">;</span>
  coneMapper<span class="sy2">-</span><span class="sy1">&gt;</span>SetInputConnection<span class="br0">(</span> cone<span class="sy2">-</span><span class="sy1">&gt;</span>GetOutputPort<span class="br0">(</span><span class="br0">)</span> <span class="br0">)</span><span class="sy4">;</span>
 
  vtkNew<span class="sy1">&lt;</span>vtkActor<span class="sy1">&gt;</span> coneActor<span class="sy4">;</span>
  coneActor<span class="sy2">-</span><span class="sy1">&gt;</span>SetMapper<span class="br0">(</span> coneMapper.<span class="me1">GetPointer</span><span class="br0">(</span><span class="br0">)</span> <span class="br0">)</span><span class="sy4">;</span>
 
  ren<span class="sy2">-</span><span class="sy1">&gt;</span>AddActor<span class="br0">(</span> coneActor.<span class="me1">GetPointer</span><span class="br0">(</span><span class="br0">)</span> <span class="br0">)</span><span class="sy4">;</span>
  renWin<span class="sy2">-</span><span class="sy1">&gt;</span>AddRenderer<span class="br0">(</span> ren.<span class="me1">GetPointer</span><span class="br0">(</span><span class="br0">)</span> <span class="br0">)</span><span class="sy4">;</span>
 
  <span class="co1">// Here is the trick: we ask the RenderWindow to join the current OpenGL context created by GLUT</span>
  renWin<span class="sy2">-</span><span class="sy1">&gt;</span>InitializeFromCurrentContext<span class="br0">(</span><span class="br0">)</span><span class="sy4">;</span>
 
  <span class="co1">// Let&#39;s start the main GLUT rendering loop</span>
  glutMainLoop<span class="br0">(</span><span class="br0">)</span><span class="sy4">;</span>
 
  <span class="kw1">return</span> <span class="kw2">EXIT_SUCCESS</span><span class="sy4">;</span>
<span class="br0">}</span></pre></div></div>