原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处、作者信息和本声明。否则将追究法律责任。 http://www.voidcn.com/article/p-dnjvrbos-wx.html 【唠叨】 绘图的方式有两种:
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。 http://www.voidcn.com/article/p-dnjvrbos-wx.html
// //创建DrawNode,然后后加入到Layer层中 DrawNode* drawNode = DrawNode::create(); this->addChild(drawNode); //...基本图形绘制... //
// //圆点 ('位置' , '圆点半径' , '填充颜色') void drawDot(const Vec2 &pos, float radius, const Color4F &color); //线段 ('起点' , '终点' , '半线宽' , '填充颜色') void drawSegment(const Vec2 &from, const Vec2 &to, float radius, const Color4F &color); //三角形 ('顶点1' , '顶点2' , '顶点3' , '填充颜色') void drawTriangle(const Vec2 &p1, const Vec2 &p2, const Vec2 &p3, const Color4F &color); //多边形 ('顶点数组' , '顶点个数' , '填充颜色' , '轮廓粗细' , '轮廓颜色') void drawPolygon(Vec2 *verts, int count, const Color4F &fillColor, float borderWidth, const Color4F &borderColor); //二次贝塞尔图形 ('起点' , '控制点' , '终点' , '分段数' , '填充颜色') void drawQuadraticBezier(const Vec2& from, const Vec2& control, const Vec2& to, unsigned int segments, const Color4F &color); //三次贝塞尔图形 ('起点' , '控制点1' , '控制点2' , '终点' , '分段数' , '填充颜色') void drawCubicBezier(const Vec2& from, const Vec2& control1, const Vec2& control2, const Vec2& to, unsigned int segments, const Color4F &color); //
drawNode->clear();
BlendFunc bl = { GL_ONE, GL_ONE }; drawNode->setBlendFunc(bl);
// Vec2 point[4]; point[0] = Vec2(100, 100); point[1] = Vec2(100, 200); point[2] = Vec2(200, 200); point[3] = Vec2(200, 100); //绘制空心多边形 //填充颜色:Color4F(1, 0, 0, 0), 透明 //轮廓颜色:Color4F(0, 1, 0, 1), 绿色 drawNode->drawPolygon(point, 4, Color4F(1, 0, 0, 0), 1, Color4F(0, 1, 0, 1));
//创建DrawNode DrawNode* drawNode = DrawNode::create(); this->addChild(drawNode); //圆点 drawNode->drawDot(Vec2(50, 50), 10, Color4F::RED); //线段 drawNode->drawSegment(Vec2(20, 100), Vec2(100, 100), 5, Color4F(0, 1, 0, 1)); drawNode->drawSegment(Vec2(20, 150), Vec2(100, 150), 10, Color4F(0, 0, 1, 1)); //三角形 drawNode->drawTriangle(Vec2(20, 250), Vec2(100, 300), Vec2(50, 200), Color4F(1, 1, 0, 1)); //实心多边形 Vec2 point1[4]; point1[0] = Vec2(150, 50); point1[1] = Vec2(150, 150); point1[2] = Vec2(250, 150); point1[3] = Vec2(250, 50); drawNode->drawPolygon(point1, 4, Color4F(1, 0, 0, 1), 1, Color4F(0, 1, 0, 1)); //空心多边形 Vec2 point2[4]; point2[0] = Vec2(150, 200); point2[1] = Vec2(150, 300); point2[2] = Vec2(250, 300); point2[3] = Vec2(250, 200); drawNode->drawPolygon(point2, 4, Color4F(1, 0, 0, 0), 1, Color4F(0, 1, 0, 1)); //二次贝塞尔 Vec2 from1 = Vec2(300, 20); Vec2 to1 = Vec2(450, 20); Vec2 control = Vec2(360, 100); drawNode->drawQuadraticBezier(from1, control, to1, 100, Color4F::ORANGE); //三次贝塞尔 Vec2 from2 = Vec2(300, 100); Vec2 to2 = Vec2(450, 100); Vec2 control1 = Vec2(350, 0); Vec2 control2 = Vec2(400, 200); drawNode->drawCubicBezier(from2, control1, control2, to2, 100, Color4F::YELLOW); //颜色混合测试 BlendFunc bl = { GL_ONE, GL_ONE }; drawNode->setBlendFunc(bl); drawNode->drawSegment(Vec2(300, 250), Vec2(450, 250), 10, Color4F::GREEN); drawNode->drawTriangle(Vec2(300, 200), Vec2(400, 300), Vec2(450, 150), Color4F::RED);
// 一个点、多个点 // 正方形小点 void drawPoint(const Vec2& point, const float pointSize, const Color4F &color); void drawPoints(const Vec2 *position, unsigned int numberOfPoints, const Color4F &color); void drawPoints(const Vec2 *position, unsigned int numberOfPoints, const float pointSize, const Color4F &color); // 线 void drawLine(const Vec2 &origin, const Vec2 &destination, const Color4F &color); // 矩形、四边形 // Solid表示实心 void drawRect(const Vec2 &origin, const Vec2 &destination, const Color4F &color); void drawRect(const Vec2 &p1, const Vec2 &p2, const Vec2 &p3, const Vec2& p4, const Color4F &color); void drawSolidRect(const Vec2 &origin, const Vec2 &destination, const Color4F &color); // 多边形 // Solid表示实心 void drawPoly(const Vec2 *poli, unsigned int numberOfPoints, bool closePolygon, const Color4F &color); void drawSolidPoly(const Vec2 *poli, unsigned int numberOfPoints, const Color4F &color); // 椭圆 // Solid表示实心 void drawCircle(const Vec2 ¢er, float radius, float angle, unsigned int segments, bool drawLineToCenter, const Color4F &color); void drawCircle( const Vec2& center, float radius, float angle, unsigned int segments, bool drawLineToCenter, float scaleX, float scaleY, const Color4F &color); void drawSolidCircle(const Vec2& center, float radius, float angle, unsigned int segments, const Color4F& color); void drawSolidCircle(const Vec2& center, float radius, float angle, unsigned int segments, float scaleX, float scaleY, const Color4F &color); // 样条曲线 void drawCardinalSpline(PointArray *config, float tension, unsigned int segments, const Color4F &color); void drawCatmullRom(PointArray *points, unsigned int segments, const Color4F &color);