Tilengine - The 2D retro graphics engine forum
Adding more blending modes - Printable Version

+- Tilengine - The 2D retro graphics engine forum (http://tilengine.org/forum)
+-- Forum: English forums (http://tilengine.org/forum/forumdisplay.php?fid=3)
+--- Forum: Support (http://tilengine.org/forum/forumdisplay.php?fid=7)
+--- Thread: Adding more blending modes (/showthread.php?tid=1723)



Adding more blending modes - System64 - 05-09-2022

Hello. I want to add more blending modes into Tilengine, such as logical OR, logical AND, and so on. I know I can define a custom blending function, but I want to implement it right into the library. How can I achieve that please?
Thanks for your answer.


RE: Adding more blending modes - megamarc - 05-09-2022

Hi!
Built-in blending tables are created in file Tables.c, in CreateBlendTables() function:
https://github.com/megamarc/Tilengine/blob/effe3a778de747469f8c83b6452af66e5cad30a8/src/Tables.c#L20

To add new modes, just expand the public enumeration TLN_Blend here:
https://github.com/megamarc/Tilengine/blob/effe3a778de747469f8c83b6452af66e5cad30a8/include/Tilengine.h#L83

And add the corresponding blend formula in the aforementioned CreateBlendTables()  with the desired effect.

For example formula for hypothetical logical AND should be:

Code:
_blend_tables[BLEND_AND][offset] = (a & b);

Parameters a and b are brightness levels between 0 and 255


RE: Adding more blending modes - System64 - 05-09-2022

(05-09-2022, 08:55 PM)megamarc Wrote: Hi!
Built-in blending tables are created in file Tables.c, in CreateBlendTables() function:
https://github.com/megamarc/Tilengine/blob/effe3a778de747469f8c83b6452af66e5cad30a8/src/Tables.c#L20

To add new modes, just expand the public enumeration TLN_Blend here:
https://github.com/megamarc/Tilengine/blob/effe3a778de747469f8c83b6452af66e5cad30a8/include/Tilengine.h#L83

And add the corresponding blend formula in the aforementioned CreateBlendTables()  with the desired effect.

For example formula for hypothetical logical AND should be:

Code:
_blend_tables[BLEND_AND][offset] = (a & b);

Parameters a and b are brightness levels between 0 and 255

Ah thanks! I will try this!


RE: Adding more blending modes - System64 - 05-10-2022

I added new blend modes in my fork. Thanks for your help!