简体   繁体   English

如何将linmath.h矩阵传递给glsl着色器?

[英]How to pass linmath.h matrices to glsl shader?

I'm learning the linmath.h library, but I'm having trouble passing matrices made by it in my main program to my vert shader: 我正在学习linmath.h库,但是我在主程序中将它制作的矩阵传递给我的vert着色器时遇到了麻烦:

#include "linmath.h"
…
GLint mat_uniform_handle = glGetUniformLocation(shade_program_handle, "matrix");
…
mat4x4 M;
mat4x4_identity(M);
glUniformMatrix4fv(mat_uniform_handle, 1, GL_FALSE, M);

But of course that gives me a type error because linmath matrices have the type float (*)[4] and glUniformMatrix4fv takes the type const GLfloat * . 但是当然这给了我一个类型错误,因为linmath矩阵的类型为float (*)[4]glUniformMatrix4fv的类型为const GLfloat *

I tried writing my own converter that concated the columns of the matrix into a single array, then returned a pointer to the first element, but that didn't work. 我尝试编写自己的转换器,将矩阵的列连接成一个数组,然后返回指向第一个元素的指针,但这不起作用。

Am I missing some function of linmath.h that does this conversion for me? 我错过了linmath.h一些函数,它为我做了这个转换吗? If not, how do I properly convert a linmath.h matrix to an opengl matrix? 如果没有,我如何正确地将linmath.h矩阵转换为opengl矩阵?

It's pathetic that I didn't try this before asking here, but here's the solution, just a straight cast.: 可悲的是我在问这里之前没试过这个,但这里是解决方案,只是一个直接的演员:

glUniformMatrix4fv(mat_uniform_handle, 1, GL_FALSE, (GLfloat *)M);

Hope this helps someone. 希望这有助于某人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM