[vtkusers] Using VTK mixed with OpenGL in a MFC app

BURRELL Benjamin Benjamin.BURRELL at Tenix.com
Thu Aug 19 03:41:28 EDT 2004


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. ?

Regards,
Benjamin Burrell





More information about the vtkusers mailing list