2

In OpenGL, how can I draw a given percentage of the outline of a circle? And how can I control the thickness of that outline?

Example: If the percentage is 100, then the outline of a full circle should be drawn. If the percentage is 50, the outline of half a circle should be drawn.

I've tried the following, but the problem there is that it completes the lineloop, leading to a line connecting the startpoint and endpoint of the circle outline. Additionally, it does not seam to let me change the thickness of the outline.

glBegin(GL_LINE_LOOP);

    for (int i=0; i < (360/10*percent/10); i++) {
        float degInRad = i*DEG2RAD;
        glVertex2f(a+cos(degInRad)*r,b+sin(degInRad)*r);
    }

glEnd();

I am tempted to just make my circle up of GL_POINTS, but I was wondering if there is a better way?

Ben
  • 15,938
  • 19
  • 92
  • 138
  • Im encountering the same issue and from this post my code now looks like this `glEnable(GL_LINE_SMOOTH); glLineWidth(10); glBegin(GL_LINE_STRIP); for (int i=0; i < (360/10*100/10); i++) { float degInRad = i*DEG2RAD; glVertex2f(x1+cos(degInRad)*r,y1+sin(degInRad)*r); } glEnd();` but I still get the bits missing in between even with GL_LINE_SMOOTH. Am I putting it in the wrong place or something? – user1135469 May 10 '13 at 01:15

1 Answers1

5

Replace GL_LINE_LOOP with GL_LINE_STRIP, this way the last and first vertices aren't connected. Use the glLineWidth() function to define your line thickness.

StuGrey
  • 1,479
  • 9
  • 20
  • Thx, but if I place `glLineWidth(20)` inside the GL_LINE_LOOP, then it still draws it with a width of 1px. If I place it outside, the line looks very very weird (it sort of has little bits missing inbetween). – Ben Jul 15 '12 at 14:09
  • From the Docs: Not all widths can be supported when line antialiasing is enabled. If an unsupported width is requested, the nearest supported width is used. Only width 1 is guaranteed to be supported; others depend on the implementation. Likewise, there is a range for aliased line widths as well. To query the range of supported widths and the size difference between supported widths within the range, call glGetInteger with arguments GL_ALIASED_LINE_WIDTH_RANGE, GL_SMOOTH_LINE_WIDTH_RANGE, GL_SMOOTH_LINE_WIDTH_GRANULARITY. – StuGrey Jul 15 '12 at 14:13
  • Solved by using `glEnable(GL_LINE_SMOOTH);`. Thank you. – Ben Jul 15 '12 at 14:45