patricker's picture

Change scale/perspective to 1:1

I'm just just getting started with OpenTK and I'm working in 2D. I'm drawing rectangles and I want to view them at 1:1 scale where 1 unit in my code == 1px on screen.

I'm working from the base example code that shows a triangle with three colors. console app, inherits from GameWindow.

I got this working so that it showed a rectangle but when I tell it to draw a rectangle that is a 5x5 cube with it's origin at 0,0 I get a HUGE cube that goes off the edge of the screen. If I'm doing anything obviously wrong please let me know, otherwise how can I adjust the scale/perspective so that I see things in the desired scale?

Thanks,
Pat


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

You need to setup a correct orthographic projection. Use Matrix4.CreateOrthographicOffCenter:

Matrix4 ortho = Matrix4.CreateOrthographicOffCenter(0, Width, Height, 0, 0.1f, 256f);

and set this as your projection matrix.