I'm trying to use vertex arrays to draw a reasonably large mesh, containing a large number of vertices. The textures have been determined from these and it's easy enough to draw in immediate mode along the lines of:
glBegin(GL_TRIANGLES) {
for ( int faceIdx = 0; faceIdx < nFaces; ++faceIdx )
glVertex3fv(&vertexArray[vIdx]);
glTexCoord2fv(&texCoord[vIdx++]);
glVertex3fv(&vertexArray[vIdx]);
glTexCoord2fv(&texCoord[vIdx++]);
glVertex3fv(&vertexArray[vIdx]);
glTexCoord2fv(&texCoord[vIdx++]);
}
}
glEnd();
However for readability, speed and the rest I want to use vertex arrays (with a view to moving to VBOs). Is there a way of getting around putting a single vertex into the array multiple times?
As I understand it at the moment it's necessary to specify each vertex of the mesh as many times as it appears in a face of the mesh, as each vertex identifies to multiple texture coordinates (the textures are captured from a real-world image of the object the mesh approximates), i.e. my vertex/tex coord array reads as if I'd filled it in immediate mode.
Is there any way to use vertex arrays, whilst specifying the texture coordinates, without using redundant (by which I mean repeated) vertices?
So it can be used in vertex shader.No matter with whether the texture has mipmap. Basically yes.
in display() function : GLuint texture; texture = LoadTexture("bubble. png"); glBindTexture(GL_TEXTURE_2D, texture);
1.0 Introduction. Texture mapping is a process of stretching a texture onto a 3D object; the applied texture will follow the 3D object as it transforms. Texture mapping is fun and beneficial but it can be challenging for beginners. Texture can also be distorted for a visual effect.
Texture coordinates specify the point in the texture image that will correspond to the vertex you are specifying them for. Think of a rectangular rubber sheet with your texture image printed on it, where the length of each side is normalized to the range 0-1.
A single vertex is comprised of all attributes that make up this single vertex. So two vertices that share the same position but have different texture coordinates are conceptually different vertices. So no, there is no simple way around repeating vertex positions for different texCoords.
But usually such vertex duplications are only neccessary in some rare regions (like sharp edges, because of different normals, or like in your case a texture seam). So do all your faces' corners really have different texCoords? Maybe you can pre-process your data a bit and find neighbouring faces that share positions and texCoords and can therefore share the vertex. I would be suprised if that wouldn't be the case for many many vertices and you end up with only a small bunch of duplicated vertices.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With