Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ch3 how the orthographic projection matrix computed? #91

Open
changkaizhao opened this issue Nov 27, 2017 · 1 comment
Open

ch3 how the orthographic projection matrix computed? #91

changkaizhao opened this issue Nov 27, 2017 · 1 comment

Comments

@changkaizhao
Copy link

changkaizhao commented Nov 27, 2017

when drawing background texture, how does its orthographic projection matrix computed?
it gave as below

static const GLfloat proj[] =
{
  0,        -2.f/w,     0,      0,
  -2.f/h,      0,       0,       0,
  0,              0,       1,       0,
  1,               1,        0,       1
};

but I found the orthographic projection matrix has the structure like this: https://www.scratchapixel.com/lessons/3d-basic-rendering/perspective-and-orthographic-projection-matrix/orthographic-projection-matrix

[
 2/(r-l)     0         0           -(r+l)/(r-l)
 0          2/(t-b)   0         -(t+b)/(t-b)
0             0         -2/(f-n)     -(f+n)/(f-n)
0            0           0                   1
]
@changkaizhao
Copy link
Author

I think the texture vertices are not in correct order. so it needs to inverse the projection matrix to give a correct drawing on the screen.
if modify the texture vertices in correct order.

static const GLfloat textureVertices[] =
     {
     0, 1,
     1, 1,
     0, 0,
     1, 0
     };

then we can apply the projection matrix like this:

    GLfloat proj2[] =
    {
        2.0/w, 0, 0, 0,
        0, 2.0/h, 0, 0,
        0, 0, -1, 0,
        -1, -1, 0, 1
    };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant