gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 01:17:40 26 4
gpt4 key购买 nike

我使用OpenGL编写了一个程序。它实现了一个简单的功能:画一个茶壶。为了让它在屏幕上看起来更漂亮,我启用了多重采样抗锯齿。确实如此。看下面的位图:

enter image description here

但是当我将其保存为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);

enter image description here

我很好奇。 为什么它们不同:渲染到默认的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

关于opengl - 使用 glReadPixels 检索位图时抗锯齿丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11131104/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com