Why is my arrow drawing the wrong way?
I have this code to draw an 开发者_如何学Pythonarrow:
const GLfloat vertices[] = {
-0.25f, -0.25f,
0.0f, 0.0f,
0.25f, -0.25f,
0.0f, 0.5f,
};
glVertexPointer(2, GL_FLOAT, 0, vertices);
glEnableClientState(GL_VERTEX_ARRAY);
glColor4f(0.0f, 0.5f, 0.0f, 1.0f);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
It should draw similar to this:
This is the actual result (which is undesired):
I don't see what I have done wrong, the vertices seem correct to me, but it seems like OpenGL draws the polygon in a different order than I specified. Can anyone help me out? Thanks in advance. :)
Your triangle strip takes the lower three points first (i.e. the lower part of your green arrow) and then the right three points. Just change the order of points in your definition:
const GLfloat vertices[] = {
-0.25f, -0.25f,
0.0f, 0.0f,
0.0f, 0.5f,
0.25f, -0.25f,
};
精彩评论