Draw a pentagon using vertex arrays?
Posted: Fri Mar 02, 2012 3:23 am
The rectangle way goes like this:
But I'm not seeing this work for, say, a pentagon or octagon. For a rectangle, conveniently a set of 4 verts you can take the first 3 and draw a triangle and then the last 3 and draw a triangle. On paper, I'm not seeing this work for a pentagon.
Thoughts?
And if not, I'm sure I'll eventually self-solve and post answer.
Code: Select all
const int VertCount = 4; // Rectangle
const GLfloat Vertex2f [] =
{
drawRect.x1, y1,
drawRect.x2, y1,
drawRect.x2, y2,
drawRect.x1, y2,
};
const GLfloat TexCoord2f[] =
{
drawRect.left, drawRect.top, // Top
drawRect.right, drawRect.top, // Right
drawRect.right, drawRect.bottom, // Bottom
drawRect.left, drawRect.bottom, // Left
};
glEnable (GL_TEXTURE_2D);
glBindTexture (GL_TEXTURE_2D, TexSlot);
// size (Specifies the number of coordinates per array element), type (GL_FLOAT, etc), stride, pointer
glTexCoordPointer (2, GL_FLOAT, 0, TexCoord2f);
glEnableClientState (GL_TEXTURE_COORD_ARRAY);
glVertexPointer (2, GL_FLOAT, 0, Vertex2f);
glEnableClientState (GL_VERTEX_ARRAY);
glDrawArrays (GL_TRIANGLE_FAN, 0, VertCount); // First, count
glDisableClientState (GL_VERTEX_ARRAY);
glEnableClientState (GL_TEXTURE_COORD_ARRAY);
Thoughts?
And if not, I'm sure I'll eventually self-solve and post answer.