简体   繁体   English

OpenGL帧缓冲区受窗口大小的影响

[英]OpenGL framebuffer affected by size of window

I am using OpenGL with GLSL shaders to do some image processing. 我正在将OpenGL与GLSL着色器一起使用以进行某些图像处理。 I'm basically using framebuffers with an orthographic projection to render my image multiple times (each with different settings for the fragment shader). 我基本上是使用带有正交投影的帧缓冲区多次渲染我的图像(每个片段着色器都有不同的设置)。

I then have 2 framebuffers with textures attached to them that I render back and forth between (eg. tex1 is attached to fb1, tex2 is attached to fb2. first pass renders the input texture into fb1, second pass renders tex1 into fb2, 3rd pass renders tex2 into fb1... back and forth) until the final pass renders from whatever texture into an output framebuffer. 然后,我有2个帧缓冲区,并在它们之间来回渲染纹理(例如,tex1附着到fb1,tex2附着到fb2。第一遍将输入纹理渲染到fb1,第二遍将tex1渲染到fb2,第三遍将tex2渲染为fb1 ...(来回),直到最后一遍从任何纹理渲染到输出帧缓冲区为止。

All of this is done using orthographic projections so none of the image should be missing. 所有这些操作都是使用正交投影完成的,因此不会丢失任何图像。 This all works fine until the window is resized. 在调整窗口大小之前,所有这些都可以正常工作。 If I decrease the height of the window by half the image ends up only being drawn in the top half of the window that's left (this is for one pass, 2 passes and it will end up only in the top 1/4 of the window). 如果我将窗口的高度减小一半,则图像最终只会在剩下的窗口的上半部分绘制(这是一遍,两遍,并且最终只会在窗口的上半部分1/4处绘制) )。 Can anyone understand why this is happening? 谁能理解为什么会这样?

The second pic is after resizing the window to 3/4 its original height 第二张图片是将窗口调整为原始高度的3/4之后

http://i567.photobucket.com/albums/ss112/davidc538/rtip1.png http://i567.photobucket.com/albums/ss112/davidc538/rtip1.png

http://i567.photobucket.com/albums/ss112/davidc538/rtip2.png http://i567.photobucket.com/albums/ss112/davidc538/rtip2.png

Looks like you're not updating your texture dimensions when the resize occurs. 调整大小时似乎没有更新纹理尺寸。 ie your window has resized, but you're still blitting to its initial dimensions. 也就是说,您的窗口已调整大小,但您仍在尝试初始化其初始尺寸。

  • Pass 1 writes tex1 (which is attached to fb1) 传递1写入tex1(已附加到fb1)
  • Pass 2 writes tex1 (which is attached to fb1) to tex2 (fb2) 第2遍将tex1(附加到fb1)写入tex2(fb2)
  • Pass 3 writes tex2 back to tex1 第三遍将tex2写回到tex1
  • Pass 3 writes tex1 back to tex2 第三遍将tex1写回到tex2

That would mean you are shrinking/enlarging your image on every pass. 这意味着您每次通过都会缩小/放大图像。

You can avoid this by updating your fbo's during the resize (I'd advise rounding to the nearest larger power-of-two), or by leaving the fbo's at a fixed size and always rendering to the full window (although your image would be blurry when rendered to a large window). 您可以通过在调整大小时更新fbo来避免这种情况(我建议四舍五入到最接近的较大的2的幂),或者通过将fbo保持固定大小并始终渲染到整个窗口(尽管图像会渲染到大窗口时模糊不清)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM