Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 -> https://i.sstatic.net/jZALG.png

like image 435
Nilzone- Avatar asked Dec 29 '25 23:12

Nilzone-


1 Answers

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.

like image 116
Sergey K. Avatar answered Jan 01 '26 13:01

Sergey K.