0
votes

I'm working with modern opengl, and my goal is to debug a viewing frustum culling. In order to achieve this, I created another viewport, so I can look at my entire model and my frustum moving while I'm moving in my principal program.

It works, but there is still a strange behaviour I don't understand... my viewport are :

glViewport(0,0, screenWidth, screenHeight)
//render my program with motionned camera
glViewport(screenWidth/2, screenHeight/2, screenWidth/2, screenHeight/2)
//render my MotionLess Camera

Since I'm stacking them, I'm wondering if it creates an undefined behavior? Because my result isn't what I expected. (Here's the better draw you'll see ever! : )

enter image description here

In fact, What I thought is that my screen would be like the part red and darker red => My program is rendered on the red part, and my motionless camera on the darker red. But the yellow part appeared => My motionned camera is rendered on the red screen, it's ok. But my motionless camera is rendered in the yellow part, and the rest of the darker red is black.

I show you with my real example :

enter image description here

Do you know from where does it come from?

** EDIT : ** As datenwolf mentionned, my problem is due to the face that I'm rendering to FBO. And it seems that you do not want to use a glViewport offset other than (0,0) when you render in FBO (see this : HereIsAnAnswer).

2

2 Answers

3
votes

(…) Since I'm stacking them, (…)

OpenGL viewports don't stack. Each call to glViewport replaces whatever viewport has been set before.

(EDIT): Also the viewport doesn't necessarily clip geometry that transforms outside of it, i.e. if the viewport is only a portion of the window then stuff "outside" of the viewport might still be visible. To make sure that you're actually clipping stuff outside the viewport, you have to combine it with scissor testing (glEnable(GL_SCISSOR_TEST)) and set the scissor rectangle to match with the viewport using glScissor(…).

-1
votes

This looks like somewhere you are rendering with clip space coordinates from 0..1 instead of -1..+1 (assuming that the "yellow" error part is what you want to appear across the whole of the dark red part).

So maybe in the vertex shader, you need to scale your vertices by 2 and subtract 1 to move from 0..1 coordinates to -1..+1 coordinates?

Also, it's glViewport(), but it's probably just a typo in the question.

Documentation on clip space and other coordinate systems used in OpenGL:

https://learnopengl.com/#!Getting-started/Coordinate-Systems