cyclopentane

09-30-2003, 03:58 PM

So I have to create lines using glDrawPixels and the mouse. I can easily record every click of the mouse to get a starting point and an ending point for my line. Using these two points I use either DDA or Bresenham line algorithm. Here is the Bresenham algo:

void draw_line (int x0, int y0, int x1, int y1) {

int x, y = y0;

int dx = 2*(x1 - x0), dy = 2*(y1 - y0);

int dydx = dy - dx, F = dy - dx/2;

for (x = x0; x <= x1; x++) {

draw_pixel (x, y);

if (F < 0) F+= dy;

else {y++; F+= dydx;}

}

}

This algorith is supposed to give me a line. However I do not know what draw_pixel is. Do I create an array and store values in it then use that array in glDrawPixel, or what do I do from here?

If I do need an array, then how do I implement that? Plus with glDrawPixel I need to use RasterPos* () and how do I line it up with the start and end points of my line?

Hope someone can help. Thanks In advanced.

Pete

void draw_line (int x0, int y0, int x1, int y1) {

int x, y = y0;

int dx = 2*(x1 - x0), dy = 2*(y1 - y0);

int dydx = dy - dx, F = dy - dx/2;

for (x = x0; x <= x1; x++) {

draw_pixel (x, y);

if (F < 0) F+= dy;

else {y++; F+= dydx;}

}

}

This algorith is supposed to give me a line. However I do not know what draw_pixel is. Do I create an array and store values in it then use that array in glDrawPixel, or what do I do from here?

If I do need an array, then how do I implement that? Plus with glDrawPixel I need to use RasterPos* () and how do I line it up with the start and end points of my line?

Hope someone can help. Thanks In advanced.

Pete