13,201,934 members (73,412 online)
Rate this:
See more:
Hi, I'm having a bit of trouble making a good, nice, round, filled 2D circle in OpenGL. I use GNU C compiler, CodeBlocks IDE and Windows XP. The following code produces an ellipse that looks more like a "tomato" in the sense that it is wide for how tall it is. So the problem is, how to "thin it out" in the middle to make it more round like an actual circle.

```//filled circle
float x1,y1,x2,y2;
float angle;

x1 = 0.5,y1=0.6;
glColor3f(1.0,1.0,0.6);

glBegin(GL_TRIANGLE_FAN);
glVertex2f(x1,y1);

for (angle=1.0f;angle<361.0f;angle+=0.2)
{
glVertex2f(x2,y2);
}

glEnd();```
Posted 10-Mar-10 13:46pm
Updated 11-Mar-10 4:41am
v2

Rate this:

## Solution 3

Yes then it is definitely about aspect ratio. Which function are you using for initialize camera - gluOrtho2D or gluPerspective? You need to match the parameters to these functions with the aspect ratio of the window.

-Saurabh
Rate this:

## Solution 1

sin and cos expects angle to be in radians and not in degrees.

bala_48225 wrote:
for (angle=1.0f;angle<361.0f;angle+=0.2)

Try:
`for(angle=0.0f ; angle<2*3.14159 ; angle+=0.2)`

-Saurabh
v2
Rate this:

## Solution 4

Well it occured to me this morning to change the output window to a 1:1 square shape, like 600x600 and once I did, everything was perfect, so I guess perfection has been reached, haha. Nonetheless, feel free to run something past me about gluOrtho2d and gluPerspective, because the auto-code from my IDE/compiler (codeblocks/gnu) doesn't use those. At any rate, it sounds like those are useful for 4:3 and whatnot, and thanks again for your time, Saurabh.-B
v3
Rate this:

## Solution 5

Well, I bought the book Beginning OpenGL Game Programming, 2nd edition from Borders and used the first example project (after I finally got it to compile and everything), and then took their drawing code out and put mine in and modified things like gluLookat() bit by bit and sure enough, I can now make a 800x600 or 1024x768 screen with a nice, round planet. The auto-code from the CodeBlocks/Mingw setup was very simple and designed to set up a small 1:1 window and then do a rotating triangle, while the example from the book used all kinds of different functions like gluLookat() and gluPerspective and who knows what else. So the moral of the story for me is, buy a book. So until the next time I remain humbly yours, good people of Code Project. -B
Rate this:

## Solution 6

If it's a filled circle:

glEnable(GL_POINT_SMOOTH);
glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
glPoint(x, y, z);
v2
Rate this:

## Solution 7

I believe this gon help more in great way with OOP concept

```class circle{
public : float x,y,rot;

public:
void createcircle (int k, int r, int h);

};
void circle::createcircle (int k, int r, int h) {
glBegin(GL_TRIANGLE_FAN);
for (int i = 0; i < 180; i++)
{
x = r * cos(i) - h;
y = r * sin(i) + k;
glVertex3f(x + k,y - h,0);

x = r * cos(i + 0.1) - h;
y = r * sin(i + 0.1) + k;
glVertex3f(x + k,y - h,0);
}
glEnd();
}```

- See more at: Draw Circle in OpenGL
Rate this:

## Solution 2

Hello Saurabh, the same thing happened, though the "circle" wasn't complete this time so I "overkilled" it like this:

for (angle=0.0f;angle<3*3.14159;angle+=0.2)

by putting a 3 instead of 2 in "angle < 2*3.14159" as you see to finish it up.

At any rate, it's still a tomato. I personally think it has something to do with the aspectratio of the setup, because if I do this:

x1=-0.1f, y1=-0.1f,x2=0.1f,y2=0.1f;

glVertex2f(x1,y1);
glVertex2f(x2,y1);
glVertex2f(x2,y2);
glVertex2f(x1,y2);

glEnd();

it's a rectangle instead of a square. Perhaps you or someone else knows how to fiddle with some setup variables and thanks at any rate for giving it a shot. By the way, how do you indent on here? I put some spaces to indent, but it comes out flat.
v2

Top Experts
Last 24hrsThis month
 OriginalGriff 330 Richard MacCutchan 125 Dave Kreskowiak 100 ppolymorphe 75 GKP1992 75
 OriginalGriff 8,150 ppolymorphe 2,069 Karthik Bangalore 1,724 CPallini 1,208 Jochen Arndt 1,075