'How to draw a smooth and filled circle using SDL?

I'm using SDL in my C project in which I want to draw a circle that is filled and has a smooth stroke at the same time. Sure, there are functions for each task in SDL: I used aacircleRGBA() and filledCircleRGBA(). Unfortunately, there is no aafilledCircleRGBA() which I would need.

The problem is, that these two functions are both working well separately, but when I try to use them together (drawing circles on each other with the same properties), the size of the circles they draw do not match. One of them (which one is depending on the radius) is always a little bit bigger. This can be seen in the picture below:

...
aacircleRGBA(renderer, 300, 300, 100, 90, 160, 20, 255);
filledCircleRGBA(renderer, 300, 300, 100, 90, 160, 20, 255);

SDL_RenderPresent(renderer);
...

enter image description here

As you can see, the aacircleRGBA() draws a "taller", while the filledCircleRGBA() draws a "wider" circle than the other.

Is there a way to use these two better than I did, or is there any other useful function in SDL that can solve the problem?



Solution 1:[1]

I'm a bit late, I know. I have a very nice solution, but it may not be the fastest. You start by drawing that yucky circle with filledCircleRGBA, then draw an ellipse with an aaellipseRGBA, using radius+1 as your rx, and finally smooth out the top and bottom of the circle with aacircleRGBA.

void aaFilledCircle(SDL_Renderer* renderer, short x, short y, short rad,
                    char r, char g, char b, char a) {
    filledCircleRGBA(renderer, x, y, rad, r, g, b, a);
    aaellipseRGBA(renderer, x, y, rad+1, rad, r, g, b, a);
    aacircleRGBA(renderer, x, y, rad, r, g, b, a);
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shifu