How to make the line color flat instead of gradient in OpengGL ES 2.0?

289 views Asked by At

I'm working with OpengGL ES 2.0 in android. I'm given with these vertices which I used to draw shapes by connecting them with lines. Now I need to change color of each of these lines individually. I tried passing a color matrix for each vertex through vertex shader to fragment shader but the color gets interpolated (which actually makes sense, since I'm giving different color to two vertices). I did some googling about that and found out glSmoothShader cannot be disabled in OpengGL ES.

Is there a way to color those lines without the colors getting interpolated?

Or is there a way to use multiple triangles to draw a line between two vertices that way i can flat color each of those triangles.

1

There are 1 answers

1
Eugene Styer On

One solution is to duplicate your vertices. That is, if you currently have a vertex V connected to three lines (as an example), then create three vertices V1, V2, and V3 with the same location but different colors, where each vertex has the color of the corresponding line. So if line 1 is red, line 2 is blue, and line 3 is green, then V1 will be red, V2 blue, and V3 green.