<p>I have a pretty basic widget rendering, largely based upon the learnopengl.com &quot;hello triangle.&quot; I'm actually using a tristrip to create two triangles, forming a semi-opaque square over the top of the other stuff in my window. In this square, I'm using the fragment shader to set the semi-opaque background color and an arrow that points in the direction of flight. What I want to do next is render a <code>GL_LINES</code> vertex buffer that contains the historical position of the aircraft.</p>
<p>It seems easy enough to set up a second vertex attribute object and vertex buffer, but what is unclear to me is whether it's possible to use a single vertex &amp; fragment shader pair to handle this second dataset. It wouldn't be terribly difficult to set up a group of widgets to render the opaque square, then the historical course information, then the arrow, but I already have the first and third stages working.... and breaking everything up would mean 3 vertex and 3 fragment shaders.</p>
<p>I'm guessing that it's impossible to deal with the semi-opaque background, the historic course, and the arrow all in one vertex/fragment shader pair, but it'd be obtuse to just make that assumption and make a mess out of some tolerably organized code before I got an informed answer.</p>

CC BY-SA 4.0
2020-12-12T18:06:03.303Z
Actually trying to do these "all in one" shader while doable could be very difficult using three different shaders, like you said, is much cleaner, and easier to understand. Setting up a shader to render GL_LINES is a hardware setting that can't be flipped on and off in the middle of shader. The same with turning on alpha blending.  So to render "lines" would require rendering degenerate triangles or some other "hack", its just better to stick with the 3 shaders, especially if you are still learning opengl.
pmw1234
CC BY-SA 4.0
2020-12-14T22:01:28.490Z
Thanks for the confirmation. I did eventually go that route and, once the initial pain was past, it really did reduce down to a neat, clean implementation. Maybe I"ve spent too much time in shadertoy, and thought I could do the whole thing in one fragment shader. Simple newbie shortsightedness. =]
Sniggerfardimungus
<shader><fragment-shader><vertex-buffer-object>
Rendering different array types in the same vertex/fragment shader?
Sniggerfardimungus
# Rendering different array types in the same vertex/fragment shader?

(Asked by: username_0 on 2020-12-09)

I have a pretty basic widget rendering, largely based upon the learnopengl.com "hello triangle." I'm actually using a tristrip to create two triangles, forming a semi-opaque square over the top of the other stuff in my window. In this square, I'm using the fragment shader to set the semi-opaque background color and an arrow that points in the direction of flight. What I want to do next is render a `GL_LINES` vertex buffer that contains the historical position of the aircraft.

It seems easy enough to set up a second vertex attribute object and vertex buffer, but what is unclear to me is whether it's possible to use a single vertex & fragment shader pair to handle this second dataset. It wouldn't be terribly difficult to set up a group of widgets to render the opaque square, then the historical course information, then the arrow, but I already have the first and third stages working.... and breaking everything up would mean 3 vertex and 3 fragment shaders.

I'm guessing that it's impossible to deal with the semi-opaque background, the historic course, and the arrow all in one vertex/fragment shader pair, but it'd be obtuse to just make that assumption and make a mess out of some tolerably organized code before I got an informed answer.

**Tags:** shader, fragment-shader, vertex-buffer-object

> **Comments:**
> **username_1**: Actually trying to do these "all in one" shader while doable could be very difficult using three different shaders, like you said, is much cleaner, and easier to understand. Setting up a shader to render GL_LINES is a hardware setting that can't be flipped on and off in the middle of shader. The same with turning on alpha blending.  So to render "lines" would require rendering degenerate triangles or some other "hack", its just better to stick with the 3 shaders, especially if you are still learning opengl.  
> **username_0**: Thanks for the confirmation. I did eventually go that route and, once the initial pain was past, it really did reduce down to a neat, clean implementation. Maybe I"ve spent too much time in shadertoy, and thought I could do the whole thing in one fragment shader. Simple newbie shortsightedness. =]  

---

## 0 answers

