Files
igl/tutorial/105_Overlays/main.cpp
T
michelleandJérémie Dumas b8ee8b99cf Text Rendering Using GLSL in ImGui Menu (#1549)
* This is the code that renders the letter a for each vertex on the mesh paired with  a libigl-example-project

* Code for rendering just the number 12 on the 12th vertex

* Rendering vertices via glsl works, with geometry shader

* Added dynamic font scaling so accomodate ortho and perspective projections.

* Got faceids rendering

* Code cleanup

* This allows user to add custom text at some location rendered with the text shaders

* Dedicated separate VBOs for face and vertid labels

* Added in extra label rendering

* Moved texture binding to its own function and other code cleanup

* More conflict resolution when fetching upstream changes

* Resolved the relative path to font atlas

* Change scope variable for font atlas macro

* Removed PNG texture loaded from disk, and encoded font atlas into byte array. Other minor changes for VBO iterators and removed uneeded dependencies from previous commits

* Encapsulated text VBOs into struct to remove code duplication, and fixed bug for both overlay and text shaders being used at same time.

* Remove whitespace

* Tentative for Windows build fix not initializing TextGL structs in header

* Removed uniform that only belongs for text labels

* Added init and free methods for label buffers initialization and passing some args by reference on label methods

* Compressed font atlas that is under 50kB reduced from 330kB with decompression function

* Converting type from string literal to char array

* Broke up string literal

* Cleanup font atlas.

* Linux compile fix.

* Remove deprecated text pipeline.

Co-authored-by: Jérémie Dumas <jeremie.dumas@ens-lyon.org>
2020-08-09 15:49:22 -07:00

82 lines
2.0 KiB
C++
Executable File

#include <igl/readOFF.h>
#include <igl/opengl/glfw/Viewer.h>
#include <igl/opengl/glfw/imgui/ImGuiMenu.h>
#include <sstream>
#include "tutorial_shared_path.h"
Eigen::MatrixXd V;
Eigen::MatrixXi F;
int main(int argc, char *argv[])
{
// Load a mesh in OFF format
igl::readOFF(TUTORIAL_SHARED_PATH "/bunny.off", V, F);
// Find the bounding box
Eigen::Vector3d m = V.colwise().minCoeff();
Eigen::Vector3d M = V.colwise().maxCoeff();
// Corners of the bounding box
Eigen::MatrixXd V_box(8,3);
V_box <<
m(0), m(1), m(2),
M(0), m(1), m(2),
M(0), M(1), m(2),
m(0), M(1), m(2),
m(0), m(1), M(2),
M(0), m(1), M(2),
M(0), M(1), M(2),
m(0), M(1), M(2);
// Edges of the bounding box
Eigen::MatrixXi E_box(12,2);
E_box <<
0, 1,
1, 2,
2, 3,
3, 0,
4, 5,
5, 6,
6, 7,
7, 4,
0, 4,
1, 5,
2, 6,
7 ,3;
// Plot the mesh
igl::opengl::glfw::Viewer viewer;
viewer.data().set_mesh(V, F);
// Plot the corners of the bounding box as points
viewer.data().add_points(V_box,Eigen::RowVector3d(1,0,0));
// Plot the edges of the bounding box
for (unsigned i=0;i<E_box.rows(); ++i)
viewer.data().add_edges
(
V_box.row(E_box(i,0)),
V_box.row(E_box(i,1)),
Eigen::RowVector3d(1,0,0)
);
// Plot labels with the coordinates of bounding box vertices
std::stringstream l1;
l1 << m(0) << ", " << m(1) << ", " << m(2);
viewer.data().add_label(m+Eigen::Vector3d(-0.007, 0, 0),l1.str());
std::stringstream l2;
l2 << M(0) << ", " << M(1) << ", " << M(2);
viewer.data().add_label(M+Eigen::Vector3d(0.007, 0, 0),l2.str());
// activate label rendering
viewer.data().show_custom_labels = true;
// Rendering of text labels is handled by ImGui, so we need to enable the ImGui
// plugin to show text labels.
igl::opengl::glfw::imgui::ImGuiMenu menu;
menu.callback_draw_viewer_window = [](){};
viewer.plugins.push_back(&menu);
// Launch the viewer
viewer.launch();
}