@H_404_0@
@H_404_0@这就要求引擎全局组织绘制命令,即openglcocos2d::CustomCommand @H_404_0@
class CustomCommand : public RenderCommand{public: CustomCommand(); ~CustomCommand(); public: voID init(float depth); voID execute(); inline bool isTranslucent() { return true; } std::function<voID()> func;protected:};
@H_404_0@render执行单个RenderCommand时就是调用execute函数,最后访问额func成员,从而执行下面的onDraw。 @H_404_0@最后产生一堆绘制命令。等待真正opengl去执行,实际上每条绘制函数的命令都会去flush一次。 @H_404_0@
@H_404_0@代码是演示效果:VisibleRect来自testCpp,或者说下面整段来自testCpp。
voID HelloWorld::draw(Renderer *renderer,const Mat4 &transform,uint32_t flags){ m_customCommand.init(_globalZOrder); m_customCommand.func = CC_CALLBACK_0(HelloWorld::onDraw,this,transform,flags); renderer->addCommand(&m_customCommand);}voID HelloWorld::onDraw(const Mat4 &transform,uint32_t flags){ Director* director = Director::getInstance(); director->pushmatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW,transform); //draw CHECK_GL_ERROR_DEBUG(); // draw a simple line // The default state is: // line WIDth: 1 // color: 255,255,255 (white,non-transparent) // Anti-Aliased // glEnable(GL_liNE_SMOOTH); DrawPrimitives::drawline( VisibleRect::leftBottom(),VisibleRect::righttop() ); CHECK_GL_ERROR_DEBUG(); // line: color,wIDth,aliased // gllinewidth > 1 and GL_liNE_SMOOTH are not compatible // GL_SMOOTH_liNE_WIDTH_RANGE = (1,1) on iPhone // gldisable(GL_liNE_SMOOTH); gllinewidth( 5.0f ); DrawPrimitives::setDrawcolor4B(255,255); DrawPrimitives::drawline( VisibleRect::lefttop(),VisibleRect::rightBottom() ); CHECK_GL_ERROR_DEBUG(); // TIP: // If you are going to use always thde same color or wIDth,you don't // need to call it before every draw // // Remember: OpenGL is a state-machine. // draw big point in the center DrawPrimitives::setPointSize(64); DrawPrimitives::setDrawcolor4B(0,128); DrawPrimitives::drawPoint( VisibleRect::center() );//中心的圆点,蓝色正方向 CHECK_GL_ERROR_DEBUG(); // draw 4 small points Vec2 points[] = { Vec2(60,60),Vec2(70,70),Vec2(60,60) }; DrawPrimitives::setPointSize(4); DrawPrimitives::setDrawcolor4B(0,255); DrawPrimitives::drawPoints( points,4);//四个青色点 CHECK_GL_ERROR_DEBUG(); // draw a green circle with 10 segments gllinewidth(16); DrawPrimitives::setDrawcolor4B(0,255); DrawPrimitives::drawCircle( VisibleRect::center(),100,2,10,false); CHECK_GL_ERROR_DEBUG(); // draw a green circle with 50 segments with line to center gllinewidth(2); DrawPrimitives::setDrawcolor4B(0,255); DrawPrimitives::drawCircle( VisibleRect::center(),200,CC_degrees_TO_radians(90),50,true); CHECK_GL_ERROR_DEBUG(); // draw a pink solID circle with 50 segments gllinewidth(2); DrawPrimitives::setDrawcolor4B(255,255); DrawPrimitives::drawSolIDCircle( VisibleRect::center() + Vec2(140,0),40,1.0f,1.0f); CHECK_GL_ERROR_DEBUG(); // open yellow poly DrawPrimitives::setDrawcolor4B(255,255); gllinewidth(10); Vec2 vertices[] = { Vec2(0,Vec2(50,50),Vec2(100,100),100) }; DrawPrimitives::drawpoly( vertices,5,false);//左下角的方形 CHECK_GL_ERROR_DEBUG(); // filled poly gllinewidth(1);//五角星 Vec2 filledVertices[] = { Vec2(0,120),170),Vec2(25,200),Vec2(0,170) }; DrawPrimitives::drawSolIDpoly(filledVertices,color4F(0.5f,0.5f,1,1 ) ); // closed purble poly DrawPrimitives::setDrawcolor4B(255,255); gllinewidth(2); Vec2 vertices2[] = { Vec2(30,130),Vec2(30,230),200) }; DrawPrimitives::drawpoly( vertices2,3,true); CHECK_GL_ERROR_DEBUG(); // draw quad bezIEr path 中间这条线 DrawPrimitives::drawQuadBezIEr(VisibleRect::lefttop(),VisibleRect::center(),VisibleRect::righttop(),50); CHECK_GL_ERROR_DEBUG(); // draw cubic bezIEr path 上面的线 DrawPrimitives::drawCubicBezIEr(VisibleRect::center(),Vec2(VisibleRect::center().x+30,VisibleRect::center().y+50),Vec2(VisibleRect::center().x+60,VisibleRect::center().y-50),VisibleRect::right(),100); CHECK_GL_ERROR_DEBUG(); //draw a solID polygon Vec2 vertices3[] = {Vec2(60,160),190),Vec2(90,160)}; DrawPrimitives::drawSolIDpoly( vertices3,4,color4F(1,1) ); // restore original values gllinewidth(1); DrawPrimitives::setDrawcolor4B(255,255); DrawPrimitives::setPointSize(1); CHECK_GL_ERROR_DEBUG(); //end draw director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);}
@H_404_0@
西。 @H_404_0@const Vec2& center, @H_404_0@float radius, @H_404_0@float angle,---------这个参数有什么用?没看懂,测试了也感觉不出区别。。终于找到了,相对于x轴正方向旋转方向。比如:从90*pi/180度即y轴正方向与圆交点的位置 @H_404_0@unsigned int segments,:圆边被切成多少段线段 @H_404_0@bool drawlinetoCenter:圆心到起始绘制点是否绘制线段 @H_404_0@
voID drawCircle( const Vec2& center,float radius,float angle,unsigned int segments,bool drawlinetoCenter){ drawCircle(center,radius,angle,segments,drawlinetoCenter,1.0f);}待续 总结
以上是内存溢出为你收集整理的DrawPrimitive真是一个好类!!cocos的开发组干了好事。全部内容,希望文章能够帮你解决DrawPrimitive真是一个好类!!cocos的开发组干了好事。所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)