Hi all,
A very basic question I guess :
how do I draw a circle in OpenGL,
given its center and radius ?
I mean just a circle drawn by a continuous line,
there are no filling nor texture involved here.
I know I can do this step by step by increasing
an angle and using glBegin() with GL_LINE_STRIP
or GL_LINE_LOOP, and calling glVertex3f(x,y,z)
but this needs to be done inside a loop.
So I'm wondering if there's a dedicated
function, like glCircle( center, radius, ... ) ?
TIA
|
|
0
|
|
|
|
Reply
|
5.d (68)
|
8/26/2010 9:09:04 AM |
|
Jean-Christophe wrote:
> Hi all,
>
> A very basic question I guess :
> how do I draw a circle in OpenGL,
> given its center and radius ?
>
> I mean just a circle drawn by a continuous line,
> there are no filling nor texture involved here.
>
> I know I can do this step by step by increasing
> an angle and using glBegin() with GL_LINE_STRIP
> or GL_LINE_LOOP, and calling glVertex3f(x,y,z)
> but this needs to be done inside a loop.
>
> So I'm wondering if there's a dedicated
> function, like glCircle( center, radius, ... ) ?
I was wondering the same some time ago, but for the ellipse (that is
just a more general case), and the simplest solution I found was to use
a texture.
If someone knows a better way (without using lists), I would be very
interested to hear.
|
|
0
|
|
|
|
Reply
|
Vladimir
|
8/26/2010 9:15:19 AM
|
|
"Vladimir Jovic" <vladaspams@gmail.com> wrote in message
news:i55bb7$aj6$1@news.albasani.net...
> Jean-Christophe wrote:
>> So I'm wondering if there's a dedicated
>> function, like glCircle( center, radius, ... ) ?
>
> I was wondering the same some time ago, but for the ellipse (that is just
> a more general case), and the simplest solution I found was to use a
> texture.
>
> If someone knows a better way (without using lists), I would be very
> interested to hear.
gluDisk()
--
Charles E Hardwidge
|
|
0
|
|
|
|
Reply
|
Charles
|
8/26/2010 9:26:29 AM
|
|
On Aug 26, 11:26=A0am, "Charles E Hardwidge"
| So I'm wondering if there's a dedicated
| function, like glCircle( center, radius, ... ) ?
> gluDisk()
Yes I know gluDisk( qobj, innerRadius, outerRadius, slices, loops );
but I want to avoid using DISK to draw a simple CIRCLE.
For now I use the following code,
but I want to avoid such a time-consuming loop.
glBegin( GL_LINE_STRIP );
for( a =3D 0.0f; a <=3D 6.2831853f; a +=3D 1.0f )
{ y =3D d * (float)sin( a );
x =3D d * (float)cos( a );
glVertex3f( x, y, z );
}
glEnd();
|
|
0
|
|
|
|
Reply
|
Jean
|
8/26/2010 10:31:35 AM
|
|
On Thu, 26 Aug 2010 02:09:04 -0700, Jean-Christophe wrote:
> A very basic question I guess :
> how do I draw a circle in OpenGL,
> given its center and radius ?
>
> I mean just a circle drawn by a continuous line,
> there are no filling nor texture involved here.
>
> I know I can do this step by step by increasing
> an angle and using glBegin() with GL_LINE_STRIP
> or GL_LINE_LOOP, and calling glVertex3f(x,y,z)
> but this needs to be done inside a loop.
>
> So I'm wondering if there's a dedicated
> function, like glCircle( center, radius, ... ) ?
gluDisk() creates a filled annulus (or disc if the inner radius is zero).
Alternatively, you can use evaluators. The following code generates a
quarter of the unit circle in the X-Y plane using a quadratic rational
Bezier curve:
#define K 0.7071067811865475 /* sqrt(1/2) */
static const GLfloat cpts[3][4] = {
{0, 1, 0, 1},
{K, K, 0, K},
{1, 0, 0, 1}
};
#define NSEGS 50 /* number of segments */
glEnable(GL_MAP1_VERTEX_4);
glMap1f(GL_MAP1_VERTEX_4, 0, 1, &cpts[0][0]);
glMapGrid1f(NSEGS, 0, 1);
glEvalMesh1(GL_LINE, 0, NSEGS);
Reflect or rotate the control points to obtain the other quadrants.
You can do it with three 120-degree sections, but the angular spacing of
the vertices is less uniform. Or you can use two cubic curves (three
for more uniform spacing), or even a single quintic curve (6 control
points).
All polynomial or rational approaches have some nonuniformity in the
angular spacing. If you want perfectly uniform angular spacing, you have
to generate the vertices yourself with sin/cos (which is what gluDisk()
does).
|
|
0
|
|
|
|
Reply
|
Nobody
|
8/26/2010 10:35:55 AM
|
|
On Aug 26, 12:31=A0pm, Jean-Christophe <5...@free.fr> wrote:
>
> Yes I know gluDisk( qobj, innerRadius, outerRadius, slices, loops );
> but I want to avoid using DISK to draw a simple CIRCLE.
>
> For now I use the following code,
> but I want to avoid such a time-consuming loop.
>
> glBegin( GL_LINE_STRIP );
> =A0for( a =3D 0.0f; a <=3D 6.2831853f; a +=3D 1.0f )
> =A0{ y =3D d * (float)sin( a );
> =A0 =A0x =3D d * (float)cos( a );
> =A0 =A0glVertex3f( x, y, z );
> =A0}
> glEnd();
If it's really a performance problem (have you
measured it or are you just imagining?) you
could put the values in an array and use
glDrawArrays().
> So I'm wondering if there's a dedicated
> function, like glCircle( center, radius, ... ) ?
There is, but it probably uses a loop just ;ike
yours.
|
|
0
|
|
|
|
Reply
|
fungus
|
8/26/2010 10:41:38 AM
|
|
"Jean-Christophe" <5.d@free.fr> wrote in message
news:a8b6bdfa-c252-401f-9d10-c18a63bdcc81@l6g2000yqb.googlegroups.com...
> On Aug 26, 11:26 am, "Charles E Hardwidge"
>
> | So I'm wondering if there's a dedicated
> | function, like glCircle( center, radius, ... ) ?
>
>> gluDisk()
>
> Yes I know gluDisk( qobj, innerRadius, outerRadius, slices, loops );
> but I want to avoid using DISK to draw a simple CIRCLE.
>
> For now I use the following code,
> but I want to avoid such a time-consuming loop.
>
> glBegin( GL_LINE_STRIP );
> for( a = 0.0f; a <= 6.2831853f; a += 1.0f )
> { y = d * (float)sin( a );
> x = d * (float)cos( a );
> glVertex3f( x, y, z );
> }
> glEnd();
>
If your circle doesn't change much you could cache it into a texture and do
nothing more fancy than blast it out when you need it.
You can optimise in the algorithm. It's cheap and dirty but might be what
you're looking for:
http://slabode.exofire.net/circle_draw.shtml
Fragment shaders:
http://people.freedesktop.org/~idr/OpenGL_tutorials/03-fragment-intro.html
Use a "vector shader" technique:
http://www.valvesoftware.com/publications/2007/SIGGRAPH2007_AlphaTestedMagnification.pdf
--
Charles E Hardwidge
|
|
0
|
|
|
|
Reply
|
Charles
|
8/26/2010 10:56:33 AM
|
|
On Aug 26, 11:09=A0am, Jean-Christophe
> how do I draw a circle in OpenGL,
> given its center and radius =A0?
Ok - thanks to all of you for your answers !
|
|
0
|
|
|
|
Reply
|
Jean
|
8/26/2010 11:16:32 AM
|
|
Jean-Christophe wrote:
> On Aug 26, 11:26 am, "Charles E Hardwidge"
>
> | So I'm wondering if there's a dedicated
> | function, like glCircle( center, radius, ... ) ?
>
>> gluDisk()
>
> Yes I know gluDisk( qobj, innerRadius, outerRadius, slices, loops );
> but I want to avoid using DISK to draw a simple CIRCLE.
>
> For now I use the following code,
> but I want to avoid such a time-consuming loop.
>
> glBegin( GL_LINE_STRIP );
> for( a = 0.0f; a <= 6.2831853f; a += 1.0f )
> { y = d * (float)sin( a );
> x = d * (float)cos( a );
> glVertex3f( x, y, z );
> }
> glEnd();
Don't think anyone's mentioned this, so I will. You can get rid of the
costly trigonometric operations by using the midpoint circle algorithm
(Google it).
In terms of implementing it for use with OpenGL, I guess you could write
the points it produces to a vertex array and do it that way. There may
be more OpenGL-friendly approaches, though, I'm not sure.
Cheers,
Stu
|
|
0
|
|
|
|
Reply
|
Stuart
|
8/26/2010 8:58:12 PM
|
|
|
8 Replies
379 Views
(page loaded in 0.071 seconds)
Similiar Articles: Drawing a circle. - comp.graphics.api.openglHi all, A very basic question I guess : how do I draw a circle in OpenGL, given its center and radius ? I mean just a circle drawn by a continuous ... how to draw a circle inside circle - comp.soft-sys.matlab ...hi, i need to draw a circle of outer dia-10cm with center as (0,0) and with the same center i need to draw another circle of dia-5cm in the same figu... Draw Circle in matrix - comp.soft-sys.matlabHow do yo draw a circle in a matrix with the value at 10V?? This is my set code so far, the circle should be to the left of the rectangle. a=zeros(... draw circle, eclipse and various shape on image matrix - comp.soft ...Hi, I wonder if there is some files available in matlab central that can draw circle, eclipse and various shape on an image matrix? Note: not on a pl... Drawing series of circles - comp.soft-sys.matlabDear Fellows/Expert I have a 2D work plane of 100 mm x 160 mm. In this work plane I want to draw following two series of circles: Series 1; ... How to draw circle (round) text using iTextSharp library? - comp ...Find text position in PDF using iText - comp.text.pdf How to draw circle (round) text using iTextSharp library? - comp ... Find text position in PDF using iText ... Diameter symbol doesn't show up. - comp.cad.solidworksI just opened a drawing, and instead of showing the diameter symbol (a circle with a slash), it displays . Is there some setting to change this. Than... Arc of a circle - comp.lang.idl-pvwaveHello! simple question: does anybody know how to draw an arc of a circle in plot. A circle can be easily created, knowing the center coordinates an... Conic Section Drawing - comp.soft-sys.matlabDrawing a circle. - comp.graphics.api.opengl Conic Section Drawing - comp.soft-sys.matlab Chapter 7 Drawing a circle and conic sections Chapter 7 Drawing a circle and ... PSP 9 adding nodes to a contour - comp.graphics.apps.paint-shop ...I just downloaded PSP 9. After drawing a circle I wanted to add a node. Just as in PSP 8 you have to press the control key while moving the cursor o... How to Draw a Circle: 7 Methods - wikiHowHow to Draw a Circle. Although there are many ways to draw a perfect circle, some work better than others in certain situations. Here are a few techniques; you pick ... How to Draw a Circle | eHow.comLearning how to draw a circle is a very important artistic skill. Many objects are made up of circles, including wheels, rings, oranges and faces. If you can ... 7/23/2012 6:39:54 AM
|