Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Problem glDrawElements using GL_LINE_LOOP...deformed result

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    7

    Problem glDrawElements using GL_LINE_LOOP...deformed result

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


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


    The code to load and render:
    Code :
    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);
    }

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Posts
    786
    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •