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.


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.


1 Answer 1


It sounds like your version of the opengl.h header is too old, and doesn't include the declarations for functions and constants from newer versions. Despite that the OpenGL implementation in the driver is 4.6, you won't be able to access the newer functionality without the appropriate declarations. You'll also need code to load the function addresses from the driver for newer functions (this is called a "loader").

There are a few different libraries/tools out there for this, but one I like is Glad, which is an online loader generator. It will generate a header and source file that you can download and add directly to your project in place of the usual opengl.h.

You can put in the version of OpenGL you want - probably 4.6 with "Compatibility" profile - that will include the "old-fashioned" stuff like immediate mode, which I think you said you were using. (You could use "Core" profile if you want to get rid of all deprecated stuff and only use modern OpenGL, but that may be a steeper learning curve.) You can also put in any extensions you want to use, and it will include their associated functions and constants in the generated loader.

  • 1
    $\begingroup$ Thank you very much for your help again ! I managed to do that, after a while spent not realising I do have the admin privileges to copy and paste the glad and KHR folders alongside the GL folder somewhere in the MinGW directory. Eventually everything compiled ok, but on running, my program crashed immediately, with an access violation message... $\endgroup$
    – Simon
    Dec 27, 2021 at 15:29
  • 2
    $\begingroup$ You might need to do some initialization call for Glad to run the loader and populate the function pointers. You can look at glad.h and see if you can find it (or maybe the Glad website has docs), or I can look at it a little while later. BTW, putting those files into the mingw directory is not really recommended :) You can just keep them in your project's source directory and include from there. $\endgroup$ Dec 27, 2021 at 15:48
  • 2
    $\begingroup$ BTW, do you know how to use the debugger in your IDE? If not, might be a good time to learn - it would have saved you the trouble of doing printfs and taken you directly to where it was crashing. $\endgroup$ Dec 27, 2021 at 15:51
  • 2
    $\begingroup$ OMG thanks so much ! I added if (!gladLoadGL()) { printf("Failed to initialize OpenGL context"); return -1; } after the line "EnableOpenGL(hwnd, &hDC, &hRC);" that came with the OpenGL template in Codeblocks, and things seem to work ! The line "const GLubyte* SHADINGLANGUAGESTRING = glGetString(GL_SHADING_LANGUAGE_VERSION);" now works, which is a good omen. I don't know whether I put "gladLoadGL()" in the right place, but I'm not one to look a gift horse in the mouth !! XD $\endgroup$
    – Simon
    Dec 27, 2021 at 16:14
  • 2
    $\begingroup$ If you're using brackets on your include, like #include <glad.h>, you might need to switch to quotes, like #include "glad.h". The former is used for system headers, and the latter for ones local to your own project. $\endgroup$ Dec 27, 2021 at 16:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.