I'm making a very simple cube in OpenTK and it seemed to be going fine until I tried to move it around. Moving it along the X Axis seems to elongate the cube, not the result I hoped for.

My Vertex Shader

#version 330

in vec3 vPosition;
in  vec3 vColor;
out vec4 color;
uniform mat4 modelview;
    gl_Position = modelview * vec4(vPosition, 1.0);
    color = vec4( vColor, 1.0);

My Fragment Shader

#version 330

in vec4 color;
out vec4 outputColor;

    outputColor = color;

How I make modelview

    Matrix4 c = Matrix4.LookAt(Game.camera.Position, new Vector3(Game.camera.X + 1f, 0, Game.camera.Z + 0f), new Vector3(0, 1, 0)) * Matrix4.CreatePerspectiveFieldOfView(
    (float)(0.5 * Math.PI),
    (float)1366 / 768,
    1000.0f); * Matrix4.CreateTranslation(Origin);
GL.UniformMatrix4(Game.uniform_mview, false, ref c);

What I'm doing here is adding 0.01 to Origin.X while moving the camera the opposite direction

What I'm doing here is adding 0.01 to Origin.X while moving the camera the opposite direction.

Does anyone know why it produces this result? Thanks in advance for your help.

EDIT: Multiplied matrices by perspective * view * model

enter image description here

This weird line seems to blink in and out as I move the camera around.

EDIT 2: Matrix Printout

(0, 0.9999995, 0.001019571, 0.001019367)
(0, 0.001019367, -1.0002, -0.9999995)
(0.5622255, 0, 0, 0)
(1207.66, -0.9999995, 980.9957, 980.9995)
  • \$\begingroup\$ are the marices in the correct order? I'd usually expect perspective * view * model... \$\endgroup\$ Dec 28, 2016 at 14:31
  • \$\begingroup\$ @realUser404 apologies, I wasn't referring to that, I meant the modelview in the question above, i.e. c = lookat * proj * trans. I'd usually expect it to be something like proj * lookat * trans \$\endgroup\$ Dec 28, 2016 at 16:30
  • \$\begingroup\$ Sorry for the delay on getting back to you guys, it's 6:52AM here. I will try switching my matrices around, see if that works. \$\endgroup\$
    – user81509
    Dec 28, 2016 at 19:53
  • \$\begingroup\$ I just switched the matrices around, and I'm getting a weird green line that blinks on and off, I'll post a gif. \$\endgroup\$
    – user81509
    Dec 28, 2016 at 20:01
  • \$\begingroup\$ seems like a weird result. Another thing that may be a typo: 1000.0f); * Matrix4.CreateTranslation(Origin); is there supposed to be a semicolon before the * here? \$\endgroup\$ Dec 28, 2016 at 20:32


You must log in to answer this question.