Creylon
Creylon

Reputation: 1

GLSL no rendering if gl_color is used

I am trying to render a texture in lwjgl using shaders. As soon as I use gl_Color in the vertex shader I got no ouput.

This is working:

#version 120

attribute vec2 position;
attribute vec2 texCoord;

varying vec2 fragmentCoord;

void main()
{
    gl_Position = gl_ModelViewProjectionMatrix * vec4(position, 0.0f, 1.0f);
    //gl_FrontColor = gl_Color;
    gl_FrontColor = vec4(1.0f, 1.0f, 1.0f, 1.0f);
    fragmentCoord = (gl_TextureMatrix[0] * vec4(texCoord, 0.0f, 1.0f)).xy;
}

This is not working:

#version 120

attribute vec2 position;
attribute vec2 texCoord;

varying vec2 fragmentCoord;

void main()
{
    gl_Position = gl_ModelViewProjectionMatrix * vec4(position, 0.0f, 1.0f);
    gl_FrontColor = gl_Color;
    gl_FrontColor = vec4(1.0f, 1.0f, 1.0f, 1.0f);
    fragmentCoord = (gl_TextureMatrix[0] * vec4(texCoord, 0.0f, 1.0f)).xy;
}

The fragment shader for both is:

#version 120

uniform sampler2D texture;

varying vec2 fragmentCoord;

void main()
{
    gl_FragColor = texture2D(texture, fragmentCoord) * gl_Color;
}

The same code works for a friend and I wonder why it doesnt for me.

What am I doing wrong?

Upvotes: 0

Views: 1089

Answers (1)

ClickerMonkey
ClickerMonkey

Reputation: 1941

The fragment shader should have this:

gl_FragColor = texture2D(texture, fragmentCoord) * gl_FrontColor;

Since gl_FrontColor is an output of the vertex shader... gl_Color is not.

Upvotes: 2

Related Questions