简体   繁体   English

glDrawElements只绘制了半个四边形

[英]glDrawElements only draws half a quad

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 我的指数 - 矢量包含:1 2 3 1 3 4

My vertices-vector contains: -1 -1 0 1 -1 0 1 1 0 -1 1 0 我的顶点向量包含:-1 -1 0 1 -1 0 1 1 0 -1 1 0

When I run the program, it only draws half a quad - Ie a triangle. 当我运行程序时,它只绘制了半个四边形 - 即一个三角形。

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

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. 否则,您永远不会触摸顶点编号0并最终使用四边形的一半。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM