In glScissor use glScissor

When we use the function to cut a visualable area,like this:
void beforeDraw() { m_scissorState=glIsEnabled(GL_SCISSOR_TEST); m_originScissor[4]; if(m_scissorState==GL_FALSE){ glGetIntegerv(GL_VIEWPORT,m_originScissor); glEnable(GL_SCISSOR_TEST); } else{ glGetIntegerv(GL_SCISSOR_BOX,m_originScissor); } CCPoint wordPoint = convertToWorldSpace(ccp(0,0)); float sx = this->getScaleX(); float sy = this->getScaleY(); CCSize size=getContentSize(); CCEGLView::sharedOpenGLView()->setScissorInPoints( wordPoint.x*sx,wordPoint.y*sy, size.width*sx,size.height*sy); } void afterDraw() { glDisable(GL_SCISSOR_TEST); } virtual void visit() { if (isVisible())//Cut the view { //some other thing this->beforeDraw(); CCLayer::visit(); this->afterDraw(); } }
We get a problem that the first glScissor invalid.

We can Fix it like this:
`void beforeDraw()
{
m_scissorState=glIsEnabled(GL_SCISSOR_TEST);
if(m_scissorState==GL_FALSE)glEnable(GL_SCISSOR_TEST);
m_originScissor[4];
glGetIntegerv(GL_SCISSOR_BOX,m_originScissor);
CCPoint wordPoint = convertToWorldSpace(ccp(0,0));
float sx = this->getScaleX();
float sy = this->getScaleY();
CCSize size=getContentSize();
float self[4];
self[0]=wordPoint.xsx;
self[1]=wordPoint.y
sy;
self[2]=size.widthsx;
self[3]=size.height
sy;
float expectScissor[4];//intersection Scissor
expectScissor[0]=max(self[0],m_originScissor[0]);
expectScissor[1]=max(self[1],m_originScissor[1]);
expectScissor[2]=max(min(self[0]+self[2],m_originScissor[0]+m_originScissor

[2])-expectScissor[0],0);
expectScissor[3]=max(min(self[1]+self[3],m_originScissor[1]+m_originScissor

[3])-expectScissor[1],0);
CCEGLView::sharedOpenGLView()->
setScissorInPoints(
expectScissor[0],expectScissor[1],
expectScissor[2],expectScissor[3]);
}
void afterDraw(){
if(m_scissorState==GL_FALSE)glDisable(GL_SCISSOR_TEST);//If already open it

do not close it
CCEGLView::sharedOpenGLView()->
setScissorInPoints(
m_originScissor[0],m_originScissor[1],
m_originScissor[2],m_originScissor[3]);//recover the origin scissor
}
virtual void visit(){
if (isVisible())//Cut the view
{
//other thing
this->beforeDraw();
CCLayer::visit();
this->afterDraw();
}
}`
I don’t know how to paste the code…