2

I need to draw several "layers" of bitmaps that are semi-transparent to a FBO (for later readback).

My current approach is to create a FBO, attach a texture to it and use glTexSubImage2D to "draw" the bitmaps to the FBO, this however, doesn't work as glTexSubImage2D doesn't draw/blend the pixels, but just overwrite the pixels currently in the texture.

What's the best way to do this?

monoceres
  • 4,722
  • 4
  • 38
  • 63

1 Answers1

3
  • You create a FBO with a clean texture R attached to hold the final result.
  • For each of your bitmaps you:
    • Upload the bitmap to a texture T (T and and R are different textures).
    • Render a quad textured with T into the FBO with GL_BLEND enabled and properly set up.

The final result is that R holds your blended bitmaps. You can now read it back or use in other texturing operations.

Yakov Galka
  • 70,775
  • 16
  • 139
  • 220
  • Thanks, this works. Final question: My layers may be of different size (hence glTextSubImage2D) which means that there may be leftovers of the previous layer in T. What's the best way to make sure I have an empty texture between each layer draw? – monoceres Nov 09 '16 at 16:28
  • 1
    If the texture size chnges: either create a new texture each time, or tweak your quad and texture coordinates so that they draw and sample only to/from the relevant part of the FBO/texture. – Yakov Galka Nov 10 '16 at 08:05