Jump to content

  • Log In with Google      Sign In   
  • Create Account


Problem glDrawElements using GL_LINE_LOOP...deformed result


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 ShotoReaper   Members   -  Reputation: 149

Like
0Likes
Like

Posted 17 March 2013 - 06:45 AM

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

 

 



Sponsor:

#2 RobTheBloke   Crossbones+   -  Reputation: 2295

Like
0Likes
Like

Posted 22 March 2013 - 06:22 AM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS