내가 믹서기 2.66에서 만든 메쉬 파일에서 읽고 표준에 데이터를로드하는 .OBJ 로더를 만들 .OBJ 로더에 메쉬에 여분의 정점을 추가 : 벡터를 그 OpenGL은 VBO로 전달됩니다. 메쉬 파일의 어떤 정점도 (0,0,0)의 위치를 갖지 않습니다. 그러면 메쉬가 센터에서 여분의 버텍스를 얻는 이유는 무엇입니까? 원래 메쉬는 정점이 4 개인 삼각형 평면입니다.
struct Vertex
{
//Position
GLfloat m_X;
GLfloat m_Y;
GLfloat m_Z;
//Normal
GLfloat m_NX;
GLfloat m_NY;
GLfloat m_NZ;
//TexCoords
GLfloat m_U;
GLfloat m_V;
};
void Mesh::loadMesh(std::string Filename)
{
...
const unsigned int PositionAttribute = 0;
const unsigned int NormalAttribute = 1;
const unsigned int TexCoordAttribute = 2;
//Create a new VBO and use the variable id to store the VBO id
glGenBuffers(1, &MeshVBO);
//make the new VBO active
glBindBuffer(GL_ARRAY_BUFFER, MeshVBO);
//Pass the Mesh's vertex data into the VBO to be transferred to super fast Video RAM
glBufferData(GL_ARRAY_BUFFER, m_Vertices.size() * sizeof(Vertex), &m_Vertices[0], GL_STATIC_DRAW);
glEnableVertexAttribArray(PositionAttribute);
glEnableVertexAttribArray(NormalAttribute);
glEnableVertexAttribArray(TexCoordAttribute);
//specifies the location and data of an array of vertex
glVertexAttribPointer(PositionAttribute, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)0);
glVertexAttribPointer(NormalAttribute, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)(sizeof(GLfloat) * 3)); //12 byte offset
glVertexAttribPointer(TexCoordAttribute, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)(sizeof(GLfloat) * 6)); //24 byte offset
//make the new VBO active
glBindBuffer(GL_ARRAY_BUFFER, MeshVBO);
glGenBuffers(1, &MeshIBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, MeshIBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, (sizeof(GLushort) * m_IndexList.size()), &m_IndexList[0], GL_STATIC_DRAW);
//Cleanup
delete[] m_VertexArray;
delete[] m_Indices;
m_VertexArray = NULL;
m_Indices = NULL;
return Success;
}
void Mesh::drawMesh()
{
glDrawElements(GL_POINTS, (GLsizei)m_IndexList.size() + 1, GL_UNSIGNED_SHORT, 0);
}
Plane.obj
# Blender v2.66 (sub 1) OBJ File: ''
# www.blender.org
mtllib plane.mtl
o Plane
v 0.622129 -0.622129 0.000000
v -0.622129 -0.622129 0.000000
v 0.622129 0.622129 -0.000000
v -0.622129 0.622129 -0.000000
vn 1.000000 0.000000 0.000000
usemtl None
s off
f 2//1 1//1 3//1
f 4//1 2//1 3//1
아마도'glDrawElements()'의 두 번째 인수에서'+ 1 '입니다. 당신이 가진 것보다 한 가지 더 많은 포인트를 명시 적으로 렌더링하는 것 같습니다. –
생성 된 메쉬 파일을 게시 할 수 있습니까? 네 개 이상의 꼭지점이 지정되면 문제가 어디서 발생하는지 확인할 수 있습니다. @Reto Koradi에 동의하지만 +1 – Daniel
@ Retekoradi gldrawelements()에서 "+1"을 제거하면 메쉬에서 오른쪽 아래 정점이 제거됩니다. 내 벡터가 어떻게 든 지표를 적절하게 전달하지 않을 가능성이 있습니까? 디버그에서 검사 된 색인은 파일의 색인과 일치합니다. –