View Full Version : drawing circles in opengl

12-06-2000, 01:12 AM
i need to develop a simple drawing tool in opengl which will let me draw points, lines, circles and ellipses. these options must be availble by clicking the right mouse button. i can include a line and points but can't get circles to work.

help please

Michael Steinberg
12-06-2000, 05:47 AM
You'll need to "simulate" circles with lines.

Tim Stirling
12-06-2000, 11:22 AM
You'll need to "simulate" circles with lines.

try a for-next loop and rotate and then translate out the length of the radius.
I did something like this before, allowing you to choose the number of lines is usefull so you can have anything from a pentagon to a pixel perfect circle.

12-06-2000, 02:51 PM
Rotate and translate out of the radius? huh!? It's far easier just to zzap the verticies:

for(int i=0; i<CIRCLE_RESOLUTION; i++) {
float ang=((float)i/(foat)CIRCLE_RESOLUTION)*2.0*3.14159265;
glVertex2f(cos(ang)*rad, sin(ang)*rad);


I wanna be a nudist \ And live by the sea \ I wanna be a buisness man \ Drinking lots of coffee --- Regurgitator

12-07-2000, 05:37 AM
It may be easier, but it isn't as nice and it isn't as fast.

12-08-2000, 04:10 AM
simulating the circle is easiest done with sin and cos, it is useful to know that sin and cos are modelled on a circle, sin and cos of an angle will produce two new values which can represent proportional vertices of a circle.