[…]
if I call draw circle like this
for (int i=1;i<=15;i++)
draw(200,200,i);
Well, that’s about the slowest way you can possibly render a filled
circle!
How about calculating the coordinates of the left and right edges (using
sin() is the easiest way, although there are faster ways), and then do
the rendering using SDL_FillRect()…?
Something like
#include <math.h>
void circle(SDL_Surface screen, int x, int y, int r, Uint32 color)
{
int y1, y2;
SDL_Rect rect;
for(y1 = -r, y2 = r; y1; ++y1, --y2)
{
int xr = (int)(sqrt(rr - y1*y1) + 0.5);
rect.x = x - xr;
rect.y = y + y1;
rect.w = 2 * xr;
rect.h = 1;
SDL_FillRect(screen, &rect, color);
rect.y = y + y2;
rect.h = 1;
SDL_FillRect(screen, &rect, color);
}
rect.x = x - r;
rect.y = y;
rect.w = 2 * r;
rect.h = 1;
SDL_FillRect(screen, &rect, color);
}
You’d probably want to replace the sqrt() with some fixed point
approximation for speed. (A 3rd or 4th degree polynomial or something. In
iterative code like this, they can be imlemented using only adds.)
BTW, how come the docs don’t mention that SDL_FillRect() writes the
resulting clipped rectangle into the dest rect?
//David Olofson — Programmer, Reologica Instruments AB
.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |
-------------------------------------> http://olofson.net -'On Sunday 30 December 2001 23:31, Todd V . Rovito wrote: