0
votes

I'm encountering something really really strange.

I have a very simple program that renders a simple full-screen billboard using the following shader pipeline:

VERTEX SHADER:

#version 430

layout(location = 0) in vec2 pos;

out vec2 tex;

void main()
{
    gl_Position = vec4(pos, 0, 1);
    tex = (pos + 1) / 2;
}

FRAGMENT SHADER:

#version 430

in vec2 tex;

out vec3 frag_color;

void main()
{
    frag_color = vec3(tex.x, tex.y, 1);
}

The program always renders the quad in the correct positions (so I've ruled out the VAO as culprit), but for some reason ignores whatever values I set for tex and always set it to vec2(0,0), rendering a blue box.

Is there something I'm missing here? I've done many opengl apps before, and I've never encountered this. :/

1
Are the elements of pos + 1 always less than 2?Scraniel
yes. the box is bounded from (-1,-1) to (1,1). I can also do a direct assignment (eg: tex = vec2(0.5,0.5); ) and it still doesn't work.Andrew S. Allen
I was thinking it was doing integer division, but if direct assignment still gives you the same issue, perhaps not.Scraniel
Using a uniform, I can set color in the fragment shader. Uniforms don't work in the vertex shader (just like direct assignment)...Andrew S. Allen
Do you have alpha channel enabled? If so, you should output vec4 from fragment shader. Check your formats. Also, there should be layout(location = 0) for frag_color, but that shouldn't be the issue.Jaa-c

1 Answers

0
votes

I've seen implementations of OpenGL 2.0 having problems at compile time when adding floats and not explicitly casted integers.
Even if it is not a problem I would think possible on a 4.3 implementation, maybe you should just add dots and suffixes to your "integer" constants.

The last line of you're vertex shader seems to be the only one that could be a problem (I believe values are always casted in constructors :p ) so you would have something like this instead:

tex = (pos + 1.0f) / 2.0f;

Remember that you're shaders can compile on thousands of different implementations so it's a good habit to always be explicit!!!