I create a .obj loader that reads from a mesh file that was created in blender 2.66 and loads the data into a std::vector that is passed to Opengl as a VBO. None of the vertices in the mesh file have a position of (0,0,0). So what could be a possible reason that the mesh is getting that extra vertex in the center? As the original mesh is just a triangulated plane with only four vertices.
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