[vtkusers] Color doesn't change with external Open GL render -- ?
David Edwards
dedwards at msc.com
Wed Jul 16 20:17:44 EDT 2003
Hi,
I need to do some OpenGL immediate mode rendering into a VTK scene. In
this example, I draw a cone using VTK, and when I get an EndEvent from
the vtkRenderer (which occurs at the end of the render), I draw a little
rectangle using pure OpenGL.
Here's the problem: The drawn rectangle is always the same color as the
cone, regardless of what I set it to with glColor3f. If I change the
cone to red, the rectangle will be red, etc. The rect is renderer in the
correct location, but with the wrong color.
The code is below. I sure could use some help on this one.
Thanks,
- David Edwards
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Draw vtk cone and pure OpenGL rectangle.
//
#include "stdafx.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkConeSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkCommand.h"
#include "vtkProperty.h"
#include <gl/gl.h>
#include <gl/glu.h>
class CRenderCommand : public vtkCommand
{
public:
static CRenderCommand *New()
{ return new CRenderCommand; }
//
// This gets executed when the Renderer completes the rendering
// (but before exiting UpdateGeometry()
virtual void Execute(vtkObject *caller, unsigned long, void*) {
vtkRenderer *renderer = reinterpret_cast<vtkRenderer*>(caller);
vtkRenderWindow* rw = renderer->GetRenderWindow();
rw->MakeCurrent();
glColor3f(0,1,0); // This line has no effect
glRectf(.3,-.3,.4,-.4); // Draw the rectangle
}
};
void main( int argc, char *argv[] )
{
//
// create a rendering window and renderer
vtkRenderer *ren = vtkRenderer::New();
//
// Add the callback for the render method
CRenderCommand* pCallback = CRenderCommand::New();
ren->AddObserver(vtkCommand::EndEvent,pCallback);
vtkRenderWindow *renWindow = vtkRenderWindow::New();
renWindow->AddRenderer(ren);
//
// create an actor and give it cone geometry
vtkConeSource *cone = vtkConeSource::New();
cone->SetResolution(8);
vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New();
coneMapper->SetInput(cone->GetOutput());
vtkActor *coneActor = vtkActor::New();
coneActor->SetMapper(coneMapper);
coneActor->GetProperty()->SetColor(0,0,1);
//
// assign our actor to the renderer
ren->AddActor(coneActor);
//
// draw the resulting scene
vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWindow);
renWindow->Render();
iren->Start();
//
// Clean up
ren->Delete();
renWindow->Delete();
cone->Delete();
coneMapper->Delete();
coneActor->Delete();
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20030716/73780cde/attachment.htm>
More information about the vtkusers
mailing list