尝试使用cocos2d-x 3.8.1绘制三维地形

时间:2015-09-24 11:42:09

标签: c++ ios cocos2d-x

我想在cocos2d-x

中的3d视图中绘制一个实心网格

bool MeshTerrain :: init(){

if(!Node::init()){

    return false;

}

positions.push_back(-5.0f);positions.push_back(-5.0f);positions.push_back(0.0f);
positions.push_back(5.0f);positions.push_back(-5.0f);positions.push_back(0.0f);
positions.push_back(5.0f);positions.push_back(5.0f);positions.push_back(0.0f);
positions.push_back(-5.0f);positions.push_back(5.0f);positions.push_back(0.0f);

texs.push_back(0.0f);texs.push_back(0.0f);
texs.push_back(1.0f);texs.push_back(0.0f);
texs.push_back(1.0f);texs.push_back(1.0f);
texs.push_back(0.0f);texs.push_back(1.0f);

indices.push_back(0);
indices.push_back(1);
indices.push_back(2);

indices.push_back(0);
indices.push_back(2);
indices.push_back(3);


mesh = cocos2d::Mesh::create(positions, normals, texs, indices);
mesh->setTexture("texture.png");

return true;

}

void MeshTerrain :: draw(cocos2d :: Renderer * renderer,const cocos2d :: Mat4& transform,uint32_t flags){

auto programstate = mesh->getGLProgramState();
auto& meshCommand = mesh->getMeshCommand();
GLuint textureID = mesh->getTexture() ? mesh->getTexture()->getName() : 0;

meshCommand.init(_globalZOrder
      , textureID
      , programstate
      , 0
      , mesh->getVertexBuffer()
      , mesh->getIndexBuffer()
      , mesh->getPrimitiveType()
      , mesh->getIndexFormat()
      , mesh->getIndexCount()
      , transform
      ,flags);

renderer->addCommand(&meshCommand);

}

但我一直在犯同样的错误:

断言失败:GLProgramState不能是nill 断言失败:(glProgramState),函数init,文件/Users/Juggernogger93/Desktop/StormStrike/StormStrike/cocos2d/cocos/renderer/CCMeshCommand.cpp,第108行。

有没有人知道如何解决这个问题。

1 个答案:

答案 0 :(得分:1)

通过getGLProgramState(),而不是0。