Cocos2d-x opengl 画图

  1. #include "BaseDrawLayer.h"  
  2.   
  3. BaseDrawLayer::BaseDrawLayer()  
  4. {  
  5.   
  6. }  
  7. BaseDrawLayer::~BaseDrawLayer(void)  
  8. {  
  9.   
  10. }  
  11.   
  12. void BaseDrawLayer::draw()  
  13. {  
  14.     //注意:注意OpenGL的坐标系,起始点为左下角  
  15.     CCSize s=CCDirector::sharedDirector()->getWinSize();  
  16.       
  17.     //设置点大小、颜色,然后绘制一个点  
  18.     glPointSize(64);  
  19.     glColor4f(0.0,0.0,1.0,0.5);  
  20.     ccDrawPoint(ccp(s.width/2+10,s.height/2));  
  21.   
  22.     //绘制一条线,参数为起始点和终点的坐标  
  23.     glEnable(GL_LINE_SMOOTH);  
  24.     ccDrawLine(ccp(0,0),ccp(s.width,s.height));  
  25.   
  26.      // 设置线的宽度,颜色,然后绘制一个圆  
  27.     glLineWidth(2);  
  28.     ccDrawColor4B(0, 255, 255, 255);  
  29.     //参数说明:中心点坐标,半径,角度,分段数,经过中间的线是否显示  
  30.     ccDrawCircle( ccp(s.width/2, s.height/2), 50, 0, 50, false);  
  31.       
  32.     //绘制多边形  
  33.     ccDrawColor4B(255, 255, 0, 255);  
  34.     glLineWidth(10);  
  35.     CCPoint vertices[] = { ccp(0,0), ccp(50,50), ccp(100,50), ccp(100,100), ccp(50,100) };  
  36.     //参数说明:点集合,点数,这五个点是否构成闭合  
  37.     ccDrawPoly( vertices, 5, false);  
  38.   
  39.     //绘制实心多边形  
  40.     glLineWidth(1);  
  41.     CCPoint filledVertices[] = { ccp(0,120), ccp(50,120), ccp(50,170), ccp(25,200), ccp(0,170) };  
  42.     ccDrawSolidPoly(filledVertices, 5, ccc4f(0.5f, 0.5f, 1, 1 ) );  
  43.   
  44.     //绘制三角形  
  45.     ccDrawColor4B(255, 0, 255, 255);  
  46.     glLineWidth(2);  
  47.     CCPoint vertices2[] = { ccp(30,130), ccp(30,230), ccp(50,200) };  
  48.     ccDrawPoly( vertices2, 3, true);  
  49.   
  50.     //绘制一个控制点贝瑟尔曲线  
  51.     //参数说明:起点、控制点、终点,分段数  
  52.     ccDrawQuadBezier(ccp(0,s.height), ccp(s.width/2,s.height/2), ccp(s.width,s.height), 50);  
  53.   
  54.     //绘制两个控制点贝瑟尔曲线  
  55.     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);  
  56.   
  57.      //绘制填充的菱形  
  58.     CCPoint vertices3[] = {ccp(60,160), ccp(70,190), ccp(100,190), ccp(90,160)};  
  59.     ccDrawSolidPoly( vertices3, 4, ccc4f(1,1,0,1) );  
  60.   
  61.     // 恢复opengl绘制的原始值  
  62.     glLineWidth(1);  
  63.     ccDrawColor4B(255,255,255,255);  
  64.     ccPointSize(1);  
  65. }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值