View Full Version : Circles, ellipses with stipple pattern
09-05-2005, 06:32 AM
I found samples for drawing circles or ellipses on the web. What I want to do is draw them with stipple pattern, just like glLineStipple. What is the easiest way to do this?
09-05-2005, 12:14 PM
Imagine a 4-sided figure. Doesn't look like a circle. Imagine an 8-sided figure (like a US stop sign). It's looking more like a circle, but still rought. Now imagine a 36-sided figure. Looks pretty much like a circle.
Really you're connecting each of the 36 points with a line (which will obey line stipple). So your quest now is to calculate the 36 points you need for a circle.
There are many resources to find this information out. If you still need help I'll try to post some more details.
09-05-2005, 10:59 PM
Are you having trouble drawing a circle/ellipse or is setting the right line style your problem?
09-05-2005, 11:00 PM
this should work:
int i, steps = 36;
float x = 0.0, y = 0.0, r = 1.0, phi, dphi = 2.*M_PI / (float)(steps);
for(i = 0, phi = 0.0; i < steps; i ++, phi += dphi)
glVertex3f(x+r*cos(phi), y+r*sin(phi), 0.0);
glDisable(GL_LINE_STIPPLE);draws a circle in the x-y-plane at center x/y,
radius r. increasing "steps" will result in a
a stipple pattern is defined with glLineStipple.
the pattern is a 16-bit short (values from 0x0000
- 0xffff), so "0xff" means: 8 bits sets in the
pattern, the following 8 bits are cleared. the
value "1" defines how often each bit in the
pattern is repeated.
09-05-2005, 11:34 PM
That's the code I needed ;) Thank you RigidBody!
09-06-2005, 02:39 AM
If you plan on drawing many circles, consider pre-calculating your sin/cos values. It will save some time in a tight loop with lots of circles.
Powered by vBulletin® Version 4.2.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.