Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

how to interpolate color of an line drew using midpoint algorithm

4: Adsense

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.


  • You cannot reply to this topic
2 replies to this topic

#1 sobeit   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. 

 

Thanks in advance.



#2 Krypt0n   Members   

4692
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.

 

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.



#3 sobeit   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.