Skip to main content
gamedev.net
🔒 Locked

Rendering Circles

Started by TerrorFLOP Apr 19, 2004 at 4:16 AM 2 replies 800+ views
Original Post
TerrorFLOP
TerrorFLOP
Hey, I was just wondering... Wots da best way to render circles and ellipses on screen, WITHOUT using high level GDI functions like DrawEllipse??? I''d like a low level approach to this problem, using the address to the video card graphics buffer (via DirectX) and using low level inline assembley in C++. I''d like to wrap this up in a nice function that draws circles and ellipses fast, anywhere on the screen. Because speed is an issue, I thought generating huge lookup tables which hold plots for various radii of circles and ellipses might be the best and fastest approach. Would this be the best way to proceed??? Also, does DirectX have a draw circle function, which uses accelerated hardware??? Thanks!
Telamon
Telamon
The fastest approach (AFAIK) is to draw one octet of the circle, and then reflect it across the horizontal and diagonal axes. The code for doing this might look something like this:


sector(int r)
{
int x = r;
int y = 0;

e = -r;
dedy = 1;
dedx = 2 - r - r;

while( x > y ) {

point( x, y );
e += dedy;
dedy += 2
y += 1;

if ( e >= 0 ) {

e += dedx;
dedx += 2;
x -= 1;

}
}
}


To get ellipses, or to draw rotated ellipses, you need to multiply the resulting points by the appropriate linear transformation.

----------------------------------------
Let be be finale of seem, seems to me.
----------------------------------------

Shedletsky''s Code Library:

Open source projects and demos

TerrorFLOP
TerrorFLOP
Thx Telamon...

I''ll look into your algorithm :-)
Cornutopia
Cornutopia
A wireframe polygon rendered using line-strips in Direct 3D would be the hardware accelerated way to draw circles. Anti-aliasing aside, wireframe acceleration seems to be the poorer cousin of solid polygons but you should still be able to manage a few million circles a second or something on a Geforce 3.

Of course, setting up the 3D api just to render circles might be more trouble that its worth! But on the plus side you could render any line polygon easily once/if you get that far.

Mark
Sound Effects For Game Developers
http://www.indiesfx.co.uk
Flatspace is here: The ultimate space adventure
http://www.lostinflatspace.com

[edited by - Mark Sheeky on April 20, 2004 12:46:28 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.