Registered Member
|
Hi,
I would like to create the following two overloads for an OpenGL helper function: void GLVertex(const Eigen::Vector2f &vec) { glVertex2f(vec.x(),vec.y()); } void GLVertex(const Eigen::Vector3f &vec) { glVertex3f(vec.x(),vec.y(),vec.z()); } I quickly discovered that calling e.g. GLVertex(a+b) doesn't work because the type of a+b is a CwiseBinaryOp. I understand that I should instead be defining these functions as receiving MatrixBase<Derived>. But how can I write these two functions using MatrixBase<Derived> but still let the compiler figure out which one to call?? Thank you |
Registered Member
|
You can use a helper struct with a default template argument and partial specialization to choose between the different functions:
A different approach is to always evaluate the expression. The .eval() member function takes an expression (like a CwiseBinaryOp) and evaluates it into a Matrix.
|
Moderator
|
You can also have a look at the "unsupported/Eigen/OpenGLSupport" file, to see how we dealt with that issue. This file contains many wrappers to OpenGL functions.
|
Registered Member
|
Thanks. Too bad it requires such awkward wrappers, but glad to see that there are some ready-made OpenGL wrappers available for my use.
|
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]