Transparent FrameBuffer background in OpenGL

前端 未结 3 1619
执笔经年
执笔经年 2021-02-10 13:53

I want to use glClear and glClearColor to fill a frame buffer with a colour including alpha transparency. However the framebuffer always renders as opaque when binded to a textu

3条回答
  •  误落风尘
    2021-02-10 14:16

    I think there's a basic misunderstanding of the framebuffer here. The framebuffer is not really a buffer of data in itself, it does not hold any data. You attach buffers TO it (like a texture) so that you can render to offscreen buffers in the same manner you draw to the screen. So when you say you want to "glClear and glClearColor to fill a frame buffer with a colour including alpha transparency", it doesn't quite make sense because the framebuffer does not hold any color data itself.

    When you attach the texture to the framebuffer with this call:

    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, surface.texture, 0)
    

    You're making the "surface.texture" the rendering destination of the framebuffer. In other words, you're essentially saying "When I draw to this framebuffer, draw into this texture.".

提交回复
热议问题