Problem glDrawElements using GL_LINE_LOOP...deformed result

Started by
0 comments, last by RobTheBloke 11 years ago

Hi!
I try to render a mesh with GL_LINE_LOOP, but the result is deform:

problempng.png

This image show the vertex of the mesh and the indices:

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);
}

Advertisement


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");
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glDrawElements(GL_QUADS, indices.size(), GL_UNSIGNED_INT, (GLvoid*)0);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
ExitOnGLError("ERROR: No se puede dibujar el meshpart");

glBindVertexArray(0);
}

It look like you are expecting 6 line loops with 4 verts each, whereas you've actually specified a line loop of 24 verts. Rendering the buffers as wireframe quads is a quick work around.

This topic is closed to new replies.

Advertisement