I'm a newcomer to OpenGL and I was playing around with drawing triangles with different z-coordinates. From what I understand, the z axis point out of the screen, and the -z axis points into the screen.

When I draw a square with 3 corners at a 0.0 z-coordinate, and the last corner at, say, 3.0 z-coordinate, I get this:

I don't understand how it's making this shape... I thought it would be something like this, since the 4th vertex is just 'far away'.

Can someone explain?

Edit: This is my vertex data

// vertex array
float vertices[] = {
-0.5f,  0.5f,  0.0f, 1.0f, 0.0f, 0.0f, // top left, first 3 are location, last 3 are color
0.5f,  0.5f,  0.0f, 0.0f, 1.0f, 0.0f, // top right
-0.5f, -0.5f,  -2.0f, 0.0f, 0.0f, 1.0f, // bottom left
0.5f, -0.5f,  0.0f, 1.0f, 1.0f, 1.0f // bottom right
};

// element buffer array
GLuint elements[] = {
0, 1, 2,
2, 1, 3
};


And I am calling the draw like:

glDrawElements(GL_TRIANGLES, 6,GL_UNSIGNED_INT,0);

• What transformations are you applying? Or are these coordinates directly in clip space with no transformations? And how are you triangulating the square? Feb 18, 2016 at 4:21
• No transformations, I edited my post to show code Feb 18, 2016 at 4:25