28#include <easy3d/core/model.h>
29#include <easy3d/renderer/drawable_points.h>
30#include <easy3d/renderer/renderer.h>
31#include <easy3d/util/resource.h>
32#include <easy3d/util/initializer.h>
42int main(
int argc,
char **argv) {
46 const std::string file = resource::directory() +
"/data/bunny.bin";
49 TutorialEyeDomeLighting viewer(EXAMPLE_TITLE);
52 Model *model = viewer.add_model(file,
true);
54 LOG(ERROR) <<
"failed to load model. Please make sure the file exists and format is correct.";
60 drawable->set_point_size(5.0f);
The base class of renderable 3D models.
Definition: model.h:49
Renderer * renderer()
Gets the renderer of this model.
Definition: model.h:94
PointsDrawable * get_points_drawable(const std::string &name) const
Definition: renderer.cpp:286
void set_uniform_coloring(const vec4 &color)
Definition: state.cpp:89
Definition: collider.cpp:182
void initialize(bool use_log_file, bool use_setting_file, const std::string &resource_dir)
Initialization of Easy3D.
Definition: initializer.cpp:35
28#include <easy3d/core/point_cloud.h>
29#include <easy3d/renderer/opengl.h>
30#include <easy3d/renderer/drawable_points.h>
31#include <easy3d/renderer/camera.h>
32#include <easy3d/renderer/shader_manager.h>
33#include <easy3d/renderer/shader_program.h>
34#include <easy3d/renderer/eye_dome_lighting.h>
35#include <easy3d/renderer/renderer.h>
36#include <easy3d/util/setting.h>
41TutorialEyeDomeLighting::TutorialEyeDomeLighting(
const std::string& title) :
Viewer(title) {
42 camera()->setUpVector(
vec3(0, 1, 0));
43 camera()->setViewDirection(
vec3(0, 0, -1));
44 camera_->showEntireScene();
50 "---------- Eye Dome Lighting usage --------- \n"
51 "Press key 'space' to toggle Eye Dome Lighting\n"
52 "-------------------------------------------- \n";
56TutorialEyeDomeLighting::~TutorialEyeDomeLighting() {
64bool TutorialEyeDomeLighting::key_press_event(
int key,
int modifiers) {
65 if (key == KEY_SPACE) {
66 edl_enabled_ = !edl_enabled_;
67 std::cout <<
"Eye Dome Lighting " << (edl_enabled_ ?
"enabled" :
"disabled") << std::endl;
72 return Viewer::key_press_event(key, modifiers);
76void TutorialEyeDomeLighting::draw()
const {
77 if (!current_model()) {
82 const mat4& MVP = camera_->modelViewProjectionMatrix();
84 const vec3& wCamPos = camera_->position();
87 const mat4& MV = camera_->modelViewMatrix();
88 const vec4& wLightPos =
inverse(MV) * setting::light_position;
90 ShaderProgram* program = ShaderManager::get_program(
"points/points_plain_color");
92 std::vector<ShaderProgram::Attribute> attributes;
93 attributes.emplace_back(ShaderProgram::Attribute(ShaderProgram::POSITION,
"vtx_position"));
94 attributes.emplace_back(ShaderProgram::Attribute(ShaderProgram::COLOR,
"vtx_color"));
95 attributes.emplace_back(ShaderProgram::Attribute(ShaderProgram::NORMAL,
"vtx_normal"));
96 program = ShaderManager::create_program_from_files(
"points/points_plain_color", attributes);
101 auto drawable = current_model()->renderer()->get_points_drawable(
"vertices");
102 float point_size = drawable->point_size();
103 glPointSize(point_size);
107 program->
set_uniform(
"MVP", MVP);
108 program->set_uniform(
"wLightPos", wLightPos);
109 program->set_uniform(
"wCamPos", wCamPos);
110 program->set_uniform(
"lighting", drawable->normal_buffer());
111 program->set_uniform(
"per_vertex_color", drawable->coloring_method() != State::UNIFORM_COLOR && drawable->color_buffer());
112 program->set_uniform(
"default_color", drawable->color());
OpenGL Shader Compilation.
Definition: shader_program.h:78
void bind() const
Starts using the program.
Definition: shader_program.cpp:678
void release() const
Ends using the program.
Definition: shader_program.cpp:689
Mat< N, N, T > inverse(const Mat< N, N, T > &m)
Return the inverse of N x N (square) matrix m.
Definition: mat.h:977