Page 1 of 1
Line drawing
Posted: Sat Aug 06, 2005 12:41 pm
by areo
Hello,
I need to draw line.
My putpixel function is
void pixel(unsigned long colour, unsigned short posX, unsigned short posY) {
video[posY * 1024 + posX] = colour;
}
Please help. If you can then write source code.
Re:Line drawing
Posted: Sat Aug 06, 2005 12:53 pm
by Dex4u
I am not in to C myself, but here is some code that may help, its for the xbox.
http://www.xbdev.net/non_xdk/openxdk/drawline/index.php
Re:Line drawing
Posted: Sat Aug 06, 2005 2:00 pm
by codemastersnake
Check out the attached file.... I created it for VGA graphics programming....
Re:Line drawing
Posted: Sat Aug 06, 2005 2:49 pm
by distantvoices
@areo: pls refrain from source code requests. State what your problem is or what doesn't work. We are not your coding slaves.
Stay safe.
Re:Line drawing
Posted: Sat Aug 06, 2005 3:39 pm
by Tora OS
Here's some code i quickly wrote for a horizontal line. To make it do vertical lines reverse the axis in the code.
Code: Select all
//Draw Horizontal Line:
void h_line(int Yval, int start_Xval, int width, char color)
{
int END_Xval = start_Xval + width; /*set our ending pixel as WIDTH+STARTING PIXEL */
while (start_Xval <= END_XVal) /*while the current pixel is less than or equal to the ending X value */
{
pixel(color, Xval, start_Yval); //draw the pixel
start_Xval++; //increase our current X pixel by one.
}
return; //done
}
Re:Line drawing
Posted: Sun Aug 07, 2005 2:27 am
by Cjmovie
Goto gamedev.net, look under articles->Programming->graphics
Then look for an article on Breseham Line algoritham (I think that's it...)
Re:Line drawing
Posted: Sun Aug 07, 2005 9:56 pm
by Rainer
if this doesnt help you, then I dont know what will:
http://en.wikipedia.org/wiki/Bresenham%27s_algorithm
Re:Line drawing
Posted: Tue Aug 09, 2005 3:12 pm
by NotTheCHEAT
@areo: pls refrain from source code requests. State what your problem is or what doesn't work. We are not your coding slaves.
Was he specifically requesting source code, or was he asking if anyone knew how? There's nothing wrong with saying "Can someone please tell me how to draw a line using xxx pixel-drawing function?" What isn't OK would be to say "Give me some source code for drawing a line using xxx pixel-drawing function!!!"
Remember to be nice
And yes, you want the Bresenham algorithm. Basically, since every line is the set of solutions to a linear equation, it figures out what those solutions are and plots them. I don't remember exactly what it does, but that's how it works. It's fast, easy to implement and understand, etc.
There is also a Bresenham circle algorithm, and others (I think).
Re:Line drawing
Posted: Tue Aug 09, 2005 5:55 pm
by mystran
Bresenham circle is indeed another popular algorithm.
Anyway, the basic idea of drawing a line is looping over one coordinate, and solving the the line equation (or using linear interpolation) to get the other coordinate. The only complication is deciding which coordinate to loop so that you don't end up with holes.
But yeah Bresenham is a good algorithm.
Re:Line drawing
Posted: Wed Aug 10, 2005 4:00 pm
by Cjmovie
Yay, I was right ;D!