Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How send eigen a matrix to GLSL?

How send "Eigen matrix" to GLSL? For example this:

// Set up the model and projection matrix
Eigen::Matrix<GLfloat,4,4> projection_matrix;

projection_matrix = frustum(-1.0f, 1.0f, -aspect, aspect, 1.0f, 500.0f);
glUniformMatrix4fv(render_projection_matrix_loc, 1, GL_FALSE, &projection_matrix.data()[0]);

I looked this way(matrix.date()[0]) for uBLAS, but Eigen isn't uBLAS. How I can do this?

like image 534
Ivan Avatar asked Dec 26 '22 17:12

Ivan


1 Answers

Simply call the .data() function:

glUniformMatrix4fv(render_projection_matrix_loc, 1, GL_FALSE, projection_matrix.data());

You might also be interested by the <unsupported/Eigen/OpenGLSupport> module which allows you to write:

glUniform(render_projection_matrix_loc, projection_matrix);

while taking care of the dimensions, scalar type, storage layout, etc. For instance, it also works with expressions:

glUniform(render_projection_matrix_loc, 2*projection_matrix.tranpose());
like image 168
ggael Avatar answered Dec 28 '22 07:12

ggael