<p>Okay. So after 6 hours of tinkering with my code, trying different approaches and googling for solutions, I found this page:</p>

<p><a href="http://www.glprogramming.com/red/chapter03.html" rel="nofollow">http://www.glprogramming.com/red/chapter03.html</a></p>

<p>There is a short C listing which put me on the right track to solve this.</p>

<p>What I did wrong was that I should have set the frustum to something like this:</p>

<pre><code>GLdouble x0 = -(1366/768);
GLdouble x1 = 1366/768;
glFrustum(x0, x1, -1, 1, 1, 100);
// the last two values aren't critical, as long as they are positive
</code></pre>

<p>But before that, I should have set the <strong>glViewport</strong> properly, before setting up the frustum:</p>

<pre><code>glViewport(0, 0, 1366, 768);
</code></pre>

<p><strong>I didn't do it and that's why my code produced such weird results.</strong></p>

<p>Now I can create a unit cube with following vertices:</p>

<pre><code>0.0, 1.0, 0.0
1.0, 1.0, 0.0
1.0, 0.0, 0.0
0.0, 0.0, 0.0
0.0, 1.0, 1.0
1.0, 1.0, 1.0
1.0, 0.0, 1.0
0.0, 0.0, 1.0
</code></pre>

<p>And it will display properly as a cube of size 1 in every direction.</p>

CC BY-SA 3.0
2016-02-27T01:22:06.027Z
To expand a little on the solution you found: with values like 1366 and 768 in `glFrustum`, you were effectively setting an extremely wide field of view (nearly 180 degrees), which caused extreme perspective distortion; that's why the cube looked weirdly stretched out. You might prefer to use `gluPerspective` instead of `glFrustum`, as the parameters there are more intuitive.
Nathan Reed
CC BY-SA 3.0
2016-02-26T22:46:50.040Z
2016-02-26T22:46:50.040Z
Paweł Pela
<p>I'm beginner in OpenGL and I stumbled into a problem. I'm in OpenGL 2.1 for the time being, if that's of any help. </p>

<p>I set my Frustum as such:</p>

<pre><code>glFrustum(-1366, 1366, -768, 768, 1, 20000);
</code></pre>

<p>Now, when I create a cube from quads like this:</p>

<pre><code>0.0, 500.0, 0.0
500.0, 500.0, 0.0
500.0, 0.0, 0.0
0.0, 0.0, 0.0
0.0, 500.0, 500.0
500.0, 500.0, 500.0
500.0, 0.0, 500.0
etc.
</code></pre>

<p>It is not a cube, as I expected. It's extremely stretched along the z axis.</p>

<p>Here's a screenshot of how it looks now: <a href="https://www.dropbox.com/s/diznfumtev7g259/Screenshot%20from%202016-02-26%2017%3A01%3A58.png?dl=0" rel="nofollow">https://www.dropbox.com/s/diznfumtev7g259/Screenshot%20from%202016-02-26%2017%3A01%3A58.png?dl=0</a> (I removed one of the faces temporarily)</p>

<p>The shape starts to resemble a cube a bit when I change the vertices to:</p>

<pre><code>0.0, 500.0, 0.0
500.0, 500.0, 0.0
500.0, 0.0, 0.0
0.0, 0.0, 0.0
0.0, 500.0, 0.3
500.0, 500.0, 0.3
500.0, 0.0, 0.3
etc.
</code></pre>

<p>Code related to this (I am translating this from assembly which I am actually using).</p>

<p>Matrices setup on initialization:</p>

<pre><code>glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1366.0, 1366.0, -768.0, 768.0, 1.0, 20000.0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
</code></pre>

<p>Transformations of the cube inside the "render()" function:</p>

<pre><code>glLoadIdentity();
glTranslated(1000.0, 500.0, 0.0);
glRotated(degrees, 0.0, 0.0, 1.0); // degrees is +=2 every frame
glTranslated(-250.0, -250.0, distance); // distance is -=0.001 every frame
</code></pre>

<p>There are no other matrix operations in the code.</p>

<p>The code uses GLUT to initialize a window with double buffer and depth buffer. Depth testing is enabled.</p>

<p>It all seems to work as expected, the rotation is ok, movement also. I am only troubled by the fact that when I define a 500.0x500.0x500.0 cube, the actual output is not a cube.</p>

<p>What am I doing wrong? How to fix this?</p>

