So, I coded a little demo to show him how this is done in plain FB.mrToad wrote:Using openGL in freebasic I am able to adjust RGB values before drawing a texture, using glColor4ub. This is fine but the trouble is when I would like to maintain the brightness of the image but simply tint it more blue or red for example. Using this function the image is darkened when reducing the values from 255. I poked around but couldn't find a function in GL for it, and I don't know how to write one. The application would be to brighten an image beyond normal and also tint it a color.
https://github.com/glasyalabolas/fb-layer-modes
You can think of it as 'pixel shaders' coded in FB. The blitter is used in pretty much the same way as FB PUT statement, and works in 32-bit and 64-bit FB.
There are 2 files: 'layer modes.bas' contains the demo showing all blending modes available thus far. For best results, compile with fbc -gen gcc -Wc -O3. Use '1' and '2' to cycle between blending modes, 'q' and 'w' to increase the 'param' parameter (it does different things depending on the mode), and '+' / '-' to change the opacity of the source image. With the arrow keys you can move the image to put it in a different place in the background to see how the blending interacts (I chose that image because it has regions with high/low brightness and saturations).
And the 'benchmark.bas' file contains simple benchmarking code to test the blitter against the same functionality by the FB PUT statement. I would like to know the results you get (I haven't tried with 32-bit GCC, for example), and under which conditions (compiler switches).
@mrToad: I hope that it's useful. On another post I'll show you how you can code different effects. Experiment with it yourself, of course ;) If you want some effect that isn't covered here, we can code it and add it to the library of blending modes.
Have fun!
Paul
UPDATE 2017/12/8: Refactored the OpenGL version, so now it's a little less rushed =D Added the 'addition' blending mode. More to follow.
UPDATE 2017/12/5: The OpenGL version can be downloaded from here:
https://github.com/glasyalabolas/fb-shaders-demo
Only the 'alpha' mode is supported for now. Will add the rest soon.
UPDATE 2017/11/15: Made all blending modes not alter the alpha channel (they weren't supposed to touch it). Modified the 'bmTint' blending mode to accept a struct rather than 3 isolated parameters. It now uses a parameter to add or substract the tint color from the image. Not that anybody cares, of course.
UPDATE 2017/11/14: Corrected 'bmTint' blending mode as it was not honoring the 'opacity' parameter.