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 4 of 4

Thread: why glVertexAttrib does not work?

  1. #1
    Intern Contributor
    Join Date
    Mar 2011
    Posts
    87

    why glVertexAttrib does not work?

    i wrote a simple shader, in the vertex shader ,i declare a variable: in vect4 color;
    i use it like that gl_FrontColor = color;

    However , i want to change the value of color, so i wrote
    the following code ,but it does not change the color to red.
    why???can someone explain this to me ?
    void Shader::init(const char *vsFile, const char *fsFile)
    {
    ....;
    glShaderSource(...);
    glCompileShader(...);
    glAttachShader(...);

    .....;
    GLfloat c[]={1.0,0.0,0.0,1.0};
    GLint loc;
    loc=glGetAttribLocation(shader_id,"color");
    glVertexAttrib3fv(loc,c);
    glBindAttribLocation(shader_id,loc,"color");


    glLinkProgram(shader_id);
    }

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    2,882

    Re: why glVertexAttrib does not work?

    glGetAttribLocation queries the location assigned when you link the program. You haven't linked it yet.

    If you'd rather assign the location yourself instead of letting OpenGL assign it, use glBindAttribLocation before link.

    You should only call one or the other, not both. Take your pick -- whichever way you want to do it is fine. But make the call at the appropriate point relative to LinkProgram.

    There's also GLSL syntax to bind an attribute to a specific location in the shader, if you prefer. If you use that, you don't have to call either one of the above APIs.

    Your choice.

    See this for details:

    http://www.opengl.org/wiki/glVertexAttribPointer

  3. #3
    Intern Contributor
    Join Date
    Mar 2011
    Posts
    87

    Re: why glVertexAttrib does not work?

    could you write an examle of the correct order for me?

    i change the order like that:
    glBindAttribLocation(shader_id,0,"color");
    glVertexAttrib3fv(0,c);
    glLinkProgram(shader_id);

    but it still does not work....

  4. #4
    Intern Contributor
    Join Date
    Mar 2011
    Posts
    87

    Re: why glVertexAttrib does not work?

    it works!!!!!!!!!!!!thanks a lot

Posting Permissions

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