Connect midpoint circle dots for circle outline
Hello everyone,
I've just begun learning openGL and one of the first steps is to draw a circle using the bresenham/midpoint algorithm. The code actual works (so proud of myself! ... ) but, completely as expected there's only dots. What I would like is to actually complete the circle as in connect the dots. However, also as expected, turning glBegin(GL_POINTS) into glBegin(GL_LINE_STRIP) (or LINES for that matter) connects the wrong dots because of the algorithm. Google hasn't helped me yet and so completely against my normal customs I decided to post here.
How can I have the dots connect to get a full circle, instead of just a dotted one?
Below the code used for the algorithm. I simply call it with awCircle(0,0,10);
Code :
/****************************************************************************
* Draw the actual circle points in each section.
***************************************************************************/
void drawCirclePoints (int x, int y, int xc, int yc)
{
glBegin(GL_POINTS);
glVertex2i (xc+x,yc+y);
glVertex2i (xc-x,yc+y);
glVertex2i (xc+x,yc-y);
glVertex2i (xc-x,yc-y);
glVertex2i (xc+y,yc+x);
glVertex2i (xc-y,yc+x);
glVertex2i (xc+y,yc-x);
glVertex2i (xc-y,yc-x);
glEnd();
}
/****************************************************************************
* Function to make sure all points of a whole circle get drawn
***************************************************************************/
void awCircle (int xc, int yc, int rad)
{
int x,y,d;
x = 0;
y = rad;
drawCirclePoints (x,y,xc,yc);
d = 1 - rad;
while (x < y)
{
if (d < 0)
{x++;d += 2*x +1;}
else
{ x++; y--;d += 2*(x-y) + 1;}
drawCirclePoints (x,y,xc,yc);
}
}