cocos2d-x 简单OpenGL 画图
void testNode::draw(){ CCSize s = CCDirector::sharedDirector()->getWinSize(); //线 glLineWidth( 5.0f ); //线宽 ccDrawColor4B(255,0,0,255);//画笔颜色 ccDrawLine( CCPointMake(0, s.height/2), CCPointMake(s.width, s.height/2) );//画一条线 ccDrawLine( CCPointMake(s.width/2, 0), CCPointMake(s.width/2, s.height)); // //方块 ccPointSize(64); //设置方块的大小 ccDrawColor4B(0,0,255,128); ccDrawPoint(ccp(s.width/2, s.height/2));//位置 // //ccDrawPoint方法也可以实现自定点的四边形 CCPoint points[] = { ccp(60,60), ccp(70,70), ccp(60,70), ccp(70,60) }; // //也可以群画 ccPointSize(4);//设置大小 ccDrawColor4B(0,255,255,255); ccDrawPoints( points, 4);//ccDrawPointsvoid // ccDrawPoints( const CCPoint *points, unsigned int numberOfPoints ) //// points 位置 numberOfPoints 个数 // //画圆形 glLineWidth(0.5f); ccDrawColor4B(0, 255, 0, 255); ccDrawCircle(ccp(s.width/2, s.height/2), 100, 0, 20, false); // //1,位置2,半径,3角度,4段 5,是否连接上 // // //不规则形状 ccDrawColor4B(255, 255, 0, 255); glLineWidth(0.5f); CCPoint vertices[] = { ccp(0,0), ccp(50,50), ccp(100,50), ccp(100,100), ccp(50,100) }; ccDrawPoly( vertices, 5, false); // //false 如果改为 ture 会无论画到那都会把开始点和结束点连接上 // // //不规则实体形状 // 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 ) ); // //画四贝塞尔曲线路径 ccDrawQuadBezier(ccp(100, 100), ccp(200, 200), ccp(300, 100), 30); // //开始点控制点结束点分割段数 //画立方贝塞尔曲线路径 ccDrawCubicBezier(ccp(s.width/2, s.height/2), ccp(s.width/2+30, s.height/2+50), ccp(s.width/2-30, s.height/2+50),ccp(200, 200),100); //不规则平行四边形 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); }