Cocos2d-x3.0 glScissor 区域裁切

Datetime:2017-02-03 11:41:47         Topic: Cocos2d          Share        Original >>
Here to See The Original Article!!!

// on "init" you need to initialize your instance
bool HelloWorld::init()
{
	// 1. super init first
	if ( !Layer::init() )
	{
		return false;
	}
	
	Size visibleSize = Director::getInstance()->getVisibleSize();
	Point origin = Director::getInstance()->getVisibleOrigin();

	// add "HelloWorld" splash screen"
	auto sprite = Sprite::create("HelloWorld.png");

	sprite->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));

	this->addChild(sprite, 0);


	glEnable(GL_SCISSOR_TEST);// 开启显示指定区域
	return true;
}
void HelloWorld::visit(Renderer *renderer, const kmMat4& parentTransform, bool parentTransformUpdated){
	
	float x = 100;
	float y = 100;
	float n_width = Director::getInstance()->getWinSize().width;
	float n_height = Director::getInstance()->getWinSize().height/2;
	log("x = %f,y = %f,w = %f,h = %f",x,y,n_width,n_height);
	glScissor(x, y, n_width, n_height);	 // 只显示当前窗口的区域
	Layer::visit(renderer, parentTransform, parentTransformUpdated);//显示父类的内容
	//glDisable(GL_SCISSOR_TEST);			 // 禁用
	
	
	return;
	
}







New