Some C++ problems such as setbakgroundcolor


#1

As we know in python it is easy to use setBackgroundcolor,
is there similar API for C++? I’m sorry didn’t find it in the manual or reference

Besides, how can I change the type “LVecBase4f” to “std::string” quickly?
Please help


#2

You can use one of the preset background types:

winfwx->set_background_type(WindowFramework::BT_default);
winfwx->set_background_type(WindowFramework::BT_black);
winfwx->set_background_type(WindowFramework::BT_gray);
winfwx->set_background_type(WindowFramework::BT_white);
winfwx->set_background_type(WindowFramework::BT_none);

Or you can set your own clear settings on the 3D display region:

winfwx->set_background_type(WindowFramework::BT_other);

DisplayRegion *region = winfwx->get_display_region_3d();
region->set_clear_color_active(true);
region->set_clear_depth_active(true);
region->set_clear_stencil_active(true);
region->set_clear_color(LColor(1.0f, 1.0f, 1.0f, 0.0f));
region->set_clear_depth(1.0f);
region->set_clear_stencil(0);

Or you can set them directly onto the whole window rather than on the 3D display region:

winfwx->set_background_type(WindowFramework::BT_none);

GraphicsWindow *window = winfwx->get_graphics_window();
window->set_clear_color_active(true);
window->set_clear_depth_active(true);
window->set_clear_stencil_active(true);
window->set_clear_color(LColor(1.0f, 1.0f, 1.0f, 0.0f));
window->set_clear_depth(1.0f);
window->set_clear_stencil(0);

I’m not exactly sure what you mean by getting a LVecBase4f into a string. You could easily format the four components in whichever way you see fit, but you can also output it to a stream:

std::ostringstream s;
s << LVecBase4(0.0f, 0.0f, 0.0f, 1.0f);
std::string str = s.str();

#3

Thank you, that’s what I need exactly.