diff options
author | sanine <sanine.not@pm.me> | 2022-06-14 00:06:42 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2022-06-14 00:06:42 -0500 |
commit | 2f518e5e28d35ae24a5ac0e31000835e43b01972 (patch) | |
tree | 47fdeb9fa5b04e267702acb06424d3f87b37dd84 /libs/cglm/docs/source/opengl.rst | |
parent | 034d5c965ff34cfdf4b153af9f32360a02e35684 (diff) |
add cglm as 3rd-party library
Diffstat (limited to 'libs/cglm/docs/source/opengl.rst')
-rw-r--r-- | libs/cglm/docs/source/opengl.rst | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/libs/cglm/docs/source/opengl.rst b/libs/cglm/docs/source/opengl.rst new file mode 100644 index 0000000..2cebae0 --- /dev/null +++ b/libs/cglm/docs/source/opengl.rst @@ -0,0 +1,61 @@ +How to send vector or matrix to OpenGL like API +================================================== + +*cglm*'s vector and matrix types are arrays. So you can send them directly to a +function which accepts pointer. But you may got warnings for matrix because it is +two dimensional array. + +Passing / Uniforming Matrix to OpenGL: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +**glUniformMatrix4fv** accepts float pointer, you can pass matrix to that parameter +and it should work but with warnings. "You can pass" doesn't mean that you must pass like that. + +**Correct options:** + +Correct doesn't mean correct way to use OpenGL it is just shows correct way to pass cglm type to it. + +1. Pass first column +--------------------- + +The goal is that pass address of matrix, first element of matrix is also address of matrix, +because it is array of vectors and vector is array of floats. + +.. code-block:: c + + mat4 matrix; + /* ... */ + glUniformMatrix4fv(location, 1, GL_FALSE, matrix[0]); + +array of matrices: + +.. code-block:: c + + mat4 matrix; + /* ... */ + glUniformMatrix4fv(location, count, GL_FALSE, matrix[0][0]); + +1. Cast matrix to pointer +-------------------------- + +.. code-block:: c + + mat4 matrix; + /* ... */ + glUniformMatrix4fv(location, count, GL_FALSE, (float *)matrix); + +in this way, passing aray of matrices is same + +Passing / Uniforming Vectors to OpenGL: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You don't need to do extra thing when passing cglm vectors to OpengL or other APIs. +Because a function like **glUniform4fv** accepts vector as pointer. cglm's vectors +are array of floats. So you can pass it directly ot those functions: + +.. code-block:: c + + vec4 vec; + /* ... */ + glUniform4fv(location, 1, vec); + +this show how to pass **vec4** others are same. |