[vtkusers] Using VTK mixed with OpenGL in a MFC app
Clinton Stimpson
clinton at elemtech.com
Thu Aug 19 10:02:33 EDT 2004
> ------------------------------
>
> Message: 3
> Date: Thu, 19 Aug 2004 17:41:28 +1000
> From: "BURRELL Benjamin" <Benjamin.BURRELL at Tenix.com>
> Subject: [vtkusers] Using VTK mixed with OpenGL in a MFC app
> To: <vtkusers at vtk.org>
> Message-ID: <200408190741.i7J7fS1r016422 at sprint1.tenix.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hi,
>
> I have searched the vtk mailing list for the solution and even though I
> have found some posts on this, none of them where very helpful and I have
> still no idea how to get this going.
>
> What I would like to do is use a pre-existing window in my MFC MDI app,
> assign a vtkWin32OpenGLRenderWindow to it and use it with VTK and OpenGL
> calls.
> Eg. I want to be able to have a visualisation of terrain using VTK, then
> have small textured 2D squares and primitives such as lines written in
> OpenGL moving around dictated by a socket connection. All this of course
> sharing the same window.
>
> At the moment I have had my project working all implemented in VTK and
> working fine (except slow after a lot of speed tuning, hence wanting to
> do the moving items in OpenGL), now I am trying to change to using OpenGL
> to draw the moving squares/primitives above a VTK drawn terrain. I would
> also like to keep the VTK mouse interaction as well as I have already got
> this going.
>
> My current app is a MFC MDI project which was created by using CMake. I
> then have set up my vtkWin32OpenGLRenderWindow using the following calls
> in the int CVtkMDIView::OnCreate(LPCREATESTRUCT lpCreateStruct) method.
>
> mp_renWin->SetParentId(GetParent()->GetSafeHwnd());
> mp_renWin->SetWindowId(GetSafeHwnd());
>
> mp_iren->SetRenderWindow(mp_renWin);
>
>
> This as far as I understand, this code tells my
> vtkWin32OpenGLRenderWindow to draw to my CView object which is this case
> is the class CVtkMDIView.
>
> Could someone please be able to tell me exactly the steps required to
> setup being able to call/draw OpenGL now?
> For example, if I wanted to draw a OpenGL circle on top of my VTK terrain
> I would use this OpenGL code somewhere:
>
> glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The
> Screen And The Depth Buffer
> glLoadIdentity(); // Reset The matrix
>
> glColor3ub(255, 0, 0);
>
> glPushMatrix();
> glTranslatef(x, y, 0);
> glBegin(GL_LINE_LOOP);
> for( float ang=0; ang <= 2*3.141; ang += 0.1)
> {
> glVertex2d( radius * cos(ang), radius * sin(ang));
> }
> glEnd();
> glPopMatrix();
>
>
> What calls do I have to make to the vtkRenderWindow, vtkRenderer objects
> to allow this to work, where would I place the OpenGL code, had do I do
> refreshing properly etc. ?
Derive from vtkProp, vtkActor2D, vtkProp3D or vtkActor or whatever makes
sense in your case and overload which functions (RenderOpaqueGeometry,
RenderTranslucentGeometry or RenderOverlay - for 2d drawing) you need to
overload.
And you don't need to do the glClear as that would be done for you.
Then add your new prop to the renderer.
I do things like this for drawing that can't be efficiently handled using
the vtk data set classes (e.g. dynamic data that has to be computed and
drawn at render time and is dependent on camera orientation).
Clint
>
> Regards,
> Benjamin Burrell
>
>
>
>
> ------------------------------
More information about the vtkusers
mailing list