Jump to content
  • Advertisement
Sign in to follow this  
sobeit

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.

If you intended to correct an error in the post then please contact us.

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. 

 

Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement

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.

 

for proper shading, you can

-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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!