Search code examples
openglrenderingblendingfbo

Rendering layers of bitmaps with alpha to FBO


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?


Solution

    • 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.