W
W
w0lkolak2021-08-22 11:39:27
OpenGL
w0lkolak, 2021-08-22 11:39:27

How to draw a multi-colored polyline in OpenGL without a gradient?

In PyQt in QOpenGLWidget I draw a scene using OpenGL. It has a multi-colored trajectory. Some of the segments in the trajectory are yellow, some are green. 61220b2c52a0b689311122.png
I do not need a gradual color transition, I need an instant color change for areas with different parameters.

for i in np_list:
            if new != old:
                if new == 0:
                    glColor3f(*OpenGL_color_1)
                else:
                    glColor3f(*OpenGL_color_2)
                old = new
            glVertex3f(i[4], i[5], i[6])

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Shatunov, 2021-08-22
@w0lkolak

And the answer will be very simple.
At the color change point, you need to put two vertices. The first vertex is to finish the line of the previous color, and the second one is to start the line of the next color.
It won't affect performance in any way.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question