0

Hello I'm currently using the

 Vector3 translation = new Vector3( tx, ty, tz);
        GL.Translate(translation);

Way of translating an object in OpenTK where the Vector3 values are from -1 to 1

How do I change this and make the values of a movable object to go pixel wise that way I can set up a scene based on the user's screen size.

Thanks!

Wezley
  • 413
  • 1
  • 3
  • 19

1 Answers1

1

In legacy OpenGL 1.x, you can achieve this by setting up an orthographic projection with GL.Ortho:

GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
GL.Ortho(0, Width, Height, 0, -1, 1);

GL.MatrixMode(MatrixMode.Modelview);
GL.LoadIdentity();
GL.Translate(1.0f, 0, 0); // translates by 1 pixel

Be forewarned that this will make your application difficult to port to high-resolution (4K) monitors. I would advise using a resolution-independent approach if at all possible. For example:

GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
GL.Ortho(-1, 1, 1, -1, -1, 1);

GL.MatrixMode(MatrixMode.Modelview);
GL.LoadIdentity();
GL.Translate(1.0f / Width, 0, 0); // translates by 1 pixel
The Fiddler
  • 2,726
  • 22
  • 28
  • Now nothing is showing up on my screen. Thank you for the reply! – Wezley Dec 23 '14 at 05:40
  • Here is my draw code: GL.BindTexture(TextureTarget.Texture2D, textID); GL.Translate(0.5, 0.7, 0); drawObject(100, 20, 0.15f, 0.15f); GL.Translate(-0.7, -0.3, 0); drawObject(100, 60, 0.15f, 0.15f); GL.Translate(0.8, -0.5, 0); drawObject(100, 100,0.15f, 0.15f); GL.Translate(1, 1, 0); GL.PopMatrix(); GL.Flush(); – Wezley Dec 23 '14 at 05:45
  • [code](GL.BindTexture( TextureTarget.Texture2D, textID); GL.Translate(0.5, 0.7, 0); drawObject(100, 20, 0.15f, 0.15f); GL.Translate(-0.7, -0.3, 0); drawObject(100, 60, 0.15f, 0.15f); GL.Translate(0.8, -0.5, 0); drawObject(100, 100,0.15f, 0.15f); GL.Translate(1, 1, 0); GL.PopMatrix(); GL.Flush(); ) – Wezley Dec 23 '14 at 05:45