问题保存比窗口大的openGL FBO [英] problem saving openGL FBO larger than window
问题描述
我正在渲染到OpenGL屏幕外帧缓冲对象中,并喜欢将其另存为图像.请注意, FBO 大于显示尺寸.我可以渲染到屏幕外的缓冲区中并将其用作纹理,这可以正常工作.我可以使用偏移量将较大的纹理滚动"通过显示,这使我确信,我可以渲染到比窗口更大的上下文中.
I'm rendering into an OpenGL offscreen framebuffer object and like to save it as an image. Note that the FBO is larger than the display size. I can render into the offscreen buffer and use it as texture, which works. I can "scroll" this larger texture through the display using an offset, which makes me confident, that I render into a larger context than the window.
如果我将屏幕外缓冲区保存到图像文件中,则始终会被裁剪.保存的代码片段为:
If I save the offscreen buffer to an image file it always gets cropped. The code fragment for saving is:
void ofFBOTexture::saveImage(string fileName) {
glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
// get the raw buffer from ofImage
unsigned char* pixels = imageSaver.getPixels();
glReadPixels(0, 0, 1024, 1024, GL_RGB, GL_UNSIGNED_BYTE, pixels);
imageSaver.saveImage(fileName);
}
请注意,已裁剪图像内容,正确保存了可见部分(这意味着像素格式,GL_RGB问题等没有错误),但是剩余空间填充了一种颜色.
Please note, that the image content is cropped, the visible part is saved correctly (which means no error in pixel formats, GL_RGB issues etc.), but the remaining space is filled with one color.
所以,我的问题是-我在做什么错了?
So, my question is - what am I doing wrong?
推荐答案
最后,我解决了这个问题.
Finally I solved the issue.
我必须激活fbo才能保存其内容:
I have to activate the fbo for saving its contents:
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
// save code
...
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
,而仅通过
为glReadPixels
选择fbo
while only selecting the fbo for glReadPixels
via
glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
不够.
(所有其他经过纠正和测试的事物,例如视口大小,缓冲区的宽度和高度,图像纹理等)
(All other things where correct and tested, eg. viewport sizes, width and height of buffer, image texture etc.)
这篇关于问题保存比窗口大的openGL FBO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!