我正在使用这个 Bresenham 的算法来画圆。此代码有效,但我需要实心圆圈,而不仅仅是边框。
这是我的代码:
void setPixel(int x,int y) {
glBegin(GL_POINTS);
glColor3f(0.0f, 1.0f, 0.0f);
glPointSize (20.0);
glVertex2i(x,y);
glEnd();
}
void BresenhamKrug(int xCenter, int yCenter,int r){ //napravite parametarski poziv
int x=0,y=r;
int d=3-(2*r);
glColor3f(0.5,0.3,1.);
while(x<=y)
{
setPixel(xCenter+x,yCenter+y); setPixel(xCenter+y,yCenter+x);
setPixel(xCenter-x,yCenter+y); setPixel(xCenter+y,yCenter-x);
setPixel(xCenter-x,yCenter-y); setPixel(xCenter-y,yCenter-x);
setPixel(xCenter+x,yCenter-y); setPixel(xCenter-y,yCenter+x);
if (d<0)
d += (4*x)+6;
else{
d += (4*(x-y))+10;
y--;
}
x++;
}
glFlush();
}
有什么办法吗?