Jump to content
  • Advertisement
Sign in to follow this  

OpenGL glVertexColor4fv for solid, constant color specification.

This topic is 2653 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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);

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.

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!