CC BY-SA 3.0
2016-02-26T14:20:59.543Z
Its a bit hard to say what something looks like depends on where your camera is and whet Leese you have going on in the scene.
joojaa
CC BY-SA 3.0
2016-02-26T14:39:16.877Z
There is only this one cube in the scene. It is slowly rotating around its z axis and slowly going into the distance (this seems to work fine).
Paweł Pela
CC BY-SA 3.0
2016-02-26T14:58:51.237Z
Yes, but that does not help us if we cant see your matrix, etc. You dont have any code that i can help you with. Your supposed to give minimal code to reproduce the problem otherwise theres no debugging to be had. Yes cubes can look very elongated if they are very close to the camera plane.
joojaa
CC BY-SA 3.0
2016-02-26T15:52:36.163Z
@joojaa sorry. I was a bit reluctant to provide any additional code because I am writing all of this in assembly. I supposed that would not help if I posted it here :)
Paweł Pela
<opengl>
Frustum - problem with z dimension
Paweł Pela
# Frustum - problem with z dimension

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

I'm beginner in OpenGL and I stumbled into a problem. I'm in OpenGL 2.1 for the time being, if that's of any help.

I set my Frustum as such:

```
glFrustum(-1366, 1366, -768, 768, 1, 20000);

```

Now, when I create a cube from quads like this:

```
0.0, 500.0, 0.0
500.0, 500.0, 0.0
500.0, 0.0, 0.0
0.0, 0.0, 0.0
0.0, 500.0, 500.0
500.0, 500.0, 500.0
500.0, 0.0, 500.0
etc.

```

It is not a cube, as I expected. It's extremely stretched along the z axis.

Here's a screenshot of how it looks now: <https://www.dropbox.com/s/diznfumtev7g259/Screenshot%20from%202016-02-26%2017%3A01%3A58.png?dl=0> (I removed one of the faces temporarily)

The shape starts to resemble a cube a bit when I change the vertices to:

```
0.0, 500.0, 0.0
500.0, 500.0, 0.0
500.0, 0.0, 0.0
0.0, 0.0, 0.0
0.0, 500.0, 0.3
500.0, 500.0, 0.3
500.0, 0.0, 0.3
etc.

```

Code related to this (I am translating this from assembly which I am actually using).

Matrices setup on initialization:

```
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1366.0, 1366.0, -768.0, 768.0, 1.0, 20000.0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

```

Transformations of the cube inside the "render()" function:

```
glLoadIdentity();
glTranslated(1000.0, 500.0, 0.0);
glRotated(degrees, 0.0, 0.0, 1.0); // degrees is +=2 every frame
glTranslated(-250.0, -250.0, distance); // distance is -=0.001 every frame

```

There are no other matrix operations in the code.

The code uses GLUT to initialize a window with double buffer and depth buffer. Depth testing is enabled.

It all seems to work as expected, the rotation is ok, movement also. I am only troubled by the fact that when I define a 500.0x500.0x500.0 cube, the actual output is not a cube.

What am I doing wrong? How to fix this?

**Tags:** opengl

> **Comments:**
> **username_1**: Its a bit hard to say what something looks like depends on where your camera is and whet Leese you have going on in the scene.  
> **username_0**: There is only this one cube in the scene. It is slowly rotating around its z axis and slowly going into the distance (this seems to work fine).  
> **username_1**: Yes, but that does not help us if we cant see your matrix, etc. You dont have any code that i can help you with. Your supposed to give minimal code to reproduce the problem otherwise theres no debugging to be had. Yes cubes can look very elongated if they are very close to the camera plane.  
> **username_0**: @username_1 sorry. I was a bit reluctant to provide any additional code because I am writing all of this in assembly. I supposed that would not help if I posted it here :)  

---

## 1 answers

### Answer by username_0 on 2016-02-26. Score: 2 | Accepted answer

Okay. So after 6 hours of tinkering with my code, trying different approaches and googling for solutions, I found this page:

<http://www.glprogramming.com/red/chapter03.html>

There is a short C listing which put me on the right track to solve this.

What I did wrong was that I should have set the frustum to something like this:

```
GLdouble x0 = -(1366/768);
GLdouble x1 = 1366/768;
glFrustum(x0, x1, -1, 1, 1, 100);
// the last two values aren't critical, as long as they are positive

```

But before that, I should have set the **glViewport** properly, before setting up the frustum:

```
glViewport(0, 0, 1366, 768);

```

**I didn't do it and that's why my code produced such weird results.**

Now I can create a unit cube with following vertices:

```
0.0, 1.0, 0.0
1.0, 1.0, 0.0
1.0, 0.0, 0.0
0.0, 0.0, 0.0
0.0, 1.0, 1.0
1.0, 1.0, 1.0
1.0, 0.0, 1.0
0.0, 0.0, 1.0

```

And it will display properly as a cube of size 1 in every direction.

> **Comments:**
> **username_2**: To expand a little on the solution you found: with values like 1366 and 768 in `glFrustum`, you were effectively setting an extremely wide field of view (nearly 180 degrees), which caused extreme perspective distortion; that's why the cube looked weirdly stretched out. You might prefer to use `gluPerspective` instead of `glFrustum`, as the parameters there are more intuitive.  

---

