尝试使用cocos2d-x 3.8.1绘制3d地形

Trying to draw 3d terrain using cocos2d-x 3.8.1

本文关键字:绘制 3d 地形 cocos2d-x      更新时间:2023-10-16

我正在尝试在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);

}

但是我一直得到相同的错误:

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

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

通过getGLProgramState(),不是0。