- #include "BaseDrawLayer.h"
- BaseDrawLayer::BaseDrawLayer()
- {
- }
- BaseDrawLayer::~BaseDrawLayer(void)
- {
- }
- void BaseDrawLayer::draw()
- {
- //注意:注意OpenGL的坐标系,起始点为左下角
- CCSize s=CCDirector::sharedDirector()->getWinSize();
- //设置点大小、颜色,然后绘制一个点
- glPointSize(64);
- glColor4f(0.0,0.0,1.0,0.5);
- ccDrawPoint(ccp(s.width/2+10,s.height/2));
- //绘制一条线,参数为起始点和终点的坐标
- glEnable(GL_LINE_SMOOTH);
- ccDrawLine(ccp(0,0),ccp(s.width,s.height));
- // 设置线的宽度,颜色,然后绘制一个圆
- glLineWidth(2);
- ccDrawColor4B(0, 255, 255, 255);
- //参数说明:中心点坐标,半径,角度,分段数,经过中间的线是否显示
- ccDrawCircle( ccp(s.width/2, s.height/2), 50, 0, 50, false);
- //绘制多边形
- 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);
- //绘制实心多边形
- 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 ) );
- //绘制三角形
- ccDrawColor4B(255, 0, 255, 255);
- glLineWidth(2);
- CCPoint vertices2[] = { ccp(30,130), ccp(30,230), ccp(50,200) };
- ccDrawPoly( vertices2, 3, true);
- //绘制一个控制点贝瑟尔曲线
- //参数说明:起点、控制点、终点,分段数
- ccDrawQuadBezier(ccp(0,s.height), ccp(s.width/2,s.height/2), ccp(s.width,s.height), 50);
- //绘制两个控制点贝瑟尔曲线
- ccDrawCubicBezier(ccp(s.width/2, s.height/2), ccp(s.width/2+30,s.height/2+50), ccp(s.width/2+60,s.height/2-50),ccp(s.width, s.height/2),100);
- //绘制填充的菱形
- CCPoint vertices3[] = {ccp(60,160), ccp(70,190), ccp(100,190), ccp(90,160)};
- ccDrawSolidPoly( vertices3, 4, ccc4f(1,1,0,1) );
- // 恢复opengl绘制的原始值
- glLineWidth(1);
- ccDrawColor4B(255,255,255,255);
- ccPointSize(1);
- }
Cocos2d-x opengl 画图
最新推荐文章于 2024-01-31 05:18:22 发布