PDA

View Full Version : Can't pass color to shader



redefrec
08-11-2014, 11:51 AM
Hi!

I don't know if this belongs here or in the GLSL category, but here goes:

This is the shader program I'm using:


#version 330 core

uniform mat4 modelViewProjection;

layout(location = 0) in vec3 modelSpaceVertexPosition;
layout(location = 1) in vec4 vertexColor;
layout(location = 2) in vec2 vertexTextureCoordinates;

out vec4 color;
out vec2 textureCoordinates;

void main() {
gl_Position = modelViewProjection * vec4(modelSpaceVertexPosition, 1);
color = vertexColor;
textureCoordinates = vertexTextureCoordinates;
}

#version 330 core

uniform sampler2D diffuseTexture;
in vec4 color;
in vec2 textureCoordinates;
out vec4 fragmentColor;

void main() {
fragmentColor = texture2D(diffuseTexture, textureCoordinates) * color;
}


I'm trying to edit the librocket sample to use this shader:

pastebin.com/ciVySD06

Everything is working fine except for vertexColor/color which is always (1,1,1,1).

I'm running out of ideas. What am I doing wrong?

Dan Bartlett
08-11-2014, 12:14 PM
What does your glVertexAttribPointer call look like for vertexColor? If you are passing in unsigned bytes are you setting the normalized argument to GL_TRUE to get [0.0 to 1.0] rather than [0.0 to 255.0]?

redefrec
08-11-2014, 12:31 PM
What does your glVertexAttribPointer call look like for vertexColor? If you are passing in unsigned bytes are you setting the normalized argument to GL_TRUE to get [0.0 to 1.0] rather than [0.0 to 255.0]?

That was it. I misunderstood the function of that parameters. Thank you very much.