Results 1 to 3 of 3

Thread: Can't pass color to shader

  1. #1
    Newbie Newbie
    Join Date
    Aug 2014
    Posts
    2

    Can't pass color to shader

    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?

  2. #2
    Senior Member Regular Contributor
    Join Date
    Oct 2009
    Posts
    463
    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]?

  3. #3
    Newbie Newbie
    Join Date
    Aug 2014
    Posts
    2
    Quote Originally Posted by Dan Bartlett View Post
    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.

Similar Threads

  1. How to pass the color data to vertex shader(GLSL)
    By sc20184 in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 06-13-2017, 02:54 PM
  2. Replies: 1
    Last Post: 12-26-2014, 04:57 PM
  3. Replies: 1
    Last Post: 03-20-2014, 02:33 PM
  4. how do I pass color info to vertex shader?
    By zoefschildpad in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-19-2011, 09:37 PM
  5. Cannot pass color value to shader vertex attribute
    By Phinehas in forum OpenGL: Basic Coding
    Replies: 9
    Last Post: 10-05-2010, 09:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean