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);


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



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