• Advertisement
Sign in to follow this  

glVertexPointer and glTexCoordPointer

This topic is 3032 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

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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.

Share this post


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

  • Advertisement