Draw the contents of the render buffer Object

♀尐吖头ヾ 提交于 2019-12-05 03:25:05

问题


Do not quite understand the operation render buffer object. For example if I want to show what is in the render buffer, I must necessarily do the render to texture?

    GLuint fbo,color_rbo,depth_rbo;

    glGenFramebuffers(1,&fbo);
    glBindFramebuffer(GL_FRAMEBUFFER,fbo);

    glGenRenderbuffersEXT(1, &color_rb);
    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, color_rb);
    glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, 256, 256);
    glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,GL_RENDERBUFFER_EXT, color_rb);

    glGenRenderbuffersEXT(1, &depth_rb);
    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth_rb);
    glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, 256, 256);
    glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,GL_RENDERBUFFER_EXT, depth_rb);

    if(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)!=GL_FRAMEBUFFER_COMPLETE_EXT)return 1;

    glBindFramebuffer(GL_FRAMEBUFFER,0);

    //main loop    

    //This does not work :-(
    glBindFramebuffer(GL_FRAMEBUFFER,fbo);
    glClearColor(0.0,0.0,0.0,1.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    drawCube();
    glBindFramebuffer(GL_FRAMEBUFFER,0);

any idea?


回答1:


You are not going to see anything when you draw to an FBO instead of the default framebuffer, that is part of the point of FBOs.

Your options are:

  1. Blit the renderbuffer into another framebuffer (in this case it would probably be GL_BACK for the default backbuffer)

  2. Draw into a texture attachment and then draw texture-mapped primitives (e.g. triangles / quad) if you want to see the results.

Since 2 is pretty self-explanatory, I will explain option 1 in greater detail:

/* We are going to blit into the window (default framebuffer)                     */
glBindFramebuffer (GL_DRAW_FRAMEBUFFER, 0);
glDrawBuffer      (GL_BACK);              /* Use backbuffer as color dst.         */

/* Read from your FBO */
glBindFramebuffer (GL_READ_FRAMEBUFFER, fbo);
glReadBuffer      (GL_COLOR_ATTACHMENT0); /* Use Color Attachment 0 as color src. */

/* Copy the color and depth buffer from your FBO to the default framebuffer       */
glBlitFramebuffer (0,0, width,height,
                   0,0, width,height,
                   GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT,
                   GL_NEAREST);

There are a couple of things worth mentioning here:

First, blitting from one framebuffer to another is often measurably slower than drawing two textured triangles that fill the entire viewport. Second, you cannot use linear filtering when you blit a depth or stencil image... but you can if you take the texture mapping approach (this only truly matters if the resolution of your source and destination buffers differ when blitting).

Overall, drawing a textured primitive is the more flexible solution. Blitting is most useful if you need to do Multisample Anti-Aliasing, because you would have to implement that in a shader otherwise and multisample texturing was added after Framebuffer Objects; some older hardware/drivers support FBOs but not multisample color (requires DX10 hardware) or depth (requires DX10.1 hardware) textures.



来源:https://stackoverflow.com/questions/22102586/draw-the-contents-of-the-render-buffer-object

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!