Cocos2d-x--Box2D使用GLES-Render.h渲染查看剛體

分爲兩部分:文件拷貝和代碼實現html

 

1.文件拷貝:ide

 

在TestCpp下找到GLES-Render.h和GLES-Render.cpp兩個文件ui

Box2D

複製到G:\cocos2d-2.1rc0-x-2.1.3\cocos2d-2.1rc0-x-2.1.3\cocos2dx\platform\win32下debug

Cocos2d

 

 

工程中也要有一份orm

Box2D

 

 

2.代碼實現:htm

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

 

建立世界的時候加上這些

io

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 方法

form

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

ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );

kmGLPushMatrix();

world->DrawDebugData();

kmGLPopMatrix();

CHECK_GL_ERROR_DEBUG();
}
相關文章
相關標籤/搜索