<p>The post-projective Z range in OpenGL extends between &minus;1 and 1. So, a Z-value of 2 is out of range and will be clipped by the far plane.</p>

<p>The reason the square appears with a quadrant missing is that it's split into triangles from bottom left to top right, and so each triangle has two vertices with Z = 0 and one vertex with Z = 2. So, interpolating along the triangle, it hits Z = 1 (the far plane) halfway across, and everything beyond that is clipped. This results in half of each triangle disappearing.</p>

<p>BTW, you'll need a perspective projection matrix in order for far-away objects to appear smaller on screen. With no projection matrix, you're effectively using a parallel projection.</p>

CC BY-SA 3.0
2016-02-18T04:35:46.963Z
2016-02-18T04:35:46.963Z
Nathan Reed
<p>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. </p>

<p>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:</p>

<p><a href="https://i.sstatic.net/GL2Mu.png" rel="noreferrer"><img src="https://i.sstatic.net/GL2Mu.png" alt="wat"></a></p>

<p>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'.</p>

<p><a href="https://i.sstatic.net/Dmw2A.png" rel="noreferrer"><img src="https://i.sstatic.net/Dmw2A.png" alt="enter image description here"></a></p>

<p>Can someone explain?</p>

<p><strong>Edit:</strong> This is my vertex data</p>

<pre><code>// 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
};
</code></pre>

<p>And I am calling the draw like:</p>

<pre><code>glDrawElements(GL_TRIANGLES, 6,GL_UNSIGNED_INT,0);
</code></pre>

CC BY-SA 3.0
2016-02-18T04:21:46.547Z
What transformations are you applying? Or are these coordinates directly in clip space with no transformations? And how are you triangulating the square?
Nathan Reed
CC BY-SA 3.0
2016-02-18T04:25:14.960Z
No transformations, I edited my post to show code
Chara
<opengl>
Confused about z-axis behaviour
Chara
# Confused about z-axis behaviour

(Asked by: username_0 on 2016-02-18)

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:

[![wat](https://i.sstatic.net/GL2Mu.png)](https://i.sstatic.net/GL2Mu.png)

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'.

[![enter image description here](https://i.sstatic.net/Dmw2A.png)](https://i.sstatic.net/Dmw2A.png)

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);

```

**Tags:** opengl

> **Comments:**
> **username_1**: What transformations are you applying? Or are these coordinates directly in clip space with no transformations? And how are you triangulating the square?  
> **username_0**: No transformations, I edited my post to show code  

---

## 1 answers

### Answer by username_1 on 2016-02-18. Score: 5 | Accepted answer

The post-projective Z range in OpenGL extends between −1 and 1. So, a Z-value of 2 is out of range and will be clipped by the far plane.

The reason the square appears with a quadrant missing is that it's split into triangles from bottom left to top right, and so each triangle has two vertices with Z = 0 and one vertex with Z = 2. So, interpolating along the triangle, it hits Z = 1 (the far plane) halfway across, and everything beyond that is clipped. This results in half of each triangle disappearing.

BTW, you'll need a perspective projection matrix in order for far-away objects to appear smaller on screen. With no projection matrix, you're effectively using a parallel projection.


---

