# OpenGL how to interpolate color of an line drew using midpoint algorithm

This topic is 2077 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm currently trying to implement a graphics pipeline on software level. Now I have implemented the midpoint algorithm to draw a line, but how should I interpolate color of pixels between two end points. I mean, I know the linear interpolation, but my problem is that the (x, y) coordinate of a pixel generated via midpoint algorithm is not accurately lying on the actual line defined by two end points. And I want to know how OpenGL deal with it.

##### Share on other sites

I think OpenGL is not using a midpoint interpolation, as it's probably simpler to just draw two triangles to have a line and lines being a rare case, it's probably 'good enough', which is maybe why it's also not that fast to draw lines, while you'd expect it to be simpler than drawing triangles.

you could check MesaGL, a software implementation for the Opengl API to see how they do it, but it might not be what the HW does.

-divide the gradient by the count of steps you gonna take, the count of steps is the metropolitan distance, deltax+deltay, and add it on every step. not fully accurate, but you probably won't notice a difference and it's fast

-baricentrical distance: calculate the the distances at every (x,y) to both ends, weight the colors by those distances, divided by their sum

-if you make a dot product of the (x,y) with the direction vector of the line and divide by the length of the direction vector, no matter what width your line will have (so even if it's wider than long), you'll draw a gradient that always progresses from one end to the other.

##### Share on other sites

Thank you for the information, I'll check mesaGL later.

1. 1
2. 2
Rutin
22
3. 3
4. 4
5. 5

• 16
• 14
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
632928
• Total Posts
3009262
• ### Who's Online (See full list)

There are no registered users currently online

×