// now draw the polygon to stencil buffer // incrementing stencil when poly is visible drawPolygon ( poly );
// restore attributes glPopAttrib ();
}
void StencilSubScene :: decStencil ( const Polygon3D&
poly ) const

А. В. Боресков. Графика трехмерной компьютерной игры {

// save current state glPushAttrib ( GL_COLOR_BUFFER_BIT |
GL__DEPTH_BUFFER_BIT | GL_ENABLE_BIT | GL_STENCIL_BUFFER_BIT );
// setup OpenGL so we write only to stencil // buffer in visible pixels of the poly glDisable ( GL_TEXTURE_2D );
glColorMask ( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE ); glDepthMask ( GL_FALSE ) ,;
// set op to decrement on stencil pass (zpass
// or zfail)
glStencilOp ( GL_KEEP, GL_DECR, GL_DECR );
glStencilFunc ( GL_EQUAL, curStencilVal, OxFFFFFFFF );
// now draw the polygon to stencil buffer // incrementing stencil when poly is visible drawPolygon ( poly );
// restore attributes glPopAttrib ();
}
void StencilSubScene :: clearDepth ( const Cameras
camera, const Polygon3D& poly ) const
{
int numVertices = poly.getNumVertices ();
Vector3D org ( camera.getPos () ) ;
Vector3D normal ( camera.getViewDir () ); Vector3D point ( org + (camera.getZFar () * 0.99f) *
normal );
Plane farPlane ( normal, point ) ;
Vector3D v;
// save current state glPushAttrib ( GL_COLOR_BUFFER_BIT |
GL_DEPTH_BUFFER_BIT | GL_ENABLE_BIT | GL_STENCIL_BUFFER_BIT );
// now reset depth to max where stencil is
// equal to curStencilVal by projecting
// verices onto the far plane, leaving stencil
// unchanged

Пишем портальный рендерер (часть III)

glColorMask ( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
glDepthMask ( GL_TRUE ) ;
glEnable ( GL_STENCIL_TEST );
glStencilFunc ( GL_EQUAL, curStencilVal, OxFFFFFFFF );
glStencilOp ( GL_KEEP, GL_KEEP, GL_KEEP );
glDepthFunc ( GL_ALWAYS );
glBegin ( GL_POLYGON );
const Vector3D * vertices = poly.getVertices ();
for ( int i =0; i < numVertices; i++ ) {

⇐ Предыдущая| |Следующая ⇒