0

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. :/

7
  • Are the elements of pos + 1 always less than 2? Commented Nov 7, 2014 at 16:55
  • 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. Commented Nov 7, 2014 at 16:56
  • I was thinking it was doing integer division, but if direct assignment still gives you the same issue, perhaps not. Commented Nov 7, 2014 at 17:00
  • Using a uniform, I can set color in the fragment shader. Uniforms don't work in the vertex shader (just like direct assignment)... Commented Nov 7, 2014 at 17:20
  • 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. Commented Nov 7, 2014 at 17:24

1 Answer 1

0

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!!!

Sign up to request clarification or add additional context in comments.

1 Comment

Note that 1.0 is of type float in GLSL, unlike in C/C++, where it is double. So the f suffix is not needed, and actually not supported in some OpenGL versions, like OpenGL 2.0 and ES 2.0.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.