2
votes

I am going through a render pass onto a FrameBufferObject such that I can use the result as a texture in the next rendering pass. Looking at tutorials, I need to call:

glBindFramebuffer(GL_TEXTURE2D, mFrameBufferObjectID);
glViewport(0, 0, mWidth, mHeight);

where mWidth and mHeight are the width and height of the frame buffer object. It seems without this glViewport call, nothing gets drawn correctly. What's strange is that upon starting the next frame, I need to call:

glViewport(0, 0, window_width, window_height);

so that I can go back to my previous width/height of the window; but calling it seems to only render my stuff at half of the original window size. So I physically only see a quarter of my screen gets stuff rendered onto (yes the entire scene is on it). I tried putting a break point and looking at the width and heigh values, they are the original values (1024, 640). Why is this happening? I tried doubling those and it correctly draws on my entire window.

I'm doing this on Mac via xcode and with glew.

2
The problem is probably in the code you didn't show. - Yakov Galka
Is this a Mac with a retina screen? You might have a mixup between resolutions in logical pixels and actual physical pixels on screen. Or whatever the correct terminology is... - Reto Koradi
Yes, I'm using this on Mac xcode. - ChaoSXDemon
On a Mac with a retina display, the frame buffer is larger than the window by 2x in each dimension. Your glViewport call with window_width and window_height needs to be adjusted for the screen. If you use glfw, this is how you retrieve them: glfw.org/docs/latest/window_guide.html#window_fbsize - lukegravitt

2 Answers

1
votes

Try adjusting the scissor box as well as the viewport if you have the scissor test enabled using

glEnable(GL_SCISSOR_TEST);

To fix your problem write

glViewport(0, 0, mWidth, mHeight);
glScissor(0, 0, mWidth, mHeight);

and

glViewport(0, 0, window_width, window_height);
glScissor(0, 0, window_width, window_height);

everytime when you switch to a new framebuffer with a different size as the previous one, or always just to be safe.

See this link of the reference glScissor Or this other post explaining the purpose of it https://gamedev.stackexchange.com/questions/40704/what-is-the-purpose-of-glscissor

0
votes

The viewport settings are stored in the global state. So if you change it, it stays at the new values until you call glViewport again. As you already noted, you'll have to set the size whenever you want to render to a FBO (or backbuffer) that has a different size then the previously bound one.