Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

BtySgtMajor

Line Drawing Algorithms

This topic is 5790 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

Hi there, I''ve been trying to use Bresenham''s line drawing algorithm in a 16-bit mode on a 640x480 screen. But when I use it, the diagonal lines have these gaping "holes" in them (a couple pixels wide at least). Needless to say, it looks like crap. Anyone have any suggestions? Sorry if this is a lame question, but I couldn''t find any decent answers elsewhere.

Share this post


Link to post
Share on other sites
Advertisement
post the crappy line plotter code you are using and maybe someone can point out what the problem(s) might be.

or email me the code to look over at orion76@hot.rr.com

I have a made a 16 bit color line plotter myself in Direct Draw 7
and it works fine



Share this post


Link to post
Share on other sites
His problem with the gaps seems to be happenning because he's using a byte pointer to plot the pixels instead of using a word pointer or casting the byte pointer to a word pointer.

I had this sort of problem myself.


[edit]
also the way the deltas are calculated

dx = x1 - x0; // if x1=0 and x1=2 then dx = 1 and not 2 pixels

should be

dx = x1 - x0 + 1; // this will calculate the range of pixels correctly

or any advice if I'm wrong will be helpful, Thanks!!

[edited by - CodeJunkie on December 8, 2002 8:26:06 PM]

Share this post


Link to post
Share on other sites
I''m not quite sure how Brensenham''s algorithim works myself, (if anyone could expalin it, that would be great) but shouldn''t the deltas be...

DeltaX = abs(EndX - StartX);
DeltaY = abs(EndY - StartY);

???

Share this post


Link to post
Share on other sites
exactly, thanks MattS423

otherwise a negative delta would cause weird side effects maybe even gaps

[EDIT]
this code would work as well
if(x1>=x0) // fixed it was wrong x1<=x0 sorry
{dx = x1 - x0 + 1;}
else
{dx = x0 - x1 + 1;}

and if the deltas aren't calculated with the right pixel ranges
the line's slope ratio will be off

Here's the heart of plotting a line:


    
ShortAccum = 0; // maintains short/long range ratio

pixels = longPixelRange;
while(pixels--) // repeat until no more pixels to plot

{
buffer[offset] = pixClr; // plot a pixel of course


offset += longPixelDistance; // move to next pixel along the long range


// Once the accumlator is equal or greater then the long range you can move towards the short distance

ShortAccum += shortPixelRange;
if(ShortAccum>=longPixelRange)
{
offset += shortPixelDistance; // move to next pixel along the short range

ShortAccum -= longPixelRange; // maintain the short/long range ratio

}
}



Well at least that's how I see it.

[edited by - CodeJunkie on December 8, 2002 9:12:21 PM]

[edited by - CodeJunkie on December 8, 2002 9:29:55 PM]

Share this post


Link to post
Share on other sites
Well Code, I tried your WORD pointer idea such that:

*(WORD*)vbStart = color; // needs (WORD*), not (WORD)

and I divided the lpitch by two.

But, I get this weird-ass behaviour...For one, the coordinates seem off. And for things like polygons, they appear to be in two "pieces" across the screen from each other (right y coords, wrong x coords). I''m going to have a look at this, but God knows what''s going on. Oh the joys of it all.

Share this post


Link to post
Share on other sites
if you cast to a word pointer then don''t divide the pitch by 2 it can remain as it is

only if you choose to use a word pointer divide pitch by 2...Okay

sorry for the confusion

Share this post


Link to post
Share on other sites
Ok, well, I guess that really isn''t the problem then. I left the casting in *(WORD*)vbstart = color; and left the lpitch alone...But the gaping holes still appear. :\ I guess it''s back to the drawing board...Gah.

Share this post


Link to post
Share on other sites

  • 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!