Ortho Near/Far not working as I expected

Started by
2 comments, last by Hodgman 11 years, 8 months ago
ok I am having an issue where I have a plane which I am spinning in 3d space, and it is getting cut off then the edge is to far away, or past the near.

so I figured I would set the near and far to really high numbers to see if that would fix it, but it doesn't seem to matter, does ortho not cover this?


GL.Ortho(0, screen_width, screen_height, 0, -10000, 10000);
GL.Viewport(0, 0, screen_width, screen_height);


then the render code is this:

GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();


//GL.Scale(.5,.5,.5);
GL.Rotate(video_rotation_x % 360, 0, 1, 0);
GL.Rotate(video_rotation_y % 360, 1, 0, 0);
GL.Rotate(video_rotation_z % 360, 0, 0, 1);

GL.Begin(BeginMode.Quads);
GL.TexCoord2(0, 0);
GL.Vertex2(x, y);
GL.TexCoord2(1, 0);
GL.Vertex2(x + (float)video_width, y);
GL.TexCoord2(1, 1);
GL.Vertex2(x + (float)video_width, y + (float)video_height);
GL.TexCoord2(0, 1);
GL.Vertex2(x, y + (float)video_height);
GL.End();


I assumed that the -10000 would be more than enough for the near, but the corners at certain angles is cut off (looks flat) and I am just curious as to why, the video is not wider than 800 and it is at 0, so the max it could be is -800 right? maybe a bit further, but shouldn't come near -10,000, but no matter what value I use, it doesn't seem to make a difference.

also if I scale it to .5, .5, .5 it isn't clipped at all, so I am not sure how to fix it.

what am I missing?
Advertisement
GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();[/quote]This is replacing your ortho projection matrix with an 'identity' projection matrix.

You should probably be activating the Projection matrix-mode before setting your ortho matrix, and then setting the ModelView matrix-mode before setting identity + rotating.
ok this is weird, if the matrix is "replaced" then why does commenting out ortho have a different result?

I set the ortho, for the width and height, then I set the Matrix mode, if that is truly replacing the matrix then there shouldn't be any difference between


GL.Ortho(0, screen_width, screen_height, 0, -10000, 10000);
GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();


or


//GL.Ortho(0, screen_width, screen_height, 0, -10000, 10000);
GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();


but there is most definitely a difference, BUT I think I just figured out what may be wrong (as I was typing)

I think matrix mode generates the projection Identity matrix using the current matrix, BUT it will remove the z index stuff because a projection matrix has a 0 for the z index.
screen_height 0 0
0 screen_width 0
0 0 0


or something of that sort, am I close?
MatrixMode selects which built-in matrix will be modified by the following matrix commands. Before you call Identity+Ortho, you should select the Projection matrix -- this matrix is used to transform camera-space positions to the screen.

Before you call Identity+Rotate, you should select the ModelView matrix -- this matrix is used to position the object (model) and camera (view).

In your original, you're not selecting a mode before calling Ortho, so maybe it's defaulting to the ModelView matrix. This means that you'd have them backwards: your ortho-projection in the ModelView, and your camera/object rotation in the Projection. This might have strange results, as the operations will be done in the wrong order.

N.B. LoadIdentity "clears" the currently selected matrix; you should use it before setting up any matrix from scratch.

This topic is closed to new replies.

Advertisement