There are not a lot of questions on StackOverflow or anywhere else that address this “system” question. “The_Fiddler” likely knows the answer, but is too senior for a noob. I registered to see an answer, but did not find it. So after 12 years, here is the answer.
In your shader file, define;
uniform float screenHeight;
uniform float screenWidth;
Then you can access those values like;
float lerpValue = gl_FragCoord.y / screenHeight;
to keep it simple, I used screenHeight only. So that it is global, I initialized at the top of my .cpp file.
GLuint screenHeightUnf;
Then, in an InitializeProgram() function, I compiled the shaders and then “getted” (lol) the location of the fragment shader’s new uniform variable.
screenHeightUnf = glGetUniformLocation(theProgram, "screenHeight");
Then, in a new function that is called by GLSL upon reshape, I bound the program, passed the variable of screen height, and closed the binding.
void reshape (int w, int h)
{
glUseProgram(theProgram);
//glUniform1f(screenHeightUnf, 500.0f); // works
//glUniform1f(screenHeightUnf, 500); // works
//glUniform1ui(screenHeightUnf, h); // not works
glUniform1f(screenHeightUnf, h); // have to cast h to float in the front function part
glUseProgram(0);
...
}
After 12 years… I hope that you are no longer struggling with this. Though, I hope that some of the new noobs reading McKesson’s online book stumble upon this.