Results 1 to 6 of 6

Thread: Circles, ellipses with stipple pattern

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2005
    Posts
    24

    Circles, ellipses with stipple pattern

    Hi!

    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?

    Thanks.

  2. #2
    Junior Member Newbie
    Join Date
    Sep 2005
    Posts
    5

    Re: Circles, ellipses with stipple pattern

    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.

  3. #3
    Member Newbie
    Join Date
    Dec 2004
    Posts
    33

    Re: Circles, ellipses with stipple pattern

    Are you having trouble drawing a circle/ellipse or is setting the right line style your problem?

  4. #4
    Senior Member Frequent Contributor
    Join Date
    Aug 2004
    Location
    munich, germany
    Posts
    659

    Re: Circles, ellipses with stipple pattern

    this should work:

    Code :
    int	i, steps = 36;
    float	x = 0.0, y = 0.0, r = 1.0, phi, dphi = 2.*M_PI / (float)(steps);
     
    glEnable(GL_LINE_STIPPLE);
    glLineStipple(1, 0xff);
     
    glBegin(GL_LINE_LOOP);
     
    for(i = 0, phi = 0.0; i < steps; i ++, phi += dphi)
    	glVertex3f(x+r*cos(phi), y+r*sin(phi), 0.0);
     
    glEnd();
     
    glDisable(GL_LINE_STIPPLE);
    draws a circle in the x-y-plane at center x/y,
    radius r. increasing "steps" will result in a
    smoother curve.

    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.

  5. #5
    Junior Member Newbie
    Join Date
    Jun 2005
    Posts
    24

    Re: Circles, ellipses with stipple pattern

    That's the code I needed Thank you RigidBody!

  6. #6
    Junior Member Newbie
    Join Date
    Sep 2005
    Posts
    5

    Re: Circles, ellipses with stipple pattern

    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.

Similar Threads

  1. Line Stipple Pattern
    By astrelke in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-07-2014, 02:32 AM
  2. Stipple pattern mis-alignment problem
    By sharp in forum OpenGL: Windows
    Replies: 1
    Last Post: 05-16-2006, 06:53 PM
  3. draw ellipses on a surface
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-10-2004, 02:40 AM
  4. about polygon stipple pattern
    By release in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 11-18-2002, 09:09 AM
  5. Stipple pattern
    By yossi in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 05-01-2001, 03:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean