当前位置 : 主页 > 网络推广 > seo >

opengl – 使用glReadPixels检索位图时会丢失抗锯齿

来源:互联网 收集:自由互联 发布时间:2021-06-16
我用OpenGL编写程序.它实现了一个简单的功能:绘制一个茶壶.为了使它在屏幕上看起来不错,我启用了多重采样抗锯齿.确实如此.查看以下位图: 但是当我将它保存为bmp图片时,它看起来很
我用OpenGL编写程序.它实现了一个简单的功能:绘制一个茶壶.为了使它在屏幕上看起来不错,我启用了多重采样抗锯齿.确实如此.查看以下位图:

但是当我将它保存为bmp图片时,它看起来很糟糕.我用FBO和PBO来做.现在我在这里发布部分代码:

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

glGenRenderbuffers(1,&m_renderBufferColor);
glBindRenderbuffer(GL_RENDERBUFFER,m_renderBufferColor);
glRenderbufferStorage(GL_RENDERBUFFER,GL_RGB,
    m_subImageWidth,m_subImageHeight);
glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,
    GL_RENDERBUFFER,m_renderBufferColor);

glGenRenderbuffers(1,&m_renderBufferDepth);
glBindRenderbuffer(GL_RENDERBUFFER,m_renderBufferDepth);
glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT,
    m_subImageWidth,m_subImageHeight);
glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,
    GL_RENDERBUFFER,m_renderBufferDepth);

glBindFramebuffer(GL_FRAMEBUFFER,0);

glBindFramebuffer(GL_FRAMEBUFFER,m_frameBuffer);



glGenBuffers(1,m_subImageBuffer);
glBindBuffer(GL_PIXEL_PACK_BUFFER,m_subImageBuffer);
        glBufferData(GL_PIXEL_PACK_BUFFER,m_bufferSize,
            NULL,GL_STREAM_READ);

glBindFramebuffer(GL_FRAMEBUFFER,m_frameBuffer);

glBindBuffer(GL_PIXEL_PACK_BUFFER,m_subImageBuffer);
glPixelStorei(GL_PACK_ALIGNMENT,1);
//注意:以BGR的顺序读取
glReadPixels(0,0,m_subImageWidth,m_subImageHeight,
        GL_BGR,GL_UNSIGNED_BYTE,bufferOffset(0));
GLUtils::checkForOpenGLError(__FILE__,__LINE__);
m_subPixels[i] = static_cast<GLubyte*>(glMapBuffer(GL_PIXEL_PACK_BUFFER,GL_READ_ONLY));
gltGenBMP(subImageFile,GLT_BGR,m_subImageWidth,m_subImageHeight,m_subPixels[i]);
glBindBuffer(GL_PIXEL_PACK_BUFFER,0);
glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
glBindBuffer(GL_PIXEL_PACK_BUFFER,0);

我很好奇.为什么它们不同:渲染到默认的famebuffer并保存到bmp图片?

实际上,我想做的是在9个不同的相邻角度下获得9个小位图,然后合成一个位图以在立体3D屏幕上显示.但合成的位图看起来很糟糕.

有人能告诉我为什么吗?

仅仅因为你在帧缓冲区上启用多重采样并不意味着你的FBO也会拥有它.创建FBO时需要使用glRenderbufferStorageMultisample.

见:FBO Blitting is not working

并且:http://www.opengl.org/wiki/GL_EXT_framebuffer_multisample

这也是相关的:glReadPixels from FBO fails with multisampling

网友评论