draw primitives

效果图如下:



CHECK_GL_ERROR_DEBUG();

//draw a simple line

//The default state is:

//Line Width: 1

//color: 255,255,255,255 (white, non-transparent)

//Anti-Aliased

//glEnable(GL_LINE_SMOOTH);

//画一个简单的线,线宽:1,颜色:255255255255(白色不透明的)

ccDrawLine( 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 );            //设置线宽

ccDrawColor4B(255,0,0,255);

//绘制一条线,参数:起点,终点

ccDrawLine( VisibleRect::leftTop(), VisibleRect::rightBottom() );

CHECK_GL_ERROR_DEBUG();

    

//TIP:

//If you are going to use always the 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

//如果你总是要使用相同的颜色和宽度,你不需要每次都调用它,opengl已记住状态,画大点的中心

ccPointSize(64);                //设置点的尺寸(点为正方形)

ccDrawColor4B(0,0,255,128);

//绘制一个点,参数:点的坐标

ccDrawPoint( VisibleRect::center() );

CHECK_GL_ERROR_DEBUG();

    

//draw 4 small points

CCPoint points[] = { ccp(60,60), ccp(70,70), ccp(60,70), ccp(70,60) };

ccPointSize(4);  //设置点的大小 (点为正方形)

ccDrawColor4B(0,255,255,255);

//绘制多点,参数:点数组,需绘制的点数

ccDrawPoints( points, 4);

CHECK_GL_ERROR_DEBUG();

    

//draw a green circle with 10 segments

glLineWidth(16);

ccDrawColor4B(0, 255, 0, 255);

//绘制圆,参数:圆点坐标,半径,角度,分段数(越大越圆),是否连接中心点

ccDrawCircle( VisibleRect::center(), 100, 0, 10, false);

CHECK_GL_ERROR_DEBUG();    


//draw a green circle with 50 segments with line to center

glLineWidth(2);

ccDrawColor4B(0, 255, 255, 255);

ccDrawCircle( VisibleRect::center(), 50, CC_DEGREES_TO_RADIANS(90), 50, true);

CHECK_GL_ERROR_DEBUG();

    

//open yellow poly

ccDrawColor4B(255, 255, 0, 255);

glLineWidth(10);

CCPoint vertices[] = { ccp(0,0), ccp(50,50), ccp(100,50), ccp(100,100), ccp(50,100) };

//绘制多边形,参数:点数组,绘制的点数,是否头尾相接

ccDrawPoly( vertices, 5, false);

CHECK_GL_ERROR_DEBUG();

//filled poly

glLineWidth(1);

CCPoint filledVertices[] = { ccp(0,120), ccp(50,120), ccp(50,170), ccp(25,200), ccp(0,170) };

//绘制实体多边形,参数:点数组,绘制点数,实体部分的颜色

ccDrawSolidPoly(filledVertices, 5, ccc4f(0.5f, 0.5f, 1, 1 ) );

    

    

//closed purble poly

ccDrawColor4B(255, 0, 255, 255);

glLineWidth(2);

CCPoint vertices2[] = { ccp(30,130), ccp(30,230), ccp(50,200) };

ccDrawPoly( vertices2, 3, true);

CHECK_GL_ERROR_DEBUG();

    

//draw quad bezier path

//绘制有一个控制点的贝塞尔曲线,参数:起点,控制点1,终点,段数

ccDrawQuadBezier(VisibleRect::leftTop(), VisibleRect::center(), VisibleRect::rightTop(), 50);

CHECK_GL_ERROR_DEBUG();

    

//draw cubic bezier path

//绘制有两个控制点的贝塞尔曲线,参数:起点,控制点1,控制点2,终点,段数

ccDrawCubicBezier(VisibleRect::center(), ccp(VisibleRect::center().x+30,VisibleRect::center().y+50), ccp(VisibleRect::center().x+60,VisibleRect::center().y-50),VisibleRect::right(),100);

    

CHECK_GL_ERROR_DEBUG();

    

//draw a solid polygon

CCPoint vertices3[] = {ccp(60,160), ccp(70,190), ccp(100,190), ccp(90,160)};

ccDrawSolidPoly( vertices3, 4, ccc4f(1,1,0,1) );

    

//restore original values

//恢复原始值

glLineWidth(1);

ccDrawColor4B(255,255,255,255);

ccPointSize(1);

    

CHECK_GL_ERROR_DEBUG();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值