Tuesday, June 6, 2017

c++ - How do you draw a straight line between two points in a bitmap?


I'm playing around with height maps (bitmaps), trying to create some of my own in my game, and for that I need to implement some basic drawing methods. I've quickly realized that drawing straight lines isn't as basic as I thought.


It simple's if your points share an X or Y coordinate, or if they are aligned so you can draw a perfectly diagonal line. But in all other cases its trickier.



What algorithm do you use to determine what pixels need to be coloured for it to become a "straight" line ?



Answer



I think what you need is Bresenham's line algorithm.


From what I remember it is used to determine what point should be coloured, not how much each point should be coloured.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...