Jump to content
  • Advertisement
Sign in to follow this  

Stencil buffer not working on Android NDK implementation

This topic is 1148 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Got my game engine to build and run on the Android over the week end. It also builds and runs on Windows and Linux.


Is there some extra step to get stencil buffering working? Same code works as expected on WIndows and Linux.

Share this post

Link to post
Share on other sites

Thanks frob but I found the problem (face palm).


I was setting glStencilMask() before and after the render to the stencil buffer. I found some info about how this should be set before the stencil buffer is cleared and in many cases, only needs to be set in your init with all your other OpenGL settings on start up.


My implementation was from some stencil buffer demo but worked fine in WIndows and Linux. Odd.

Edited by GameCodingNinja

Share this post

Link to post
Share on other sites

i will be using stencil in future, can you tell more about it? are you only setting stencil bits during opengl initialization, or did you write something else?

Share this post

Link to post
Share on other sites

I'm only setting it in the init now. My stencil needs at the moment are very simple but I can't see needing to do more at this time.


The way to think of this is the glStencilMask() is like glClearColor, you're telling OpenGL what value to use when clearing the stencil buffer, just like the color or depth buffer. This all happens when glClear is used. Example: glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT )


See my adjusted code below.

*    desc:  Init the game
void CBaseGame::Init()
    // Init the clear color
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    // Init the stencil clear mask based on the bit size of the mask
    // Stencil buffer can only be 1 or 8 bits per pixel
    if( CSettings::Instance().GetStencilBufferBitSize() == 1 )
    else if( CSettings::Instance().GetStencilBufferBitSize() == 8 )

    // Cull the back face

    // Enable alpha blending

    // Make the zero texture the active texture

    // Show the window
    CDevice::Instance().ShowWindow( true );

    if( CSettings::Instance().GetClearTargetBuffer() )
        m_clearBufferMask |= GL_COLOR_BUFFER_BIT;

    if( CSettings::Instance().GetEnableDepthBuffer() )
        m_clearBufferMask |= GL_DEPTH_BUFFER_BIT;
    if( CSettings::Instance().GetClearStencilBuffer() )
        m_clearBufferMask |= GL_STENCIL_BUFFER_BIT;
    // Display a black screen
    glClear( GL_COLOR_BUFFER_BIT );
    SDL_GL_SwapWindow( m_pWindow );

}   // Init

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!