| 73 | } |
| 74 | |
| 75 | void StencilReflectionApp::drawScene() |
| 76 | { |
| 77 | gl::clear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); |
| 78 | gl::ScopedMatrices scopeMatrices; |
| 79 | { |
| 80 | gl::setMatrices( mCam ); |
| 81 | gl::multModelMatrix( translate( vec3( 0, -2, -1.5 ) ) ); |
| 82 | gl::multModelMatrix( rotate( -mRotation, vec3( 0, 0, 1 ) ) ); |
| 83 | { |
| 84 | // enable stencil test to be able to give the stencil buffers values. |
| 85 | gl::ScopedState scopeStencil( GL_STENCIL_TEST, true ); |
| 86 | gl::stencilFunc( GL_ALWAYS, 1, 0xFF ); |
| 87 | gl::stencilOp( GL_KEEP, GL_KEEP, GL_REPLACE ); |
| 88 | gl::stencilMask( 0xFF ); |
| 89 | gl::depthMask( GL_FALSE ); |
| 90 | gl::clear( GL_STENCIL_BUFFER_BIT ); |
| 91 | // draw the seperation plane into the stencil buffer. |
| 92 | { |
| 93 | gl::ScopedModelMatrix scopeModel; |
| 94 | gl::multModelMatrix( translate( vec3( 0, 0, 1.5 ) ) ); |
| 95 | gl::color( ColorA( 0, 0, 0, 1 ) ); |
| 96 | gl::drawSolidRect( Rectf( -1.25, -1.25, 1.25, 1.25 ) ); |
| 97 | } |
| 98 | // now tell the stencil what type of stenciling it has. |
| 99 | gl::stencilFunc( GL_EQUAL, 1, 0xFF ); |
| 100 | gl::stencilMask( 0x00 ); |
| 101 | gl::depthMask( GL_TRUE ); |
| 102 | // draw into that stenciled area |
| 103 | { |
| 104 | gl::ScopedModelMatrix scopeModel; |
| 105 | gl::ScopedBlendAlpha scopeAlphaBlend; |
| 106 | gl::ScopedState scopeCull( GL_CULL_FACE, true ); |
| 107 | gl::multModelMatrix( translate( vec3( 0, 0, 1 ) ) ); |
| 108 | gl::color( ColorA( 1.0f, 1.0f, 1.0f, .09f ) ); |
| 109 | |
| 110 | glCullFace( GL_FRONT ); |
| 111 | gl::drawCube( vec3( 0, 0, 1), vec3( 1, 1, 1 ) ); |
| 112 | |
| 113 | glCullFace( GL_BACK ); |
| 114 | gl::drawCube( vec3( 0, 0, 1), vec3( 1, 1, 1 ) ); |
| 115 | } |
| 116 | } |
| 117 | // This scope closes so Stencil test will no longer be performed |
| 118 | // The below colorCube's rendering will be unaffected. |
| 119 | gl::color( ColorA( 1, 1, 1, 1 ) ); |
| 120 | gl::drawColorCube( vec3( 0, 0, 1), vec3( 1, 1, 1 ) ); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | // Enabling stencil on the system framebuffer |
| 125 | auto options = RendererGl::Options().msaa( 16 ).stencil(); |
nothing calls this directly
no test coverage detected