glDrawElements only draws half a quad

*爱你&永不变心* 提交于 2019-12-12 14:19:50

问题


Here is my function:

void Object::draw2()
{

if(!mIsInitialised) { return; }

//Tell OpenGL about our vertex and normal data
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, &Vertices.front());

glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, 0, &Temp2.front());

//draw the .txt-file
glDrawElements(GL_TRIANGLES, Indices.size(), GL_UNSIGNED_INT, &Indices.front());

//restore the state GL back
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
}

My indices-vector contains: 1 2 3 1 3 4

My vertices-vector contains: -1 -1 0 1 -1 0 1 1 0 -1 1 0

When I run the program, it only draws half a quad - I.e a triangle.

The result -> http://i.stack.imgur.com/jZALG.png


回答1:


Your indices vector should contain:

0 1 2 0 2 3

Otherwise, you never touch the vertex number 0 and end up with the half of the quad.



来源:https://stackoverflow.com/questions/13298143/gldrawelements-only-draws-half-a-quad

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!