I have just started using openGL which i am teaching myself from a book. In my book i am told to build quads using triangle strips because it is more efficient. The book uses these vertices to create the quad.
vertices.push_back(-0.5f);
vertices.push_back(0.0f);
vertices.push_back(0.0f);
vertices.push_back(0.5f);
vertices.push_back(0.0f);
vertices.push_back(0.0f);
vertices.push_back(-0.5f);
vertices.push_back(0.0f);
vertices.push_back(-1.0f);
vertices.push_back(0.5f);
vertices.push_back(0.0f);
vertices.push_back(-1.0f);
I don't understand why the z axis is not constant, it seems like the z axis should remain constant and the y axis should change to make the square display in 2d. I dont see why the z axis is used.
Here is the rest of the code
To load vertices in buffer
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * vertices.size(), &vertices[0], GL_STATIC_DRAW);
To display square
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(0.0, 5.0, 0.1, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glEnableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glVertexPointer(3, GL_FLOAT, 0, 0);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDisableClientState(GL_VERTEX_ARRAY);
Despite me not understanding this however, the square is still displayed properly, so it must work.