While working on a particle engine in SDL, I stumbled over the following problem:
After implementing a frame interpolation technique as described here (Step 6: Optimization, I'm basically drawing the last frame with an alpha of 254 to the current frame) so that it fades out), I noticed that some pixels which were supposed to gradually fade from white to black, ended up staying gray, with rgba values of 112 to be precise. After doing some math I've found what's causing this: every frame I multiply the rgba values of the last frame by 254/255, which works fine up to and excluding 112.
Then something funny happens. When you do the following: round(112/255*254)=112, the values will stay the same (I'm rounding the number because the end value is to be stored as an 8bit color value of a pixel), meaning that my fading technique using alpha doesn't work anymore. The problem is that I would like these gray pixels which stay at 112 to fade out further. The question is, how would I achieve such a thing within SDL?
I know I could just make the value of 254 lower so that this sort of minimum decreases but I would like my particles to fade out really gently (I'm making a 60fps game). I've also considered creating an OpenGL graphics engine myself (so that I could use floating point textures, which do have to precision I need in this case), but I'm simply not good enough at OpenGL and lack the time to do such a thing. The reason I need to use a texture for storage is that I would like to have particles which emit trails (as if you stopped clearing your frame buffers and you moved an object, but instead of the screen becoming a mess the older pixels would fade out)
currentFrame->renderTo();//Draw to the current frame rendertarget
graphics.clear(Color(0,0,0,0)); //Clear the screen using the given color
graphics.scale=1.0f; //Manipulate pixel size (for visible pixel art)
SDL_SetTextureBlendMode(lastFrame->texture, SDL_BLENDMODE_NONE);
//Set blendmode to opaque
graphics.drawTexture(lastFrame,graphics.camera.position,Color(255,255,255,254));
//Draw the last frame
SDL_SetTextureBlendMode(lastFrame->texture, SDL_BLENDMODE_BLEND);
//Revert blendmode to alpha blending