SDL 2.0 Defocus Blur

Hi, I am new in the SDL 2.0 programming word. I want to realize a simple SDL project for “defocus blur” effect. For example if I have 3 objects I want to use camera aperture to focus only on the centered object, only on the first object etc… Can someone help me or give me any examples?

For blurring an entire image the approach I have adopted is to use SDL_SetTextureBlendMode() to select SDL_BLENDMODE_ADD and SDL_SetTextureAlphaMod() to control the ‘gain’. Then you can implement a simple 2D blurring filter by rendering the source image multiple times with different gains and displacements. However it’s quite difficult to get a realistic effect.

Selectively blurring some regions of the image more than others, as you want to, is considerably more difficult. The only time I’ve done that was back in the 1990s using custom hardware (see Synthetic defocussing here) and TBH I can’t even remember exactly how I did it! I will certainly have simulated it in software at the time, but I doubt that I still have any of the code.