Draw a circle in sdl, with double buffering

At any rate, let me add that when I first got back into (graphics) programming after an almost 20 year layoff, I would have been glad to see things like this, to help me “noodle around” without having to first learn OpenGL–which you could expect with my background being Turbo C 2.0 with the “good old” BGI.

Just found out that any sdl surface has an automatic, built in clip_rect, so:


void circle(int x, int y, int radius, SDL_Surface *thescreen, int r, int g, int b)
float floatx, floaty, floatradius;
SDL_Rect trect;

trect.w = 2;
trect.h = 2;

floatx = static_cast <float> (x);
floaty = static_cast <float> (y);
floatradius = static_cast <float> (radius);

float i;

for (i=0; i < 360; i+=.2)
    float degInRad = i*DEG2RAD;

    trect.x = static_cast <int> (floatx + cos(degInRad) * floatradius);
    trect.y = static_cast <int> (floaty + sin(degInRad)* floatradius);

    if(trect.x >= thescreen->clip_rect.x)
        if(trect.y >= thescreen->clip_rect.y)
            if((trect.x + trect.w) <= thescreen->clip_rect.w)
                if((trect.y + trect.h) <= thescreen->clip_rect.h)
                    SDL_FillRect(thescreen, &trect, SDL_MapRGB( thescreen->format,r,g,b));