update
[linguofeng.github.com.git] / _posts / 2012-09-14-cocos2d-x-glScissor.textile
blob6f1fe2b0fe93d1b24f4bdd2b603823d7f905d5fe
1 ---
2 layout: post
3 title: Cocos2d-x之区域裁剪
4 description: 主要使用OpenGL提供的glScissor函数。
5 categories: [archive]
6 tags: [cocos2d-x]
7 ---
9 <section id="1">
10     <div class="page-header">
11         <h3>一、在Cocos2d-x中就这样来实现区域的显示</h3>
12     </div>
13 <pre class="prettyprint">
14 class HelloLayer: cocos2d::CCLayer
16     public:
17         virtual void visit(void);
20 // visit()函数在每帧时调用
21 void HelloLayer::visit()
23     glEnable(GL_SCISSOR_TEST);              // 开启显示指定区域
24     float x = this->getPositionX();
25     float y = this->getPositionY();
26     float n_width = this->getContentSize().width;
27     float n_height = this->getContentSize().height;
28     glScissor(x, y, n_width, n_height);     // 只显示当前窗口的区域
29     CCLayer::visit();                       // 调用下面的方法
30     glDisable(GL_SCISSOR_TEST);             // 禁用
32 </pre>
33 </section>