[Solved] OpenGL renderer view-projection matrix issue
Posted: Sat Nov 07, 2015 13:47
Hi,
I'm resurrecting an old project and am updating its code from CEGUI 0.5 to current 0.8.4. While it's a lot of work, it's been easier than I expected thanks to the very detailed porting documents in the wiki, please keep this up!
I believe my last problem to solve has to do with the big renderer update from 0.7->0.8. I'm using both OpenGL and OpenGL3 renderers, both behave the same. The effect I see, is that the GUI renders inverted (both upside-down and left-right) and scaled down to about half its size. I figured out the reason, it's because the view-projection matrix computed by OpenGLRenderTarget<T>::updateMatrix() looks wrong to me. For a viewport of 1024x768, it's computing the following matrix:
whereas a correct, 2D orthographic view-proj matrix would be:
I verified that indeed replacing the code in OpenGLRenderTarget<T>::updateMatrix() by the following:
does result in my GUI being rendered correctly.
Of course, I assume that I'm doing something wrong and there's a good reason the current implementation is the way it is. Just to make sure, I've ported this example from the wiki to CEGUI 8.4 (pastebin here, diff here) and I'm seeing the exact same rendering problem, so that makes me wonder. Any hints or ideas? What's the reason for using a perspective transform with a hard-coded FoV instead of ortho?
I'm resurrecting an old project and am updating its code from CEGUI 0.5 to current 0.8.4. While it's a lot of work, it's been easier than I expected thanks to the very detailed porting documents in the wiki, please keep this up!
I believe my last problem to solve has to do with the big renderer update from 0.7->0.8. I'm using both OpenGL and OpenGL3 renderers, both behave the same. The effect I see, is that the GUI renders inverted (both upside-down and left-right) and scaled down to about half its size. I figured out the reason, it's because the view-projection matrix computed by OpenGLRenderTarget<T>::updateMatrix() looks wrong to me. For a viewport of 1024x768, it's computing the following matrix:
Code: Select all
-0.87617 0.00000 0.00000 0.00000
0.00000 1.16823 0.00000 0.00000
0.00000 0.00000 1.66667 1.00000
448.60159 -448.60156 477.70227 1433.10742
whereas a correct, 2D orthographic view-proj matrix would be:
Code: Select all
0.00195 0.00000 0.00000 0.00000
0.00000 -0.00260 0.00000 0.00000
0.00000 0.00000 -1.00000 0.00000
-1.00000 1.00000 0.00000 1.00000
I verified that indeed replacing the code in OpenGLRenderTarget<T>::updateMatrix() by the following:
Code: Select all
const float l = d_area.left(),
r = d_area.right(),
b = d_area.bottom(),
t = d_area.top();
d_matrix->d_matrix = glm::ortho(l, r, b, t);
does result in my GUI being rendered correctly.
Of course, I assume that I'm doing something wrong and there's a good reason the current implementation is the way it is. Just to make sure, I've ported this example from the wiki to CEGUI 8.4 (pastebin here, diff here) and I'm seeing the exact same rendering problem, so that makes me wonder. Any hints or ideas? What's the reason for using a perspective transform with a hard-coded FoV instead of ortho?