Jump to content
  • Advertisement
Sign in to follow this  
wwinthan

OpenGL easyway to draw a circle in opengl

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
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 this post


Link to post
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_LOOP

for( 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 this post


Link to post
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 this post


Link to post
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...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!