PDA

View Full Version : Problem glDrawElements using GL_LINE_LOOP...deformed result



shotoreaper
03-13-2013, 05:28 PM
Hi!
I try to render a mesh with GL_LINE_LOOP, but the result is deform:
http://img13.imageshack.us/img13/6084/problempng.png

This image show the vertex of the mesh and the indices:
http://img836.imageshack.us/img836/9265/verticesandindices.png

The code to load and render:

void PhysicObject::Load(void)
{
glGenVertexArrays(1, &BufferIds[0]);

ExitOnGLError("ERROR: No se puede generar el VAO");
glBindVertexArray(BufferIds[0]);
ExitOnGLError("ERROR: No se puede bindear el VAO");

// Activamos dos vertex attribute locations
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
ExitOnGLError("ERROR: No se puede activar los vertex attributes");

// Creamos los VBO
glGenBuffers(2, &BufferIds[1]);
ExitOnGLError("ERROR: No se pueden generar los buffer objects");

// Bindeamos el VBO al VAO
glBindBuffer(GL_ARRAY_BUFFER, BufferIds[1]);
glBufferData(GL_ARRAY_BUFFER, vertices.size()*sizeof(VertexTextureNormal), &vertices[0], GL_STATIC_DRAW);
ExitOnGLError("ERROR: No se puede bindear el VBO al VAO");

glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(vertices[0]) ,0);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(vertices[0]) , (GLvoid*) sizeof(vertices[0].position));
ExitOnGLError("ERROR: Could not set VAO attributes");

// Creamos el IBO
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferIds[2]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(GLuint), &indices.front(), GL_STATIC_DRAW);
ExitOnGLError("ERROR: No se puede bindear el IBO al VAO");

glBindVertexArray(0);
}
void PhysicObject::Draw()
{
std::cout<<c<<std::endl;
// Create the ModelMatrix
glm::mat4 ModelMatrix = glm::translate(
glm::mat4(1.0f),
getPosition()
);
colormat->Prepare3dDraw(ModelMatrix);
glBindVertexArray(BufferIds[0]);
ExitOnGLError("ERROR: No se puede bindear el VAO para dibujar");

glDrawElements(GL_LINE_LOOP, indices.size(), GL_UNSIGNED_INT, (GLvoid*)0);
ExitOnGLError("ERROR: No se puede dibujar el meshpart");

glBindVertexArray(0);
}

carsten neumann
03-14-2013, 12:52 PM
The primitive type (GL_TRIANGLES, GL_LINE_LOOP, etc.) and the order of indices are not independent; if you change the primitive type, indices may need to be adjusted. I'm guessing your indices were originally for GL_QUADS and the lines through the middle of the box are from the end of one quad to the start of the next.