Skip to content

Commit b0977f6

Browse files
authored
Merge pull request #123 from resibots/background_color
Add the possibility to change the background color
2 parents 187af87 + 1e15a1d commit b0977f6

13 files changed

+42
-18
lines changed

src/examples/talos.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ int main()
3232
robot_dart::RobotDARTSimu simu(dt);
3333
simu.set_collision_detector("fcl");
3434
#ifdef GRAPHIC
35-
auto graphics = std::make_shared<robot_dart::gui::magnum::Graphics>();
35+
robot_dart::gui::magnum::GraphicsConfiguration configuration;
36+
configuration.width = 1280;
37+
configuration.height = 960;
38+
configuration.bg_color = Eigen::Vector4d{1.0, 1.0, 1.0, 1.0};
39+
auto graphics = std::make_shared<robot_dart::gui::magnum::Graphics>(configuration);
3640
simu.set_graphics(graphics);
3741
graphics->look_at({0., 3.5, 2.}, {0., 0., 0.25});
3842
graphics->record_video("talos_dancing.mp4");

src/python/ci.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def clone(self):
3838

3939
# Add robot and floor to the simulation
4040
simu.add_robot(robot)
41-
simu.add_checkerboard_floor(10., 0.1, 1., np.zeros((6,1)), "floor")
41+
simu.add_checkerboard_floor()
4242

4343
simu.run(5.)
4444

src/python/example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def __call__(self):
5858

5959
# Add robot and floor to the simulation
6060
simu.add_robot(robot)
61-
simu.add_checkerboard_floor(10., 0.1, 1., np.zeros((6,1)), "floor")
61+
simu.add_checkerboard_floor()
6262

6363
# Add a camera sensor to the end-effector of the manipulator
6464
camera = rd.sensor.Camera(graphics.magnum_app(), 256, 256)

