OpenGL appears to be using (far too aggressive) frustum culling which I can't see how to modify

656 Views Asked by At

I'm trying to get an OpenGL application working in c++. OpenGL appears to be culling far & near objects.

enter image description here

The screenshot should be a load of square tiles but the squares that are a certain distance too close or too far from the camera are not rendered. This means that only a narrow strip of the squares is actually rendered (between what I believe to be the near & far plane).

I'm not using frustum culling, the only culling I have enabled is back face culling. Does OpenGL have some sort of frustum culling on by default? Is there something that I need to enable using glEnable to get all of my triangles to actually render? Enabling GL_DEPTH_TEST stops absolutely everything from rendering no matter if I call glFrustum(...) afterwards.

Thanks.

2

There are 2 best solutions below

0
Paltoquet On

Somewhere in your code you should intialize a projectionMatrix:

auto projectionMatrix = glm::mat4 perspective(fovy, aspect, zNear, zFar);

or

auto projectionMatrix = gluPerspective(fovy, aspect, near, far); 

something like the line above. The zNear and zFar specify the lower and farest boundaries of your frustrum. Thoose values will map your fragment position to [-1, +1].

Every fragment with a z == near will be mapped to -1. Everything with a depth less than near will be discarded.

Try to find thoose near and far parameters and change their values to something that fit your scene. Avoid 0 as a near value, you can also try to move your camera to see some changes happening.

6
Jimmy Diddler On

Fixed. Not sure why but it was only rendering pieces of triangle that had their world coordinates (as opposed to coordinates relative to the camera) between 1 and -1. Fixed by using gluPerspective() rather than glMatrixMode(GL_PROJECTION) followed by a glFrustum(...) call.

Still none the wiser as to why it wasn't broken, but at least it's working now :)