• Create Account

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

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

2 replies to this topic

### #1sobeit  Members

463
Like
0Likes
Like

Posted 04 February 2013 - 01:38 PM

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.

### #2Krypt0n  Members

4529
Like
0Likes
Like

Posted 05 February 2013 - 04:15 AM

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.

### #3sobeit  Members

463
Like
0Likes
Like

Posted 07 February 2013 - 01:39 PM

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

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.