# OpenGL easyway to draw a circle in opengl

This topic is 3693 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

any easy ways to draw circle(& filled circle)??help! all i have is center point and radius

##### Share on other sites
i can transfrom circle to arc and draw it but it's not efficient..

##### Share on other sites
You can fill a vertex array with points on the circle and draw that array.
:)

##### Share on other sites
One approach is to basically draw segments around a point, using sin/cos to figure out the distance. Something similar to

http://boogame.svn.sourceforge.net/viewvc/boogame/trunk/src/Video/Paint.cs?revision=129&view=markup

Look at lines 256-274. It should be pretty obvious how to translate to your language of choice. The filled is 282-308.

I don't know if it is efficient, but it works out pretty well for me.

##### Share on other sites
Render a texture map quad using an alpha only circle texture.
High quality result can be achieved with small textures using this technique.

##### Share on other sites
Use GL_POLYGON (filled) or GL_LINE_LOOP (unfilled) with parametric equations for your vertex coordinates.

x = r*cos(theta)
y = r*sin(theta)

theta ranging from 0 to 2*pi.

Size of your angle increment, of course, is indirectly proportional to the smoothness of your circle.

Then translate your circle to your given center point, as it should be at (0,0,0) by default.

float delta_theta = 0.01;glBegin( GL_POLYGON ); // OR GL_LINE_LOOPfor( float angle = 0; angle < 2*PI; angle += delta_theta )glVertex3f( r*cos(angle), r*sin(angle), 0 );glEnd();

Cheers,

Cryo();

[Edited by - cryo2010 on November 5, 2008 2:08:46 AM]

##### Share on other sites
Draw a single quad with the dimension of the circle and use the fragment shader to draw it.

EDIT: The points of the circle are defined by (s - 0.5)^2 + (t - 0.5)^2 <= 0.25 where (s,t) are the texture coordinates.

##### Share on other sites
Turn off the lighting. Select a 2D projection. Choose a flat colour. Use the Glut sphere drawing call.

People said easy, not fast...

1. 1
2. 2
Rutin
19
3. 3
khawk
15
4. 4
5. 5
A4L
13

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633744
• Total Posts
3013652
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!