[Opengl] Issue with Ogldev lightning tutorial (18 and 19) using Qt5.1 and 5.2 Frameworks [Solved]



  • Hello all,
    I have been struggling for 2 weeks on those 2 lightning tutorial.
    I have been using the QT framework for several tutorials and even a small private application without any issue.
    I had difficulties which I could overcome, but this time around I'm completely stuck.

    Ogldev tutorial page:
    http://ogldev.atspace.co.uk/

    I have the QT opengl/mingw/windows 64 bits release. I use Windows 7.

    Actually I can make it work, but to the expense of changing parameters in a way I feel is not correct.

    Here is a link to my project:
    https://dl.dropboxusercontent.com/u/96524863/Testcamera.zip

    It is called Testcamera as at first I thought this was the issue. But the camera (lookat) seems working well in the end.
    You will need the "test.png" texture you can find in the ogldev source or you can simply replace the texture part in the fragment shader with a plain color.

    Ogldev defines its own matrix and vector implementations.
    I use the QT framework (QMatrix4x4 and QVector2D, QVector3D).
    In other words: particularly, I do not use the pipeline and math_3d implementations from Ogldev.

    To make it work, I have to either:

    1. revert the normal in the fragment shader (I cal the "CalcDirectionalLight" function with "-normalize(Normal0)")
    2. glFrontFace(GL_CW); -> glFrontFace(GL_CCW);
    3. glCullFace(GL_BACK); -> glCullFace(GL_FRONT);

    This all boils down to the same end result: change the way Opengl considers front and back faces.
    To be noticed that by default the pyramid rotates, in my Qtproject, in the other way than the one from Ogldev.
    Same if I revert the normal (solution 1).
    But with solutions 2 and 3, the pyramid rotates and is displayed in exactly the same way as the one in Ogldev.

    I feel I shouldn't do either of those 3.

    Things I have checked/noticed:

    1. The resulting normals (calculated in my "utils" class) are exactly the same as the one from Ogldev. I used printouts to confirm.
    2. The pyramid vertices are given in counter clockworck (CCW). My understanding is, as counter clockworck gives the front face, having the culling defined as I mention above (BACK + CW) is fine.
      (I admit I checked only 2 of the faces, I hope the others are fine too).
    3. If, in my QT project, I set up (hardcode) the exact same transformations (World and WVP) matrices as in Ogldev implementation, everything is displayed correctly.
    4. The rotation matrices, when calculated only around the Y axis, from QT and the one from Ogldev are transposed of each other.
      I tried to transpose the rotation matrix from the QT project to get the same matrix, but it does not give a good result.
    5. To transfer the matrices to opengl:
      Ogldev uses: glUniformMatrix4fv(m_WVPLocation, 1, GL_TRUE, (const GLfloat*)WVP.m);
      In QT project I use: glUniformMatrix4fv(gWVPLocation, 1, GL_FALSE, WVP.constData());

    Considering GL_TRUE will transpose Ogldev's matrix, while .constadata() gives the result in column major format, my understanding is the end result is completely equivalent.

    Conclusion:
    I'm completely out of ideas to continue the investigation. Maybe one of my assumptions above is wrong or I missed something, probably completely silly, but what ? ... That is the question.

    If someone did not know what to do this week end or was in need of a small(?) programming enigma ... here you are :)

    Thanks in advance for the help.
    Imarion
    Ps:
    A) 2 tips we can easily forget:

    1. when creating the QT project do not forget to disable shadow build.
    2. my shader are in project ressources. If you modify the code there, remember to "rebuild all" otherwise the shader modifications are not taken into account.

    B) Some of the code in the projects I link here above comes from Ogldev tutorial.
    If you want to use it for yourself be sure to comply with the website rules:
    http://ogldev.atspace.co.uk/


  • Moderators

    Hi, welcome to devnet[quote]

    1. The pyramid vertices are given in counter clockworck (CCW). My understanding is, as counter clockworck gives the front face, having the culling defined as I mention above (BACK + CW) is fine.
      [/quote]GL_CCW and GL_BACK are the defaults so you don't have to change them.
      They mean that counter clockwise vertices form the front face of the triangle. Culling means "not showing". When it is set to GL_BACK it means that CW faces will be hidden (because CCW are front, not back).
      Since your model is CCW you want to leave it at default (or explicitly repeat the default) so CCW + BACK (not CW + BACK like you stated).

    With GL_CCW, GL_BACK and no changes to the shader (no negation) it renders as expected.



  • Hello,
    thank you for the reply and the explanations.

    I have checked and indeed all the faces of the pyramid are in counter clockwise order.

    I contacted the author of the ogldev tutorials on this matter.

    I mark this post as solved.

    Again thank you.

    Imarion


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.