src/python/gui.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ namespace robot_dart {
8686
.def_readwrite("data", &gui::GrayscaleImage::data);
8787

8888
py::class_<GraphicsConfiguration>(sm, "GraphicsConfiguration")
89-
.def(py::init<size_t, size_t, const std::string&, bool, bool, size_t, size_t, double, bool, bool>(),
89+
.def(py::init<size_t, size_t, const std::string&, bool, bool, size_t, size_t, double, bool, bool, const Eigen::Vector4d&>(),
9090
py::arg("width") = 640,
9191
py::arg("height") = 480,
9292
py::arg("title") = "DART",
@@ -96,7 +96,8 @@ namespace robot_dart {
9696
py::arg("max_lights") = 3,
9797
py::arg("specular_strength") = 0.25,
9898
py::arg("draw_main_camera") = true,
99-
py::arg("draw_debug") = true)
99+
py::arg("draw_debug") = true,
100+
py::arg("bg_color") = Eigen::Vector4d(0.0, 0.0, 0.0, 1.0))
100101

101102
.def_readwrite("width", &GraphicsConfiguration::width)
102103
.def_readwrite("height", &GraphicsConfiguration::height)
@@ -107,7 +108,12 @@ namespace robot_dart {
107108
.def_readwrite("shadow_map_size", &GraphicsConfiguration::shadow_map_size)
108109

109110
.def_readwrite("max_lights", &GraphicsConfiguration::max_lights)
110-
.def_readwrite("specular_strength", &GraphicsConfiguration::specular_strength);
111+
.def_readwrite("specular_strength", &GraphicsConfiguration::specular_strength)
112+
113+
.def_readwrite("draw_main_camera", &GraphicsConfiguration::draw_main_camera)
114+
.def_readwrite("draw_debug", &GraphicsConfiguration::draw_debug)
115+
116+
.def_readwrite("bg_color", &GraphicsConfiguration::bg_color);
111117

112118
py::class_<gui::Base, std::shared_ptr<gui::Base>>(sm, "Base");
113119
py::class_<BaseWindowedGraphics, gui::Base, std::shared_ptr<BaseWindowedGraphics>>(sm, "BaseWindowedGraphics");

src/python/simu.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ namespace robot_dart {
170170
py::arg("floor_width") = 10.,
171171
py::arg("floor_height") = 0.1,
172172
py::arg("size") = 1.,
173+
py::arg("first_color") = dart::Color::White(1.),
174+
py::arg("second_color") = dart::Color::Gray(1.),
173175
py::arg("pose") = Eigen::Vector6d::Zero(),
174176
py::arg("floor_name") = "checkerboard_floor")
175177

src/robot_dart/gui/magnum/base_application.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ namespace robot_dart {
107107
// These options are only for the main camera
108108
bool draw_main_camera = true;
109109
bool draw_debug = true;
110+
111+
// Background (default = black)
112+
Eigen::Vector4d bg_color{0.0, 0.0, 0.0, 1.0};
110113
};
111114

112115
struct DebugDrawData {

src/robot_dart/gui/magnum/glfw_application.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ namespace robot_dart {
1717
_speed_move(0.f),
1818
_speed_strafe(0.f),
1919
_draw_main_camera(configuration.draw_main_camera),
20-
_draw_debug(configuration.draw_debug)
20+
_draw_debug(configuration.draw_debug),
21+
_bg_color(configuration.bg_color[0],
22+
configuration.bg_color[1],
23+
configuration.bg_color[2],
24+
configuration.bg_color[3])
2125
{
2226
/* Try 16x MSAA */
2327
Configuration conf;
@@ -73,8 +77,8 @@ namespace robot_dart {
7377
Magnum::GL::Renderer::setBlendFunction(Magnum::GL::Renderer::BlendFunction::SourceAlpha, Magnum::GL::Renderer::BlendFunction::OneMinusSourceAlpha);
7478
Magnum::GL::Renderer::setBlendEquation(Magnum::GL::Renderer::BlendEquation::Add);
7579

76-
/* Change default clear color to black */
77-
Magnum::GL::Renderer::setClearColor(Magnum::Vector4{0.f, 0.f, 0.f, 1.f});
80+
/* Change clear color to _bg_color */
81+
Magnum::GL::Renderer::setClearColor(_bg_color);
7882

7983
Magnum::GL::defaultFramebuffer.bind();
8084
Magnum::GL::defaultFramebuffer.clear(

src/robot_dart/gui/magnum/glfw_application.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ namespace robot_dart {
2626
RobotDARTSimu* _simu;
2727
Magnum::Float _speed_move, _speed_strafe;
2828
bool _draw_main_camera, _draw_debug;
29+
Magnum::Color4 _bg_color;
2930

3031
static constexpr Magnum::Float _speed = 0.05f;
3132

src/robot_dart/gui/magnum/sensor/camera.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ namespace robot_dart {
6969
Magnum::GL::Renderer::setBlendFunction(Magnum::GL::Renderer::BlendFunction::SourceAlpha, Magnum::GL::Renderer::BlendFunction::OneMinusSourceAlpha);
7070
Magnum::GL::Renderer::setBlendEquation(Magnum::GL::Renderer::BlendEquation::Add);
7171

72-
/* Change default clear color to black */
72+
/* Change clear color to black */
7373
Magnum::GL::Renderer::setClearColor(Magnum::Vector4{0.f, 0.f, 0.f, 1.f});
7474

7575
/* Bind the framebuffer */

src/robot_dart/gui/magnum/windowless_gl_application.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ namespace robot_dart {
1212
Magnum::Platform::WindowlessApplication({argc, argv}, Magnum::NoCreate),
1313
_simu(simu),
1414
_draw_main_camera(configuration.draw_main_camera),
15-
_draw_debug(configuration.draw_debug)
15+
_draw_debug(configuration.draw_debug),
16+
_bg_color(configuration.bg_color[0],
17+
configuration.bg_color[1],
18+
configuration.bg_color[2],
19+
configuration.bg_color[3])
1620
{
1721
/* Assume context is given externally, if not create it */
1822
if (!Magnum::GL::Context::hasCurrent()) {
@@ -65,8 +69,8 @@ namespace robot_dart {
6569
Magnum::GL::Renderer::setBlendFunction(Magnum::GL::Renderer::BlendFunction::SourceAlpha, Magnum::GL::Renderer::BlendFunction::OneMinusSourceAlpha);
6670
Magnum::GL::Renderer::setBlendEquation(Magnum::GL::Renderer::BlendEquation::Add);
6771

68-
/* Change default clear color to black */
69-
Magnum::GL::Renderer::setClearColor(Magnum::Vector4{0.f, 0.f, 0.f, 1.f});
72+
/* Change clear color to _bg_color */
73+
Magnum::GL::Renderer::setClearColor(_bg_color);
7074

7175
/* Bind the framebuffer */
7276
_framebuffer.bind();

0 commit comments

Comments
 (0)