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

Thread: OpenGL 2.0 define custom vertex attributes

  1. #1
    Intern Contributor
    Join Date
    Sep 2013
    Posts
    89

    OpenGL 2.0 define custom vertex attributes

    Hi there.

    I am working with an application which uses OpenGL 2.0.
    I have vertex data, I have index data and I render both via a glDrawElements.
    I am also using a custom vertex and fragment shader.

    The vertex data consists of only:
    glVertexPointer(4, GL_FLOAT, stride, offsetV);
    glTexCoordPointer(4, GL_FLOAT, stride, offsetT);
    and
    glColorPointer(4, GL_FLOAT, stride, offsetC);

    My problem is, I would like to define another attribute per vertex which is not part of the fixed function pipeline.
    How could I do this? I know, I could just abuse one of the other pre-defined attributes like "glSecondaryColorPointer" but if possible I would rather define my own attribute which I can add to my vertex data.

    Thank you very much for the great help.

  2. #2
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    495
    Quote Originally Posted by Cornix View Post
    My problem is, I would like to define another attribute per vertex which is not part of the fixed function pipeline.
    How could I do this?
    You define the attribute in the vertex shader, as a global variable with an "in" qualifier. You can optionally use a layout qualifier to specify the index, or use glGetAttribLocation() in the application. The data for the attribute is provided using glVertexAttribPointer().

  3. #3
    Intern Contributor
    Join Date
    Sep 2013
    Posts
    89
    Wow, thank you. This is much simpler then I originally thought.

  4. #4
    Advanced Member Frequent Contributor arekkusu's Avatar
    Join Date
    Nov 2003
    Posts
    783
    Be warned: the aliasing of generic attribute locations to legacy built-in attribute locations is undefined. So if you use a layout qualifier (or glBindAttribLocation) it is your responsibility to carefully choose a location that will not collide (see ARB_vertex_program, circa 2002, Table X.1, "Generic and Conventional Vertex Attribute Mappings".)

    Generally, it is simpler if you convert everything to generic attributes.

  5. #5
    Intern Contributor
    Join Date
    Sep 2013
    Posts
    89
    Yes, thank you. I was thinking about that already, just removing the build-in attributes and only using my own now that I know that I can do this.

Posting Permissions

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