0

The line is automatically painted in the color of the vertices

I tried to paint each line separately from vertices but it didn't work.

void draw()
{
    glDrawArrays(GL_POINTS, 0, vertecies.size());
    glDrawElements(GL_LINES, lines.indecies.size(), GL_UNSIGNED_INT, nullptr);
}


void buffer_init()
{
    glGenBuffers(1, &vertex_bufffer);
    glBindBuffer(GL_ARRAY_BUFFER, vertex_bufffer);
    glBufferData(GL_ARRAY_BUFFER, MAX_VERTEX_COUNT * sizeof(gl_vertex2d), &vertecies[0], GL_DYNAMIC_DRAW);
    glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(gl_vertex2d), 0);
    glEnableVertexAttribArray(0);

    //colors
    glGenBuffers(1, &vertex_color_buffer);
    glBindBuffer(GL_ARRAY_BUFFER, vertex_color_buffer);
    glBufferData(GL_ARRAY_BUFFER, MAX_VERTEX_COUNT * sizeof(gl_vertex2d), &vertecies[0], GL_DYNAMIC_DRAW);
    glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(gl_vertex2d), (GLvoid*)8);
    glEnableVertexAttribArray(1);


    glGenBuffers(1, &lines_buffer);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, lines_buffer);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, MAX_LINES_COUNT * sizeof(gl_lines2d), &lines.indecies[0], GL_DYNAMIC_DRAW);

    //that's how i'm trying to color lines
    glGenBuffers(1, &lines_color_buffer);
    glBindBuffer(GL_ARRAY_BUFFER, lines_color_buffer);
    glBufferData(GL_ARRAY_BUFFER, MAX_LINES_COUNT * sizeof(gl_lines2d), &lines.colors[0], GL_DYNAMIC_DRAW);
}

But the last 3 lines of code doesn't really change anything: picture stays the same.

I'm using the following vertex and fragments shaders:

#FRAGMENT
#version 330 core

in vec4 vColor;
out vec4 fColor; 

void main()
{
    fColor = vColor;
}

#VERTEX
#version 330 core

layout(location = 0) in vec4 position;
layout(location = 1) in vec4 color;
out vec4 vColor;

void main()
{
    gl_Position = position;
    vColor = color;
}
BDL
  • 21,052
  • 22
  • 49
  • 55
  • What does it mean: *"How do i separate line color from vertex color?"*? Do you mean that you want one color attribute per primitive rather than per vertex? That is not possible, see [OpenGL: Vertex attribute arrays per primitive?](https://stackoverflow.com/questions/11351537/opengl-vertex-attribute-arrays-per-primitive) – Rabbid76 Jul 17 '19 at 20:50
  • 3
    Or possibly use the [`flat` qualifier](https://www.khronos.org/opengl/wiki/Type_Qualifier_(GLSL)#Fragment_shader_outputs) for the color attribute in the fragment shader. – Nico Schertler Jul 17 '19 at 22:01
  • @Rabbid76 yea, this is exactly what i want – Илья Забыл.оО Jul 18 '19 at 06:02
  • @NicoSchertler big thanks for advice – Илья Забыл.оО Jul 18 '19 at 06:03

0 Answers0