Implementing rectangle using gl_triangle_strip
-
I am trying to implement a rectangle (bar) for every data point using opengl gl_triangle_strip.
the problem i am facing is after the first four points, a new triangle is getting drawn with every new point.
How do i solve this issue?Please help.
-
Main reason why I am using triangle_strip is that it should be filled.
-
Hi and welcome to devnet,
That's rather on OpenGL than a Qt question. You should check the OpenGL forums for that one.
But basically, that's how triangle strip is working. Each points lead to a new triangle.
What technique are you currently using to build your rectangle ?
-
@SGaist Hi and thanks for your immediate response.
I have an incoming set of points. And i need to draw bars for each of them.
With a single point i am creating 4 points around it, giving it some width and height.
As i mentioned earlier, i want filled rectangles. so i was suggested to use triangle strips.but that has a drawback which i mentioned above. so looking for a solution.
my very little knowledge on opengl is adding to the agony. -
If you generate vertices for each point then you have a couple of options:
- create two triangles (6 vertices) and use triangles instead of triangle strips
- create 4 vertices for each point and do draw call for each two triangles as a separate triangle strip
- create 4 vertices for each point and insert two dummy vertices between each group. First dummy should have the same coords as last vertex in the previous group and second should have coords of the first vertex in following group. The duplicated vertices will produce a degenerate triangles that GPU will skip over.
-
@Chris-Kawa What about VAO + VBO ? Wouldn't it be simpler ?
-
@SGaist VBO is just a way of storing data (an array basically). What I was talking about can (and should) of course use that but the question is how do you actually interpret (draw) the data from the VBO, ie. how the data is organized (buffer layout) and what draw call to use (i.g. GL_TRIANGLES or GL_TRIANGLE_STRIP as the mode param in the glDrawArrays/Elements call). Storage and rendering are kinda orthogonal topics.
-
Good point, I've read your post with glBegin and glEnd in mind.