glVertexColor4fv for solid, constant color specification.

Started by
0 comments, last by Keebus 13 years ago
Hello community,

I have a problem I really cannot figure out myself. I've been skimming Google for the last three days with no luck, so in the end I decided to ask for help here. I'm writing a small rendering framework based on OpenGL 3.x Core.

Everything works fine with shaders and VBOs and I get some nice rendering. All this by specifying the vertex color through some VBO with glVertexAttribPointer, actually specifying a color for each vertex. The problem (no rendering) arises when I set the vertex position attribute with glVertexAttribPointer (a VBO with an array of three-floats vectors) but disable the VertexAttribArray at the vertex color attrib location and set it with glVertexAttribfv so to have only one single color for the entire mesh being rendered. Something like this:


void ShaderProgram::setConstantColor(const Color& color) const
{
glVertexAttrib4fv(mVertexColorLocation, color);
glDisableVertexAttribArray(mVertexColorLocation);
}


I've tried adding a glBindBuffer(GL_ARRAY_BUFFER, 0) before the glVertexAttrib command to make sure the color pointer is in client memory and not an offset on the video memory but no luck. Obviously I call that method right before rendering the mesh through a method that sets the vertex attrib pointer and calls glDrawElements.

This is the vertex shader:

#version 150\n
uniform mat4 fl_ProjectionMatrix;
uniform mat4 fl_ViewMatrix;
uniform mat4 fl_ModelMatrix;

in vec4 fl_VertexPosition;
in vec4 fl_VertexColor;

out vec4 fl_FrontColor;

void main() {
fl_FrontColor = fl_VertexColor;
gl_Position = fl_ProjectionMatrix * fl_ViewMatrix * fl_ModelMatrix * fl_VertexPosition;
}


While the fragment shader simply outputs the incoming front color. Last note: if I replace fl_FrontColor = fl_VertexColor with fl_FrontColor = vec4(1.0,0.0,0.0,1.0); I get an obvious red mesh as expected.

What could the problem be? Thanks for your attention and kindness.
K.
Advertisement
It's weird but the ONLY thing I did was binding the attrib locations to some static locations instead of reading them. Well it seems to be working now, thanks anyway.

This topic is closed to new replies.

Advertisement