渲染的一些代码

/**

* draw will be called fps

*/

-(void) draw {

glDisable(GL_TEXTURE_2D);

glDisableClientState(GL_TEXTURE_COORD_ARRAY);

[_renderdrawOpenGLBackground];

glDisableClientState(GL_COLOR_ARRAY);

/**画的时候也要体现出一个层次感来~ */

[_renderdrawOneColorBackground]; //背景~

_world->DrawDebugData(); // debugDraw(因为包含更多,所以放在画冰块儿后面)~

[_renderdrawTouchPath:_mouseDowntouchSegment:_touchSegment];//切割路径~

[_renderdrawNails:_single.nailsnailsCount:_single.nailsCount];

if(![_gCfg bfk:@"debugDraw"]) {

[_renderdrawIce:_world]; //形状外框线条~

[_renderdrawLittleMap:_world];

}

// restore default GL states

glEnableClientState(GL_COLOR_ARRAY);

glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glEnable(GL_TEXTURE_2D);

}




// 绘制混色的背景~

-(void) drawOpenGLBackground {

b2Vec2 vertices[4];

if(_gCfg.isHd ==YES) {

vertices[0] =b2Vec2(0.0f,640.0f);

vertices[1] =b2Vec2(960.0f,640.0f);

vertices[2] =b2Vec2(0.0f,0.0f);

vertices[3] =b2Vec2(960.0f,0.0f);

} else {

vertices[0] =b2Vec2(0.0f,320.0f);

vertices[1] =b2Vec2(480.0f,320.0f);

vertices[2] =b2Vec2(0.0f,0.0f);

vertices[3] =b2Vec2(480.0f,0.0f);

}

ccColor4F colors[4];

colors[0] = (ccColor4F){1.0f,1.0f,0.0f,1.0f};

colors[1] = (ccColor4F){0.0f,1.0f,0.0f,1.0f};

colors[2] = (ccColor4F){0.0f,0.0f,1.0f,1.0f};

colors[3] = (ccColor4F){1.0f,0.0f,0.0f,1.0f};

//将顶点(x, y)数组和颜色(r, g, b, a)数组传给opengl

glVertexPointer(2, GL_FLOAT, 0, vertices);

glColorPointer(4, GL_FLOAT, 0, colors);

glDrawArrays(GL_TRIANGLE_STRIP,0,4);

}



// 绘制单色的背景~

-(void) drawOneColorBackground {

b2Vec2 vertices[4];

if(_gCfg.isHd ==YES) {

vertices[0]=b2Vec2(0.0f,640.0f);

vertices[1]=b2Vec2(960.0f,640.0f);

vertices[2]=b2Vec2(0.0f,0.0f);

vertices[3]=b2Vec2(960.0f,0.0f);

} else {

vertices[0]=b2Vec2(0.0f,320.0f);

vertices[1]=b2Vec2(480.0f,320.0f);

vertices[2]=b2Vec2(0.0f,0.0f);

vertices[3]=b2Vec2(480.0f,0.0f);

}

//将顶点(x, y)数组和颜色(r, g, b, a)数组传给opengl

glColor4f(0.3f, 0.3f, 0.3f, 1.0f); // 灰色

glVertexPointer(2, GL_FLOAT, 0, vertices);

glDrawArrays(GL_TRIANGLE_STRIP,0,4);

}



-(void) drawNails:(b2Vec2*)nails nailsCount:(int)nailsCount {

/**绘制之前将所有的 b2Vec2 单元放大 PTM_RATIO ~ */

b2Vec2 *handled = new b2Vec2[nailsCount];

for(int i = 0; i < nailsCount; ++ i) {

b2Vec2 item = nails[i];

handled[i].Set(item.x *_gCfg.multiplyFactor, item.y *_gCfg.multiplyFactor);

}

glPointSize(8.0f);

glColor4f(1.0f,0.0f,0.0f,1.0f);

glVertexPointer(2, GL_FLOAT, 0, handled);

glDrawArrays(GL_POINTS, 0, nailsCount);

glPointSize(1.0f);

}



-(void) drawIce:(b2World*)world {

b2Body *bodyList = world->GetBodyList();

for (b2Body* b = bodyList; b; b = b->GetNext()) {

const b2Transform& xf = b->GetTransform();

for (b2Fixture* f = b->GetFixtureList(); f; f = f->GetNext()) {

if (b->IsActive() == false) {

[selfdrawSolidPolygon:fxf:xf color:b2Color(0.5f,0.5f,0.3f)];

} else if (b->GetType() ==b2_staticBody) {

[selfdrawSolidPolygon:fxf:xf color:b2Color(0.5f,0.9f,0.5f)];

} else if (b->GetType() ==b2_kinematicBody) {

[selfdrawSolidPolygon:fxf:xf color:b2Color(0.5f,0.5f,0.9f)];

} else if (b->IsAwake() ==false) {

[selfdrawSolidPolygon:fxf:xf color:b2Color(0.6f,0.6f,0.6f)];

} else {

[selfdrawSolidPolygon:fxf:xf color:b2Color(0.9f,0.7f,0.7f)];

}

}

}

}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值