GL ES 2.0 Perspective Crazyness

This topic contains 4 replies, has 3 voices, and was last updated by  b34r 7 years, 1 month ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #30272

    b34r
    Member

    Hello everyone,

    I’ve spent the last 16 hours trying to figure out how a very simple code I am writing on the Android NDK could fail this badly.

    I am porting my engine to Android and I am at a loss.
    I am using a very simple vertex shader multiplying the vertex stream by the MVP matrix and a fragment shader outputting green on a screen cleared in black.

    I have a few very simple questions:

    – Is a working OpenGL projection matrix expected to work with ES 2.0?
    – Should glViewport be given normalized or in pixels as the doc says?

    I can see the object when not passing a projection matrix (by only passing the object transformation matrix) but as soon as I put in the projection matrix nothing shows anymore…
    Could it be an initialization problem?

    Can perspective work on an object with a vertex stream only (no normal stream)?

    Thank you for any help or advice you can give me.

    #34297

    Joe Davis
    Member
    Quote:
    – Is a working OpenGL projection matrix expected to work with ES 2.0?

    Yes. There is however a difference in the way that they are implemented in code, as OGLES 2.0 does not provide a matrix stack like desktop GL or OGLES 1.x. This means you have to create and manage your own matrices (there are examples of this in most of our demos and training courses. Take a look at one of the earlier training courses, such as IntroducingPOD, to see how this is done in OGLES 2.0).

    Quote:
    – Should glViewport be given normalized or in pixels as the doc says?

    glViewport is used to declare the width and hight of the window you are rendering to in pixels, as well as the position of the lower left corner of the window in NDC (normalized device coordinates).

    If you look through the training courses in our SDK you can find many examples of this being used, but it may be worthwhile reading the Khronos documentation for this function to gain a complete understanding of what it does.

    Quote:
    I can see the object when not passing a projection matrix…

    This sounds like you are incorrectly calculating your projection matrix and causing the object to be placed outside of your clip space boundaries (e.g. behind the camera, outside of the bounds of the window, or beyond the far plane). Once again, looking through the code for training courses in our SDK should help you determine where your own calculations are going wrong.

    Quote:
    Can perspective work on an object with a vertex stream only (no normal stream)?

    The normals of the object are not involved in this calculation. You only need to transform the position of the vertices using the MVP matrix in your vertex shader.

    #34298

    b34r
    Member

    Hi,

    Thank you for the fast answer.

    Unfortunately you only confirmed my feeling that I am really at a loss here…
    The engine for which I am writing a port has a functional Direct X, OpenGL and Wii GX port using this same matrix (with RH/LH tweaking where required but I confirmed and reconfirmed this was not the issue a good thousand times already).

    I spent a lot of time investigating the problem to the point where I started swapping code from demos around. All this to no extend.

    I really believe the problem lies in the initialization code or something. I can manage to get a picture when dividing the MVP matrix by a very large factor (8192) (yes, I am that lost :D).

    Well, I am going to trace every single bit of code executed but unfortunately the NDK makes it much harder than it ought to be…

    I’ll report the issue once I get it.

    #34299

    Xmas
    Member

    Could you please post:

    – the vertex shader you are using

    – the values passed to glUniformMatrix for your MVP matrix

    – the values passed to glViewport.

    With that we should be able to help you.

    #34300

    b34r
    Member

    I got it!

    The aspect ratio was completely bogus due to a bug in the parser (which only manifested with this toolchain). Blame on me for not dumping the matrix to the log.

    I did not realize that the A/R correction was applied *after* the matrix computation and so all my tries with different formulas (there isn’t many anyway) would lead to the same problem.

    Thank you for your help!

Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic.