Line drawing
Line drawing
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.
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
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
Check out the attached file.... I created it for VGA graphics programming....
-
- Member
- Posts: 1600
- Joined: Wed Oct 18, 2006 11:59 am
- Location: Vienna/Austria
- Contact:
Re:Line drawing
@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.
Stay safe.
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
BlueillusionOS iso image
Re:Line drawing
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
Goto gamedev.net, look under articles->Programming->graphics
Then look for an article on Breseham Line algoritham (I think that's it...)
Then look for an article on Breseham Line algoritham (I think that's it...)
Re:Line drawing
if this doesnt help you, then I dont know what will:
http://en.wikipedia.org/wiki/Bresenham%27s_algorithm
http://en.wikipedia.org/wiki/Bresenham%27s_algorithm
Re:Line drawing
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!!!"@areo: pls refrain from source code requests. State what your problem is or what doesn't work. We are not your coding slaves.
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
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.
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.