[vtkusers] using glStencilFunc() and glStencilOp() function in vtk
刘卓
polinzhuo at 163.com
Wed Dec 13 01:18:19 EST 2006
Hi all:
I have read some mails about using Stencil Buffer in vtk. I know the
function vtkWin32OpenGLRenderWindow:: SetupPixelFormat() must be
overwritten. I save the buffer data to a Text file. And When I draw an
object to Stencil buffer, the result is not my desire. The code is listed
below:
pCone = vtkConeSource::New();
pCone->SetCenter( -10.0 , 0.0 , 0.0 );
pCone->SetRadius( 2.0 );
pCone->SetHeight(10);
vtkPolyDataMapper* mapMest = vtkPolyDataMapper::New();
mapMest->SetInput(pSphere->GetOutput());
meshActot = vtkOpenGLActor::New();
meshActor->SetMapper(mapMest);
meshActor->GetProperty()->SetColor(1,0,0);
ren1 = new vtkOpenGLRenderer;
ren1->AddActor( meshActor );
renWin = new vtkWin32OpenGLRenderWindow;
renWin->AddRenderer(ren1);
iren = vtkRenderWindowInteractor::New();
iren->Initialize();
glClear (GL_DEPTH_BUFFER_BIT |
GL_STENCIL_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS,1,1);
glStencilOp(GL_KEEP,GL_REPLACE,GL_REPLACE);
renWin->Render();
iren->Start();
float pSphereZBuffer[WINDOW_SIZE*WINDOW_SIZE];
glDisable( GL_TEXTURE_2D );
glDisable( GL_SCISSOR_TEST );
glPixelStorei( GL_PACK_ALIGNMENT, 1 );
glReadPixels( 0, 0,
WINDOW_SIZE, WINDOW_SIZE,
GL_STENCIL_INDEX, GL_FLOAT,
pSphereZBuffer );
ofstream file("zbuffer1.txt");
for(i = 0 ; i < WINDOW_SIZE ; i++ )
{
for(j = 0 ; j < WINDOW_SIZE ; j++ )
file<<setprecision(0)<<setw(4)<<pSphereZBuffer[WINDOW_SIZE*i+j];
file<<endl;
}
file.close();
The result is not right. But When these codes are moved in the front of the
function renWin->Render(), the result is right.
glClear (GL_DEPTH_BUFFER_BIT |
GL_STENCIL_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS,1,1);
glStencilOp(GL_KEEP,GL_REPLACE,GL_REPLACE);
just like that, the function vtkOpenGLRenderWindow::Render is overwritten.
vtkMYOpenGLRenderWindow ::Render()
{
glClear (GL_DEPTH_BUFFER_BIT |
GL_STENCIL_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS,1,1);
glStencilOp(GL_KEEP,GL_REPLACE,GL_REPLACE);
…………..
…………….
}
Who can tell me the reason?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20061213/926ff540/attachment.htm>
More information about the vtkusers
mailing list