-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
47 lines (37 loc) · 1.33 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <igl/readOFF.h>
#include <igl/opengl/glfw/Viewer.h>
#include <iostream>
#include "tutorial_shared_path.h"
#include <igl/png/writePNG.h>
#include <igl/png/readPNG.h>
// This function is called every time a keyboard button is pressed
bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier)
{
if (key == '1')
{
// Allocate temporary buffers
Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic> R(1280,800);
Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic> G(1280,800);
Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic> B(1280,800);
Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic> A(1280,800);
// Draw the scene in the buffers
viewer.core().draw_buffer(
viewer.data(),false,R,G,B,A);
// Save it to a PNG
igl::png::writePNG(R,G,B,A,"out.png");
}
return false;
}
int main(int argc, char *argv[])
{
// Load a mesh in OFF format
Eigen::MatrixXd V;
Eigen::MatrixXi F;
igl::readOFF(TUTORIAL_SHARED_PATH "/bunny.off", V, F);
std::cerr << "Press 1 to render the scene and save it in a png." << std::endl;
// Plot the mesh and register the callback
igl::opengl::glfw::Viewer viewer;
viewer.callback_key_down = &key_down;
viewer.data().set_mesh(V, F);
viewer.launch();
}