I want to make a circle

i need to aproximate a circle with Ogl. and i need to draw it in any place of the screen without using the translatef command.

Well, you could use a for loop to generate your coordinates with sin and cos… Then you can simply provide the way you want to draw with glBegin( GL_LINE_STRIP ); or somtehing…

So it could be like this:

glBegin( GL_LINE_STRIP );

for( float angle = 0.0f; angle <= (2.0f*PI); angle += 0.1f )
{
x = cos(angle);
y = sin(angle);

glVertex3f( x, y , -1 ); // I dont know you coordinate system, so this -1 maybe wrong.
}

glEnd();

This should give and idea… For a better approximation, you simply increment the angle by a smaller unit…
I have not tested this 'cause i just worte it.
I hope this helps.

Originally posted by mancha:
for( float angle = 0.0f; angle <= (2.0f*PI); angle += 0.1f )

It’s better to use something like:

angle+=2.f*PI/Segments

This way all circle segments will be equal.

Also you need to have an offset varible, if you want to draw anywhere without glTranslate. I think you maybe having a problem a lot of people have using glTranslate and not also using glPop/push matrix with it, making things not translate the way you want.

Here are a few things missing from mancha’s example:

ox, oy, oz = location of center of circle anywhere on screen.
r = radius of circle.

x = r * cos(angle);
y = r * sin(angle);

glVertex3f( ox - x, oy - y , oz ); // you may need to change ether ox or oy to plus instead of minus.

Originally posted by mancha:
[b]Well, you could use a for loop to generate your coordinates with sin and cos… Then you can simply provide the way you want to draw with glBegin( GL_LINE_STRIP ); or somtehing…

So it could be like this:

glBegin( GL_LINE_STRIP );

for( float angle = 0.0f; angle <= (2.0f*PI); angle += 0.1f )
{
x = cos(angle);
y = sin(angle);

glVertex3f( x, y , -1 ); // I dont know you coordinate system, so this -1 maybe wrong.
}

glEnd();

This should give and idea… For a better approximation, you simply increment the angle by a smaller unit…
I have not tested this 'cause i just worte it.
I hope this helps. [/b]