Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[Opengl] Issue with Ogldev lightning tutorial (18 and 19) using Qt5.1 and 5.2 Frameworks [Solved]
Imarion last edited by
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:
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:
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:
- revert the normal in the fragment shader (I cal the "CalcDirectionalLight" function with "-normalize(Normal0)")
- glFrontFace(GL_CW); -> glFrontFace(GL_CCW);
- 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:
- The resulting normals (calculated in my "utils" class) are exactly the same as the one from Ogldev. I used printouts to confirm.
- 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).
- 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.
- 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.
- 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.
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.
A) 2 tips we can easily forget:
- when creating the QT project do not forget to disable shadow build.
- 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:
Hi, welcome to devnet[quote]
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.
[/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.
Imarion last edited by
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.