I'm new to OpenGL, and trying to figure out my fragment shader. I have a rectangle drawn in my window, and I'd like to color the top half of it a different color (say blue), without hard-coding the height of the pixels.
With a window height of 1000, in my fragment shader, I have:
void main(){
if((gl_FragCoord.y) > 500)
{
color = vec3(.3, .3, 1);
}
else
{
color = fragmentColor;
}
Which colors the top half of the rectangle blue. But what if I'd like to get the window height from inside my fragment shader instead of just using 500 pixels? I initialized
uniform vec2 windowSize, and am trying to use glUniform1i() to place the window height in this variable, but I don't know how.
glUniform2fto set thewindowSizebecause it's avec2. - rwolsglGetUniformLocation, and then use that "handle" as the first argument forglUniform2f. The second and third arguments forglUniform2fcan be whatever you want. - rwolsglUniformin the hosts programs display/drawing routine. - datenwolf