PDA

View Full Version : glFrustum / Perspective Correction



pradox
04-04-2016, 06:40 AM
hello,

i am using glOrtho for 2D Projection (LineDrawing) and glFrustion for Perspective Projection (ArcBall/TrackBall), My Problem is the distorting von the View in Case of GlFrustum.
the problem i think i know, but no solution for that

The Following Code I am Using:

############
void Render()
{

GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

// line
if (LineDraw != null)
{
GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
GL.Ortho(0, game.Width, game.Height, 0, 0, 1);

GL.LineWidth(2.5f);
GL.Color3(1.0f, 1.0f, 1.0f);

GL.Begin(PrimitiveType.Lines);
ListCollection<Vector2> points = LineDraw.Points;
for (int i = 0; i < points.Size() - 1; i++)
{
GL.Vertex2(points.Get(i).X, points.Get(i).Y);
GL.Vertex2(points.Get(i + 1).X, points.Get(i + 1).Y);
}
GL.End();
}

// trackball
if (TrackBall != null)
{
GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
GL.Frustum(0, game.Width, game.Height, 0, 0, 1);

GL.MultMatrix(TrackBall.GetRoationMatrix().Mat);

DrawUtils.Rotate(rotate_x, rotate_y);

GL.Begin(PrimitiveType.Lines);
GL.Color4(1.0, 0.0, 0.0, 1.0);
GL.Vertex3(0.0, 0.0, 0.0);
GL.Vertex3(10.0, 0.0, 0.0);
GL.Color4(0.0, 1.0, 0.0, 1.0);
GL.Vertex3(0.0, 0.0, 0.0);
GL.Vertex3(0.0, 10.0, 0.0);
GL.Color4(0.0, 0.0, 1.0, 1.0);
GL.Vertex3(0.0, 0.0, 0.0);
GL.Vertex3(0.0, 0.0, 10.0);
GL.End();

DrawUtils.DrawBox();
}
}

Thanks alot.
pradox

mhagain
04-04-2016, 07:15 AM
What kind of distorting do you mean?

pradox
04-04-2016, 09:32 AM
What kind of distorting do you mean?

thank for your response.

here is an image.
2248

orginally it is a quadric box, 1x1x1.

but it scretched to right length.

i use glFrustum, i think i want to prefer this method.

thanks
pradox

pradox
04-04-2016, 09:35 AM
What kind of distorting do you mean?

im so sorry, the reason is the non-propertional window, but thats an other question i know.

thanks for your help at this time.

pradox

GClements
04-04-2016, 11:56 AM
GL.Frustum(0, game.Width, game.Height, 0, 0, 1);

This puts the viewpoint at the top-left corner of the window.