glVertexPointer and glTexCoordPointer

Started by
2 comments, last by Brother Bob 14 years, 5 months ago
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?
My timezone is GMT+1 so excuse my 'late' postings :)
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.
Ok, got it :)

Thanks for the insight
My timezone is GMT+1 so excuse my 'late' postings :)
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.

This topic is closed to new replies.

Advertisement