This example shows how to create depth images from the rendering.
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>
44TutorialDepthMap::TutorialDepthMap(
const std::string& title)
48 camera()->setUpVector(
vec3(0, 1, 0));
49 camera()->setViewDirection(
vec3(0, 0, -1));
50 camera_->showEntireScene();
54TutorialDepthMap::~TutorialDepthMap() {
62void TutorialDepthMap::draw()
const {
68void TutorialDepthMap::generate_depth() {
69 static const std::string name =
"shadow/shadow_generate";
72 std::vector<ShaderProgram::Attribute> attributes;
74 program = ShaderManager::create_program_from_files(name, attributes);
80 fbo_->deactivate_draw_buffers();
81 glClear(GL_DEPTH_BUFFER_BIT);
83 program->
set_uniform(
"MVP", camera()->modelViewProjectionMatrix());
84 for (
auto m : models_) {
85 for (
auto d : m->renderer()->points_drawables()) {
86 if (d->is_visible()) {
87 glPointSize(d->point_size());
91 for (
auto d : m->renderer()->triangles_drawables()) {
101void TutorialDepthMap::draw_depth()
const {
102 auto viewer =
const_cast<TutorialDepthMap*
>(
this);
103 auto w =
static_cast<float>(width()) * dpi_scaling();
104 auto h =
static_cast<float>(height()) * dpi_scaling();
107 const int samples = 0;
108 viewer->fbo_ =
new FramebufferObject(
static_cast<int>(w),
static_cast<int>(h), samples);
109 viewer->fbo_->add_depth_texture(GL_DEPTH_COMPONENT32F, GL_LINEAR, GL_COMPARE_REF_TO_TEXTURE, GL_LEQUAL);
111 fbo_->ensure_size(
static_cast<int>(w),
static_cast<int>(h));
114 viewer->generate_depth();
116 const Rect quad(20 * dpi_scaling(), 20 * dpi_scaling() + w/4, 40 * dpi_scaling(), 40 * dpi_scaling() + h/4);
117 shape::draw_depth_texture(quad, fbo_->depth_texture(),
static_cast<int>(w),
static_cast<int>(h), -0.9f);
118 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, where the origin of the coordinate system ...
Definition rect.h:45
OpenGL Shader Compilation.
Definition shader_program.h:75
void bind() const
Start using the program.
Definition shader_program.cpp:678
ShaderProgram * set_uniform(const std::string &name, const void *value)
Set the uniform to value.
Definition shader_program.cpp:436
void release() const
End using the program.
Definition shader_program.cpp:689
std::pair< AttribType, std::string > Attribute
Attribute: a pair of attribute type and attribute name.
Definition shader_program.h:85
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>
50int main(
int argc,
char **argv) {
54 TutorialDepthMap viewer(EXAMPLE_TITLE);
57 const std::string file_name = resource::directory() +
"/data/fountain/pointcloud.ply";
58 auto model = viewer.add_model(file_name,
true);
60 LOG(ERROR) <<
"failed to load model. Please make sure the file exists and format is correct.";
64 auto drawable = model->renderer()->get_points_drawable(
"vertices");
65 drawable->set_point_size(5);