Yeah, just as you thought there is no function to use a clip rectangle. However, if your use case is limited enough, you should be able to simulate this with render targets & blend-modes. Here's how you could do that:
- Create a render texture that is transparent and can fit your circle in it.
- Render your circle to the render texture.
- Change the blend mode to
- Render whatever you want to render on top of the circle in the render texture.
- When done, just render the render texture to the default target (window).
*If you don't want additive blending, you could take a look at
SDL_ComposeCustomBlendMode. I haven't used that myself but it looks like you might be able to implement a blend mode that takes the source color but keeps the destination alpha.
Incase you're unable to figure out the custom blend mode on your own, here's something to get you started:
SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ZERO, SDL_BLENDOPERATION_ADD, SDL_BLENDFACTOR_ZERO, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_ADD);
Do note that I haven't tried this out myself, but here's how I built that blend mode: First, we wanted to keep the source color, and not let the destination color affect that. So, we simply keep the source color as what it is (so multiply by
SDL_BLENDFACTOR_ONE) and zero out the destination color (
SDL_BLENDFACTOR_ZERO). Those can then simply be added together to get the source color as a result. Similarly, for alpha, we wanted to keep the destination alpha, so we zero out the source alpha but keep destination alpha as what it is. These can be added together.