0
\$\begingroup\$

My projection matrix was buggy, I'm not great at mathematics, but I checked it against the the songho tutorial, and the broken one seems correct to me but switching nearplane to farplane seems to have fixed it. What am I missing? My nearplane and farplane values are positive, nearplane is small about 0.01, 1.0f last time i ran against both; farplane is usually relatively large about 1000.0f, 500.0f the last time I ran it against both.

f32 l = left;
    f32 r = right;
    f32 t = top;
    f32 b = bottom;
    f32 n = nearplane;
    f32 f = farplane;

    m4x4 Result =  //TODO why did changing n to f in 0 and 5 fix it? and make sure it is fixed
    {
#if 0 // works
        2*f/(r-l), 0, (r+l)/(r-l), 0,
        0, 2*f/(t-b), (t+b)/(t-b), 0,
        0, 0, -(f+n)/(f-n), -2*f*n/(f-n),
        0, 0, -1, 0,
#else // doesn't
        (2*n)/(r-l), 0, (r+l)/(r-l), 0,
        0, (2*n)/(t-b), (t+b)/(t-b), 0,
        0, 0, -(f+n)/(f-n), (-2*f*n)/(f-n),
        0, 0, -1, 0,
    };
#endif
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Probably your intended nearplane and farplane variables mapped reversely.So it clipped out eveything that supposed to be rendered on the screen.

Possible Reasons

  • (Possible)There might be a transpose operation somewhere in your code.
  • (Possible)There is chance which songho's tutorial displays projection matrix as a one way and its possible Opengl uses it as another.For example Opengl and Directx uses different approaches when it comes to matrixes.One is using row_major layout other one is using column_major.Your case could be something like that.
  • (Not likely)It could be something with your vertex shader.
  • (Sorry for even considering it)Are you sure you passed the n,f variables correctly?
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .