I am writing basic code to; draw triangles, lines etc; to translate and orient them, and to project them in perspective, solving the occlusion problem using the depth buffer.
Having had success with a hand-made projection matrix emulating what glFrustum
used to do before it was deprecated, I upgraded to a hand-made infinite projection matrix having no far clipping plane, based on what I've read in books. This mapped $z = -\infty$ in camera space to $z = 1$ in normalised device coordinates. This all worked, and allowed me for the first time, to use infinitely distant objects, i.e. objects having $w = 0$. These render correctly behind everything else, and exhibit no parallax, and no change in size. They move only when the camera orientation changes, as desired.
I was able to induce $z$-fighting by having the ratio of the distances of the far and near clipping planes nice and large, and making two very large distant triangles, one parallel to and not far behind the other. I did this in order to justify upgrading my projection matrix again, this time to a reversed-$z$ style, again based on what I've read in books. Having done so, I changed glDepthFunc(GL_LEQUAL)
to glDepthFunc(GL_GEQUAL)
and set glClearDepth(0.0f)
. The last step remaining seemed to be to set glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE)
. However, the IDE did not recognise the definitions of the two constant parameters. The specific errors from the IDE are "GL_LOWER_LEFT undeclared (first use in this function). Did you mean..." followed by a suggestion of something else with a similar spelling, and a similar error, for the other constant. I don't know if the problem is with the function itself - the IDE seemed not to object to it, in any case. I know that this function became available only in OpenGL version 4, however, my code reports, via const GLubyte* VERSIONSTRING = glGetString(GL_VERSION)
, that it is using version 4.6.0.
The only other time I've encountered a problem like this so far, was with const GLubyte* SHADINGLANGUAGESTRING = glGetString(GL_SHADING_LANGUAGE_VERSION)
. Here too, the constant parameter was not recognised.
There are more details here: How to use maximum resolution (pixel density) with OpenGL in MS Windows about the template that I have borrowed and modified, in case that helps diagnose the problem.
EDIT:
In case it is relevant, CodeBlocks' autocomplete did not recognise the command glClipControl
, whereas it did recognise the glGetString
, in spite of it not knowing the constant GL_SHADING_LANGUAGE_VERSION that I passed to glGetString
.