简体   繁体   中英

OpenGL framebuffer affected by size of window

I am using OpenGL with GLSL shaders to do some image processing. 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.

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). Can anyone understand why this is happening?

The second pic is after resizing the window to 3/4 its original height

http://i567.photobucket.com/albums/ss112/davidc538/rtip1.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)
  • Pass 2 writes tex1 (which is attached to fb1) to tex2 (fb2)
  • Pass 3 writes tex2 back to tex1
  • Pass 3 writes tex1 back to 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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