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>
39int main(
int argc,
char **argv) {
43 DepthImage viewer(EXAMPLE_TITLE);
46 const std::string file_name = resource::directory() +
"/data/fountain/pointcloud.ply";
47 Model *model = viewer.add_model(file_name,
true);
49 LOG(ERROR) <<
"failed to load model. Please make sure the file exists and format is correct.";
54 drawable->
set_point_size(5);
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
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
29#include <easy3d/core/model.h>
30#include <easy3d/renderer/camera.h>
31#include <easy3d/renderer/drawable_points.h>
32#include <easy3d/renderer/drawable_triangles.h>
33#include <easy3d/renderer/framebuffer_object.h>
34#include <easy3d/renderer/shader_manager.h>
35#include <easy3d/renderer/shader_program.h>
36#include <easy3d/renderer/shape.h>
37#include <easy3d/renderer/renderer.h>
43DepthImage::DepthImage(
const std::string& title)
47 camera()->setUpVector(
vec3(0, 1, 0));
48 camera()->setViewDirection(
vec3(0, 0, -1));
49 camera_->showEntireScene();
53DepthImage::~DepthImage() {
61void DepthImage::draw()
const {
67void DepthImage::generate_depth() {
68 static const std::string name =
"shadow/shadow_generate";
71 std::vector<ShaderProgram::Attribute> attributes;
72 attributes.emplace_back(ShaderProgram::Attribute(ShaderProgram::POSITION,
"vtx_position"));
73 program = ShaderManager::create_program_from_files(name, attributes);
79 fbo_->deactivate_draw_buffers();
80 glClear(GL_DEPTH_BUFFER_BIT);
82 program->
set_uniform(
"MVP", camera()->modelViewProjectionMatrix());
83 for (
auto m : models_) {
84 for (
auto d : m->renderer()->points_drawables()) {
85 if (d->is_visible()) {
86 glPointSize(d->point_size());
90 for (
auto d : m->renderer()->triangles_drawables()) {
100void DepthImage::draw_depth()
const {
101 auto viewer =
const_cast<DepthImage*
>(
this);
102 auto w =
static_cast<float>(width()) * dpi_scaling();
103 auto h =
static_cast<float>(height()) * dpi_scaling();
106 const int samples = 0;
107 viewer->fbo_ =
new FramebufferObject(
static_cast<int>(w),
static_cast<int>(h), samples);
108 viewer->fbo_->add_depth_texture(GL_DEPTH_COMPONENT32F, GL_LINEAR, GL_COMPARE_REF_TO_TEXTURE, GL_LEQUAL);
110 fbo_->ensure_size(
static_cast<int>(w),
static_cast<int>(h));
113 viewer->generate_depth();
115 const Rect quad(20 * dpi_scaling(), 20 * dpi_scaling() + w/4, 40 * dpi_scaling(), 40 * dpi_scaling() + h/4);
116 shape::draw_depth_texture(quad, fbo_->depth_texture(),
static_cast<int>(w),
static_cast<int>(h), -0.9f);
117 shape::draw_quad_wire(quad,
vec4(1.0f, 0.0f, 0.0f, 1.0f),
static_cast<int>(w),
static_cast<int>(h), -0.99f);
The GenericRect class defines a rectangle in the 2D space.
Definition: rect.h:42
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