Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 1 of 1

Thread: Problem regarding line drawing

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2016

    Smile Problem regarding line drawing

    Hello I have been struggling lately to overcome some difficulties regarding drawing lines. My final goal is to use lines to represent edges of a skeleton. Since I will later use the following class on a 3d mesh I thought I would use indexed drawing.

    With that in mind I tried to draw one line using the following code to draw a simple line segment to start with:

    Code :
    class LineDrawer {
      std::vector<glm::vec3> m_vertices{glm::vec3(0, 0, 0), glm::vec3(0.5, 0.5, 0)};
      std::vector<uint> m_indices{0, 1};
      uint VAO, VBO, EBO;
      void Draw(Shader *skeletonShader, Shader *shader) {
        glDrawElements(GL_LINES, m_indices.size(), GL_UNSIGNED_INT, 0);
      void initializeDrawingBuffers() {  
        glGenVertexArrays(1, &VAO);
        glGenBuffers(1, &VBO);
        glGenBuffers(1, &EBO);
        glBindBuffer(GL_ARRAY_BUFFER, VBO);
        glBufferData(GL_ARRAY_BUFFER, m_vertices.size() * sizeof(glm::vec3),
                     &m_vertices[0], GL_STATIC_DRAW);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_indices.size() * sizeof(GLuint),
                     &m_indices[0], GL_STATIC_DRAW);
        glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, (GLvoid *)0);

    The vertex shader
    Code :
    #version 330 core
    layout (location = 0) in vec3 position;
    void main()
        gl_Position = vec4(position, 1.0f);

    The fragment shader

    Code :
    #version 330 core
    out vec4 color;
    void main()
            color = vec4(0.0f,1.0f,0.0f, 1.0f);

    Using m_vertices{glm::vec3(0, 0, 0), glm::vec3(0.5, 0.5, 0)} i expect to get a line segment starting in the center of the screen and ending in the center of the top right part of the screen. Instead I get A line segment on the x axis as if I had used m_vertices{glm::vec3(0, 0, 0), glm::vec3(0.2, 0, 0)}; check this picture: Click image for larger version. 

Name:	screenshotLineSegment.jpg 
Views:	6 
Size:	5.9 KB 
ID:	2522. The shader ignores the coordinates in the y and z axis and I am seeking for an answer for why this is happening..

    Is my initializeDrawingBuffers() function correct or do you see anything odd in my code?
    Last edited by qqtolene; 10-19-2017 at 07:06 AM.

Posting Permissions

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