<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 <GL/glut.h></span>
<span class="co2">#else</span>
<span class="co2">#include <glut.h></span>
<span class="co2">#endif</span>
<span class="co2">#include "vtkConeSource.h"</span>
<span class="co2">#include "vtkPolyDataMapper.h"</span>
<span class="co2">#include "vtkRenderWindow.h"</span>
<span class="co2">#include "vtkCamera.h"</span>
<span class="co2">#include "vtkActor.h"</span>
<span class="co2">#include "vtkRenderer.h"</span>
<span class="co2">#include "vtkNew.h"</span>
vtkNew<span class="sy1"><</span>vtkRenderer<span class="sy1">></span> ren<span class="sy4">;</span>
vtkNew<span class="sy1"><</span>vtkRenderWindow<span class="sy1">></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">></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">></span>Render<span class="br0">(</span><span class="br0">)</span><span class="sy4">;</span>
ren<span class="sy2">-</span><span class="sy1">></span>GetActiveCamera<span class="br0">(</span><span class="br0">)</span><span class="sy2">-</span><span class="sy1">></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">&</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">"VTK-GLUT Example"</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"><</span>vtkConeSource<span class="sy1">></span> cone<span class="sy4">;</span>
vtkNew<span class="sy1"><</span>vtkPolyDataMapper<span class="sy1">></span> coneMapper<span class="sy4">;</span>
coneMapper<span class="sy2">-</span><span class="sy1">></span>SetInputConnection<span class="br0">(</span> cone<span class="sy2">-</span><span class="sy1">></span>GetOutputPort<span class="br0">(</span><span class="br0">)</span> <span class="br0">)</span><span class="sy4">;</span>
vtkNew<span class="sy1"><</span>vtkActor<span class="sy1">></span> coneActor<span class="sy4">;</span>
coneActor<span class="sy2">-</span><span class="sy1">></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">></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">></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">></span>InitializeFromCurrentContext<span class="br0">(</span><span class="br0">)</span><span class="sy4">;</span>
<span class="co1">// Let'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>