Transparent FrameBuffer background in OpenGL

前端 未结 3 1620
执笔经年
执笔经年 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.".

    0 讨论(0)
  • 2021-02-10 14:20

    The clear color alpha of the FBO must be equal to 0 :

    glColorMask(TRUE, TRUE, TRUE, TRUE);
    glClearColor(0, 0, 0, 0);
    glClear(GL_COLOR_BUFFER_BIT);
    
    0 讨论(0)
  • 2021-02-10 14:27

    If you are trying to make the framebuffer transparent so you can render an object on top of your Desktop, you must know that that's not possible through Glut.

    This kind of effect is specific to the platform you are using. What is it? Linux? Windows? Mac OS X? You'll have to get your hands dirty (drop Glut out of the equation) and understand a little more about building windows.

    By the way, if your target is Windows you should check this:

    (win32) How to make an OpenGL rendering context with transparent background?

    0 讨论(0)
提交回复
热议问题