Cocos2d-x--Box2D使用GLES-Render.h渲染查看刚体

分为两部分:文件拷贝和代码实现

 

1.文件拷贝:

 

在TestCpp下找到GLES-Render.h和GLES-Render.cpp两个文件

复制到G:\cocos2d-2.1rc0-x-2.1.3\cocos2d-2.1rc0-x-2.1.3\cocos2dx\platform\win32下

 

 

工程中也要有一份

 

 

2.代码实现:

添加引用:#include <GLES-Render.h>

 

创建世界的时候加上这些

GLESDebugDraw * _debugDraw = new GLESDebugDraw(PTM_RATIO);
world->SetDebugDraw(_debugDraw);
        uint32 flags = 0;
        flags += b2Draw::e_shapeBit;
        flags += b2Draw::e_jointBit;
        flags += b2Draw::e_aabbBit;
        flags += b2Draw::e_pairBit;
        flags += b2Draw::e_centerOfMassBit;
        _debugDraw->SetFlags(flags);


 

添加或者修改 draw 方法

void HelloWorld::draw()
{
    CCLayer::draw();

    ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );

    kmGLPushMatrix();

    world->DrawDebugData();

    kmGLPopMatrix();

    CHECK_GL_ERROR_DEBUG();
}



 

 

posted @ 2013-06-29 21:50  坚固66  阅读(293)  评论(0编辑  收藏  举报