2

How do I setup openTK so I get a orthographic projection where:

  • The origin is in the top left corner of the screen
  • I can use "normal" pixel coordinates, for instance: if my window is 500 X 400 then:
    • 0,0 is the top left corner
    • 500,0 is the top right corner
    • 500,400 is the bottom right corner
    • 0,400 is the bottom left corner

I currenly have this:

_projectionMatrix = Matrix4.CreateOrthographicOffCenter(
    ClientRectangle.X, ClientRectangle.Width,
    ClientRectangle.Y, ClientRectangle.Height, -1.0f, 1.0f);

I'm not fully able to understand what's happening but is seems the origin is now in the bottom left, also I don't know if the coordinates match with the pixels on screen.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
lsie
  • 23
  • 4

1 Answers1

1

The parameters to Matrix4.CreateOrthographicOffCenter are the left, right, bottom, top, near, and far of the cuboid view volume.

If the origin of the view (ClientRectangle.Y) has to be at the top, then you've to swap the top and bottom parameter:

_projectionMatrix = Matrix4.CreateOrthographicOffCenter(
    ClientRectangle.X, 
    ClientRectangle.X + ClientRectangle.Width,
    ClientRectangle.Y + ClientRectangle.Height, 
    ClientRectangle.Y,
    -1.0f, 1.0f);
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • That worked! except for the fact that my text is now upside-down: https://imgur.com/a/gvLdwFo the text is rendered using QuickFont. Any Ideas? – lsie Dec 01 '19 at 16:26
  • 1
    Of course the text is upside down. That was what you wanted to do. Before the change, the origin was at the bottom and the y direction was upwards. Now the origin is at the top and the y direction is downwards. You've to change the text rendering to compensate that. – Rabbid76 Dec 01 '19 at 16:29