1

SDL2 provides by default 3 blend modes: alpha blend, additive, and multiply.

However I need to render filled rectangles using the Linear Light blend mode.

Is this possible to implement using OpenGL, or as a combination of the 3 built-in blend modes, or should I convert all my SDL_Textures to SDL_Surfaces and modify the pixel values manually?

Emil Laine
  • 41,598
  • 9
  • 101
  • 157
  • Keep an instance of your Surface, modify this surface and make a texture out of it. The texture is on the memory near your GPU. – jordsti Aug 24 '16 at 21:19
  • Yeah, that's what I'm probably going to do. – Emil Laine Aug 25 '16 at 15:29
  • Readback and software recalculation is likely to be enormously slow. You can render to texture and then combine two textures with a shader and have very good performance with that. However it is not exactly what blending does (rendering multiple shapes should all blend in draw order, not just once). – keltar Aug 25 '16 at 16:53

1 Answers1

3

SDL 2.0.6 introduced the function SDL_ComposeCustomBlendMode allowing you to create a new blend mode for 2D rendering.

Here is the doc entry: https://wiki.libsdl.org/SDL_ComposeCustomBlendMode

AndrewK
  • 39
  • 3