PDA

View Full Version : Lines using glDrawPixel



cyclopentane
09-30-2003, 02: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

09-30-2003, 04:54 PM
From the looks of the code you posted, draw_pixel is an application specific function. It probably does something like this:

glBegin(GL_POINTS);
glVertex2d(x,y);
glEnd();

cyclopentane
09-30-2003, 05:15 PM
However I need to use glDrawPixels. It is a requirement that I cannot get around. Any suggestions on how to do it with this (glDrawPixels)?

Thanks Again
Pete

09-30-2003, 11:45 PM
Well if the code you posted was taken directly from an OpenGL app, then draw_pixel is most likely the same thing as glDrawPixel.

10-01-2003, 05:45 AM
glDrawPixels is for drawing rectangular arrays of pixels into the framebuffer... what am I missing here? I can't believe you're really intending to use glDrawPixels to draw 1x1 arrays, are you?

This is an assigment, correct? From what you've said it sounds like you're supposed to provide an implementation of draw_pixel(), so macfiend has given you the answer above.

cyclopentane
10-01-2003, 09:20 AM
I believe that I am supposed to create an array to represent the whole line. So if my line goes from 0,0 to 5,5 then I would need to set up an array 5x5 and have the array mark the appropiate spots so it will draw a line there. However I am not really sure how to take the results from DDA or bresenham and put them into a array/matrix.