Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Can't pass color to shader

Hybrid View

  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
    Member Regular Contributor
    Join Date
    Aug 2008
    Posts
    457
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •