# glVertexPointer and glTexCoordPointer

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

## Recommended Posts

I am in a 2D scenario where I need glVertexPointer, indexed arrays and texture coordinates. Now I specify my vertex array as GLfloat vertices[8*2]; so I have 8 vertices, each two components (x,y) and enable them
 glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, sizeof(GLfloat)*2, vertices);  
In addition to that I specify an index list of GLuint indices[3*2*3]; I want to have triangles, two triangles form a "quad" and I want to have 3 "quads". So total amout is 18 elements. The drawing with
  glDrawElements(GL_TRIANGLES,18, GL_UNSIGNED_INT,  indices);

works great, so everything is in place. But unfortunately I struggle with texture coordinates. Is it possible to specify multiple texture coordinates per vertex? In my case I would need 3*2*3 coords, since the geometry is textured in a non-linear way. Or can I only specify as many tex coords as vertices (8) in my case?

##### Share on other sites
Two vertices that have different texture coordinates are not the same vertex, and so cannot be shared by the same index. Don't share indices based on the vertex position attribute alone, you need to share vertices based on all attributes. In this case, you probably need 18 vertices and 18 indices, because that's how many unique vertices you really have.

##### Share on other sites
Ok, got it :)

Thanks for the insight

##### Share on other sites
It just occurred to me that you will end up with 12 vertices, not 18. The diagonal of each quad is shared by two triangles. But still, you need more than the 8 vertices you first had. The shared edges between quads, however, cannot be shared in general.

1. 1
Rutin
34
2. 2
3. 3
4. 4
5. 5

• 12
• 14
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
633334
• Total Posts
3011409
• ### Who's Online (See full list)

There are no registered users currently online

×