0

I need to draw graph. I have to arrays of vertex attributes: array of x coordinates: xPos array of y coordinates: yPos

But X doesn't match Y.

I need to create separate arrays of indices and link them to the corresponding arrays of coordinates.

What i need

glEnableVertexAttribArray(opglp->xPositionLocation);
glBindBuffer(GL_ARRAY_BUFFER, opglp->vbo1);
glVertexAttribPointer(opglp->xPositionLocation, 1, GL_FLOAT, GL_FALSE, 0 , 0 );
        
glEnableVertexAttribArray(opglp->yPositionLocation);
glBindBuffer(GL_ARRAY_BUFFER, opglp->vbo2);
glVertexAttribPointer(opglp->yPositionLocation, 1, GL_FLOAT, GL_FALSE, 0 , 0 );
    
glDrawElements(GL_LINE_STRIP, 5, GL_UNSIGNED_SHORT, NULL);

Vertex shader:

attribute float xPosition;
attribute float yPosition;

uniform mat4 projection;
uniform mat4 modelView;

void main()
{
    vec4 pos;
    pos = vec4(xPosition, yPosition, 0.0,  1.0);
    
    gl_Position = projection * modelView * pos;
}
genpfault
  • 51,148
  • 11
  • 85
  • 139
  • 2
    Sorry, but the question is completely unclear to me. Possibly related: [Rendering meshes with multiple indices](https://stackoverflow.com/questions/11148567/rendering-meshes-with-multiple-indices) and [Why does OpenGL not support multiple index buffering?](https://stackoverflow.com/questions/44046585/why-does-opengl-not-support-multiple-index-buffering) . – Rabbid76 Jun 20 '21 at 12:07
  • Look at image, i dont know what i can add to it... – kotvkvante Jun 20 '21 at 12:42
  • 1
    Do you just mean the x coords are out-of-order? If so, why can't you re-order them accordingly? – G.M. Jun 20 '21 at 12:58
  • Because it is dynamically updated and there are a lot of points – kotvkvante Jun 20 '21 at 13:17
  • 1
    Within the limits of GLES2, there is not much you can do besides correctly ordering the x/y pairs on CPU - at least in the general case. However, you image actually doesn't look like the general case, just like 2 ring buffers wwhich our somewhat out of sync. If that is not just a random artifact in the example you gave, you can easily split this into two draw calls with appropriatly offsetted vertex attribute pointers (you might need to actually slpit it up into 3 draw calls if yhe slpit is not as symmetric as in your example, but still the principle is the same). – derhass Jun 20 '21 at 15:38
  • Does this answer your question? [Rendering meshes with multiple indices](https://stackoverflow.com/questions/11148567/rendering-meshes-with-multiple-indices) – Rabbid76 Jun 23 '21 at 18:08

0 Answers0