# Problem With DrawLine Function

• October 17th, 2012, 07:38 AM
marsh
Problem With DrawLine Function
Any advice? This is due in 3 hours so its super time important

http://pastebin.com/dxg9HyT9

Even if you spot a problem with the math or have some advice please help. Been working on this all night. It almost works, just a few lines out of place.
• October 17th, 2012, 07:40 AM
VictorN
Re: Problem With DrawLine Function
• October 17th, 2012, 07:47 AM
marsh
Re: Problem With DrawLine Function

Either way, sorry about that. I am trying to draw a line. My point.draw function places a pixel on the screen. This function is reading two points and drawing every point in between them. It almost works but certain specific angles do not draw correctly. I am guessing there is something wrong with the math. If Anyone who has done something like this before i would greatly appreciate the help.
• October 17th, 2012, 07:51 AM
VictorN
Re: Problem With DrawLine Function
perhaps, you will show us your code that "almost works but certain specific angles do not draw correctly"?
• October 17th, 2012, 08:05 AM
marsh
Re: Problem With DrawLine Function
The problem is i am not sure of the exact angle that does not work. So i cant show a single line. Here is my fill function.
http://www.freemmorpgmaker.com/files...3afbe7f552.png

You notice the dotted lines that appear. It may be a problem with my fill function though i had a similar problem with my lines earlier so i am pretty certain this is the issue. Any help would be great. Thanks.
• October 17th, 2012, 08:10 AM
VictorN
Re: Problem With DrawLine Function
Quote:

Originally Posted by marsh
Here is my fill function.

Where? :confused:
• October 17th, 2012, 08:13 AM
marsh
Re: Problem With DrawLine Function
I didnt post it, becouse i dont believe the problem is there. Also then i would need to include a lot of other classes etc. The actual project is huge.

If this is not enough information to solve the problem i understand.
• October 17th, 2012, 08:46 AM
Eri523
Re: Problem With DrawLine Function
Quote:

Originally Posted by marsh
If Anyone who has done something like this before i would greatly appreciate the help.

I haven't ever done that myself (at least not successfully... :rolleyes:), but eventually there never has been a real need to do it anyway, and I'm quite happy about it... :)

At any rate, and since you neither posted code nor the problematic angles are really clear from your screen shot, perhaps the commonly used Bresenham line algorithm is helpful for you, either as a reference to spot what's wrong with your function, or as a basis to re-implement your function from scratch.
• October 17th, 2012, 10:08 AM
Peter_B
Re: Problem With DrawLine Function
Looking at the image you provided, it is clear that the way you are drawing the filled triangles is by drawing a lot of lines radiating from one of the triangle corners. This is not a good way to draw filled triangles for the following reasons:

1) If you don't draw enough lines you get missing pixels - as you are seeing
2) Pixels near the corner you are drawing from are overwritten (drawn more than once) - this is inefficient.

So it is your fill algorithm which is wrong.

To draw filled triangles you should use a scan-line fill algorithm, such as that shown here (http://www-users.mat.uni.torun.pl/~w...i_fillers.html). NB: I just found that on a quick google - I can't vouch for it's correctness.
• October 17th, 2012, 10:52 AM
marsh
Re: Problem With DrawLine Function
Quote:

Originally Posted by Peter_B
Looking at the image you provided, it is clear that the way you are drawing the filled triangles is by drawing a lot of lines radiating from one of the triangle corners. This is not a good way to draw filled triangles for the following reasons:

1) If you don't draw enough lines you get missing pixels - as you are seeing
2) Pixels near the corner you are drawing from are overwritten (drawn more than once) - this is inefficient.

So it is your fill algorithm which is wrong.

To draw filled triangles you should use a scan-line fill algorithm, such as that shown here (http://www-users.mat.uni.torun.pl/~w...i_fillers.html). NB: I just found that on a quick google - I can't vouch for it's correctness.

Ah, thanks. I will check out that link. Sorry for my ignorance.