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: VBO/VertexArrays: The UV coords have to be unique?

  1. #1
    Intern Contributor Godlike's Avatar
    Join Date
    May 2004
    Location
    Greece
    Posts
    62

    VBO/VertexArrays: The UV coords have to be unique?

    The most common format of a triangle mesh is to have a vector of vertex coords and one for the vertex indexes. But what happens with the UV coords in the case of VBOs and vertex arrays? Does every vertex has to have a unique UV coord or am I missing something here?

  2. #2
    Advanced Member Frequent Contributor Ehsan Kamrani's Avatar
    Join Date
    May 2005
    Location
    Iran
    Posts
    547

    Re: VBO/VertexArrays: The UV coords have to be unique?

    If your model has texture, you must specify (s,t ) (or (u,v ) ) as well to render the texture:

    Code :
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    BindVBO(GL_ARRAY_BUFFER, m_texCoordVboId );
    glTexCoordPointer( 2, GL_FLOAT, 0, NULL);

    If you don't specify the texture coordinates, your code won't have any idea about the texture coordinates and will not draw the texture(s).

    <span style="color: #006600">-Ehsan-</span>

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

    Re: VBO/VertexArrays: The UV coords have to be unique?

    Quote Originally Posted by Godlike
    The most common format of a triangle mesh is to have a vector of vertex coords and one for the vertex indexes. But what happens with the UV coords in the case of VBOs and vertex arrays? Does every vertex has to have a unique UV coord or am I missing something here?
    No, your UV coords (e.g. TEXCOORD0, etc.) don't have to be unique. You can assign them all the same value if you want. It's whatever your shaders will find useful. It's just "shader input data".

    And this has nothing to do with whether you use VBOs (server arrays), client arrays, display lists, or immediate mode. It doesn't matter to any of them. It's an independent issue.

  4. #4
    Intern Contributor Godlike's Avatar
    Join Date
    May 2004
    Location
    Greece
    Posts
    62

    Re: VBO/VertexArrays: The UV coords have to be unique?

    I know its shader data but since I have vert indices I render using glDrawElements:

    mesh->vbos.vertIndices.bind(); // Bind VBO
    glDrawElements( GL_TRIANGLES, mesh->vertIndices.size(), GL_UNSIGNED_SHORT, 0 );

    With this way (I think) that every index points to a unique vertex pos, unique vertex normal and unique vertex coord. If I have a mesh with N number of vertices I also have a N number of vertex normals and N number of tex coords so that the vertex indices act like a lookup table.

    Im I right? What am I missing here?

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

    Re: VBO/VertexArrays: The UV coords have to be unique?

    Quote Originally Posted by Godlike
    I know its shader data but since I have vert indices I render using glDrawElements:

    mesh->vbos.vertIndices.bind(); // Bind VBO
    glDrawElements( GL_TRIANGLES, mesh->vertIndices.size(), GL_UNSIGNED_SHORT, 0 );

    With this way (I think) that every index points to a unique vertex pos, unique vertex normal and unique vertex coord.
    The unique is the point of confusion. Unique "offset/address" in the buffer, but not necessary unique "contents/data". For instance, you can have the vertex position at index 0 be 1,2,3 and the vertex position at index 1 be 1,2,3 as well. You might do this for instance if this vertex is on a hard corner edge where you need different normals, one for each face.

    Similarly, you can (and frequently do) repeat indices in the index buffer (e.g. 0,1,2,2,1,3,...).

    If I have a mesh with N number of vertices I also have a N number of vertex normals and N number of tex coords so that the vertex indices act like a lookup table.
    Exactly.

Posting Permissions

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