Implementing the scissor test on Cocos2dx - Plunge Interactive

Implementing the scissor test on Cocos2dx

The scissor test is a very useful OpenGL operation that discards fragments that fall outside of a certain rectangular portion of the screen. Example: Imagine you want to implement a scroll, then this is when the scissor test helps.

In Cocos2d-x this is really simple. You just need to override the “visit()” method available in any CCNode (this obviously includes CCLayer, CCScene, etc), with something like this:

void YourScene::visit()
{
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();

    CCPoint bottomLeft = this->convertToWorldSpace(ccp(0, 0));
    CCPoint topRight   = this->convertToWorldSpace(winSize);

    glEnable(GL_SCISSOR_TEST);

    CCEGLView::sharedOpenGLView()->setScissorInPoints(bottomLeft.x, bottomLeft.y,
                                                      topRight.x - bottomLeft.x,
                                                      topRight.y - bottomLeft.y);

    CCScene::visit();

    glDisable(GL_SCISSOR_TEST);
}

You just need to set the scissor area and we are done!

This site uses cookies to store information on your computer. Some cookies on this site are essential, and the site won't work as expected without them. Read more about them

ACCEPT