現時点での問題は、3D オブジェクトが部分的にしかレンダリングされないことです。両端が「満たされている」典型的な円柱がある場合、端は完全にレンダリングされますが、円柱自体はそうではありません。説明する例を添付しました。
コードの作成方法は次のとおりです。
struct ObjMeshVertex{
Vector3f pos;
Vector2f texcoord;
Vector3f normal;
};
struct ObjMeshFace{
ObjMeshVertex vertices[3];
};
struct ObjMesh{
std::vector<ObjMeshFace> faces;
};
ObjMesh myMesh;
for(size_t i = 0; i < faces.size(); ++i){
ObjMeshFace face;
for(size_t j = 0; j < 3; ++j){
face.vertices[j].pos = positions[faces[i].pos_index[j] - 1];
face.vertices[j].texcoord = texcoords[faces[i].tex_index[j] - 1];
face.vertices[j].normal = normals[faces[i].nor_index[j] - 1];
}
myMesh.faces.push_back(face);
}
設定:
glGenVertexArraysOES(1, &_boxVAO);
glBindVertexArrayOES(_boxVAO);
int sizeOfFaces = myMesh.faces.size() * sizeof(ObjMeshFace);
glGenBuffers(1, &_boxBuffer);
glBindBuffer(GL_ARRAY_BUFFER, _boxBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeOfFaces, &(myMesh.faces[0]), GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(ObjMeshVertex), 0);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(ObjMeshVertex), (void*)offsetof(ObjMeshVertex, texcoord));
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE ,sizeof(ObjMeshVertex), (void*)offsetof(ObjMeshVertex, normal));
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glBindVertexArrayOES(0);
描く:
glBindVertexArrayOES(_boxVAO);
glDrawArrays(GL_TRIANGLES, 0, indicesize);
どこ indexsize = myMesh.faces.size()
したがって、私のオブジェクトは次のようになります。
レンダリングは次のようになります。
そして、複数ではなく1つのオブジェクトのみをレンダリングしているため、この動作には少し奇妙に思えます。
球を並べて表示:
最新のレンダリング: