Note that there are some explanatory texts on larger screens.

plurals
  1. POIncorrect order of matrix values in glm?
    primarykey
    data
    text
    <p>I started using <a href="http://glm.g-truc.net" rel="nofollow noreferrer">GLM</a> library to do mathematics operations over OpenGL 3 and GLSL. I need an orthographic projection to draw 2D graphics, so I writed this simple code:</p> <pre><code>glm::mat4 projection(1.0); projection = glm::ortho( 0.0f, 640.0f, 480.0f, 0.0f, 0.0f, 500.0f); </code></pre> <p>Printing on screen the values that glm::ortho has created I get:</p> <pre><code> 0.00313 0.00000 0.00000 0.00000 0.00000 -0.00417 0.00000 0.00000 0.00000 0.00000 -0.00200 0.00000 -1.00000 1.00000 -1.00000 1.00000 </code></pre> <p>As I know this is not the correct order for the values in OpenGL, because multiplying this matrix by a position vector will ignore all translation values.</p> <p>I tested that matrix with my shader and some primitives and I only get a blank screen. But if I modify by hand the matrix as follows it works ok:</p> <pre><code> 0.00313 0.00000 0.00000 -1.00000 0.00000 -0.00417 0.00000 1.00000 0.00000 0.00000 -0.00200 -1.00000 0.00000 0.00000 0.00000 1.00000 </code></pre> <p>Moreover, looking at the function "ortho" in the "glm/gtc/matrix_transform.inl" file:</p> <pre><code>template &lt;typename valType&gt; inline detail::tmat4x4&lt;valType&gt; ortho( valType const &amp; left, valType const &amp; right, valType const &amp; bottom, valType const &amp; top, valType const &amp; zNear, valType const &amp; zFar) { detail::tmat4x4&lt;valType&gt; Result(1); Result[0][0] = valType(2) / (right - left); Result[1][1] = valType(2) / (top - bottom); Result[2][2] = - valType(2) / (zFar - zNear); Result[3][0] = - (right + left) / (right - left); Result[3][1] = - (top + bottom) / (top - bottom); Result[3][2] = - (zFar + zNear) / (zFar - zNear); return Result; } </code></pre> <p>I have replaced the last 3 initialization lines by the following code and also worked ok:</p> <pre><code> Result[0][3] = - (right + left) / (right - left); Result[1][3] = - (top + bottom) / (top - bottom); Result[2][3] = - (zFar + zNear) / (zFar - zNear); </code></pre> <p>This is a minimal vertex shader that I'm using for test (note that at this moment the uni_MVP is only the projection matrix explained above):</p> <pre><code>uniform mat4 uni_MVP; in vec2 in_Position; void main(void) { gl_Position = uni_MVP * vec4(in_Position.xy,0.0, 1.0); } </code></pre> <p>I thik that this is not a bug, because all functions works the same way. Maybe is an issue of my C++ compiler that inverts the order of multidimensional arrays? How can I solve this without modifying all GLM source code?</p> <p>I'm using the last version of GLM library (0.9.1) with Code::Blocks and MinGW running on Windows Vista.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload