Hey people. I have a problem with 3D projection in my project.

(Before I start, I’m using C# and OpenTK bindings but it really shouldn’t make a difference)

Post from another forum:

So, I’ve played around with 3D perspective and got everything working nicely with non-deprecated OpenGL but I have a problem.

I render a rotating rectangle (textured) and it rotates (roll) fine but when I pitch it down a bit and keep rolling it I get clipping on the left and right.

Here’s a sceeenshot:

and here’s the shader code as I think the problem is there:

```
#version 110
uniform float timer;
uniform mat4 window_matrix;
uniform mat4 model_matrix;
uniform int animated;
uniform int frames;
uniform int current_frame;
attribute vec2 texcoord;
attribute vec4 position;
varying vec2 frag_texcoord;
mat4 view_frustum(
float angle_of_view,
float z_near,
float z_far
) {
return mat4(
vec4( 1.0 / tan(angle_of_view), 0.0, 0.0, 0.0),
vec4( 0.0, 1.0 / tan(angle_of_view), 0.0, 0.0),
vec4( 0.0, 0.0, (z_far + z_near) / (z_far - z_near), 0.1),
vec4( 0.0, 0.0, -2.0 * z_far * z_near / (z_far - z_near), 1.0)
);
}
void main() {
vec2 temp = texcoord;
if (animated == 1) {
float step = 1.0 / float(frames);
if ( temp.x == 0.0 ){
temp.x = step * float(current_frame);
} else if ( temp.x == 1.0) {
temp.x = step * float(current_frame) + step;
}
}
frag_texcoord = temp;
gl_Position = window_matrix * model_matrix * view_frustum( radians( 60.0 ), 0.0, 100.0 ) * position;
}
```

I did some debugging and it appears the the clipping appears where the z coordinate is >1 or <-1 which didn’t really make sense to me since the polygon isn’t even supposed to rotate that way to make that position possible.

If there’s nothing wrong with my shader code and you think it’s something else I can post other code (the way I calculate the model matrix, tho I’m pretty sure it’s correct)

Oh, and the window matrix is

WindowMatrix = new Matrix4( 0.625F, 0, 0, 0,

0, -1, 0, 0,

0, 0, 1, 0,

0, 0, 0, 1 );

Thanks in advance if anyone takes the time to help.