2

Can anyone please help me with the following?

Simply put:

I have a rectangle geometry defined by 4 vertices {x,y,z} as follows:

double[] vertices = new double[12] { -5, 3, 0, 5, 3, 0, 5, -3, 0, -5, -3, 0 };

I draw the rectangle with the following:

GL.VertexPointer(3, VertexPointerType.Double, 0, vertices);

GL.DrawArrays(BeginMode.LineLoop, 0, vertices.Length / 3);

I am using Orthographic projection and my viewport setup code is:

int nWidth = ClientRectangle.Width;
int nHeight = ClientRectangle.Height;

GL.Viewport(0, 0, nWidth, nHeight);

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

GL.MatrixMode(MatrixMode.Modelview);
GL.LoadIdentity();

m_orthogonalProjectionTop = 3.05;
m_orthogonalProjectionLeft = -5.05;
m_orthogonalProjectionRight = 5.05;
m_orthogonalProjectionBottom = -3.05;

GL.Ortho(m_orthogonalProjectionLeft, m_orthogonalProjectionRight, m_orthogonalProjectionBottom, m_orthogonalProjectionTop, -1, 1);

This works as I would expect. The rectangle very nearly fills the entire rendering window (which is light blue in the screenshot below):

Rectangle

(I posted previously that I could not get this initial behaviour to work, previous post, that's why this question my seem familiar, but this part is resolved now).

Now, here is my problem:

In my render code, instead of just calling my rendering function:

RenderRectangle();

I instead call:

GL.PushMatrix();
GL.Rotate(270, 0.0, 0.0, 1.0);
RenderRectangle();
GL.PopMatrix();

And I modify my viewport so that instead of:

GL.Ortho(m_orthogonalProjectionLeft, m_orthogonalProjectionRight, m_orthogonalProjectionBottom, m_orthogonalProjectionTop, -1, 1);

I now have:

GL.Ortho(m_orthogonalProjectionBottom, m_orthogonalProjectionTop, m_orthogonalProjectionLeft, m_orthogonalProjectionRight, -1, 1);

(So that I have swapped the x and y extents of the viewport)

Then I would have expected my rectangle to still nearly fill the screen. What I actually see is that the top of the retangle is fine, it appears just shy of the top of the window, the left and right sides also are fine, but the bottom of the rectangle is just off screen (by setting the bottom of the viewport a little more negative I can see it, but its visibility varies with the window size).

Here's a screenshot, you can see that the bottom of the rectangle is off the bottom of the light blue area:

enter image description here

Can anyone please advise what I am doing wrong?

Thanks, Mitch.

user3738290
  • 445
  • 3
  • 16

1 Answers1

1

Wanted to post so that nobody wasted any time on me! I have solved it. The above code works perfectly well. The problem was that the window in which my rendering was taking place had been positioned correctly but given an incorrect height, too large, and so the actual bottom of the window (the light blue area) was outside of the main application's window.

Thanks, Mitch.

user3738290
  • 445
  • 3
  • 16