Jump to content
  • Advertisement
Sign in to follow this  
golgoth

OpenGL Index UV coordinates!

This topic is 5410 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

to passed uv coordinates to opengl we use something like this: UV *l_uv = in_primitive->GetUV(); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, 0, l_uv); glMatrixMode(GL_TEXTURE); glPushMatrix(); glLoadIdentity(); but how do we passe indexed uv coordinates???? THX

Share this post


Link to post
Share on other sites
Advertisement
Put simply, you can't. You can only have one index, the array that you pass to glDrawElements, and all your arrays must be indexed by the indices it contains.

As an example, take a model of a cube, that has 8 vertices and 12 UV texture coords. It also has two index buffers: one for the vertices, one for the texture coords, each of which contain 12 * 3 indices (12 triangles in this cube model, three vertices each). There are no duplicate values in the vertex and texture coord arrays, which means that they take up less space on disk. However, when you come to draw this cube model, each vertex has three triangles that use it, and therefore three (potentially different) sets of texture coordinates. With only one index buffer, this can't occur. The solution is to create new arrays and one index buffer that references them all. The new vertex and texture coord arrays will contain some duplicates, but usually, they won't be any more than about 10-20% bigger than they were before. The following bit of code shows how to do this:


// Create the new vertex and texture coord arrays...
pNewMesh->m_pvTexCoords = new vec2_t[pNewMesh->m_uiNumTris * 3];
pNewMesh->m_pvVertices = new vec3_t[pNewMesh->m_uiNumTris * 3];

// Copy all the values from the old arrays to the new ones...
for(x = 0; x < pNewMesh->m_uiNumTris * 3; x++)
{

pNewMesh->m_pvTexCoords[x][0] = pvTexCoords[ pTexCoordIndicesList[x] ][0];
pNewMesh->m_pvTexCoords[x][1] = pvTexCoords[ pTexCoordIndicesList[x] ][1];

pNewMesh->m_pvVertices[x][0] = pvVertices[ pVertexIndicesList[x] ][0];
pNewMesh->m_pvVertices[x][1] = pvVertices[ pVertexIndicesList[x] ][1];
pNewMesh->m_pvVertices[x][2] = pvVertices[ pVertexIndicesList[x] ][2];

}

// Create the new index array...
pNewMesh->m_piIndices = new unsigned short[pNewMesh->m_uiNumTris * 3];

for(x = 0; x < pNewMesh->m_uiNumTris * 3; x += 3)
{

pNewMesh->m_piIndices[x] = x;
pNewMesh->m_piIndices[x + 1] = x + 1;
pNewMesh->m_piIndices[x + 2] = x + 2;

}



Then, when you come to render, you just load the arrays with the glVertexPointer and glTexCoordPointer functions, and send the index buffer to glDrawElements, as usual...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!