Is there a simple possibility to change background color?

if i follow the instructions to load a simple scene (car.x3d). it is displayed with a black background. Is there a simple possibility to change that to another color?

Viewport.Background := White; is accepted but background is still black.

I think it should be Viewport.BackgroundColor. But the problem is car.x3d also define it’s own Background node, which will override Viewport’s Background setting, if you set it as MainScene.

So if you follow the instructions in Loading, displaying a scene (simple loading of 3D models) | Manual | Castle Game Engine, then you can do one of the following options:

  1. Remove the <Background /> node in car.x3d, or
  2. Remove the model from MainScene (you then need to set Viewport.Items.UseHeadlight := hlOn;), or
  3. Change the color of Background node directly, either by editing car.x3d directly, or by using code.
1 Like

Yes you are right. Viewport.BackgroundColor is that property.
I have changed both colors in Background Node to “1 1 1” and now i have a beutiful white Background.

thank you!

I have updated the sample car/road 3D models to be glTF (as mentioned on https://forum.castle-engine.io/t/scene-load-in-documentation/ ). As a side-effect, this surprising behavior is now gone, because the glTF models don’t contain any Background.

So now simply adding something like Viewport.BackgroundColor := Yellow; to the simple source as in Loading, displaying a scene (simple loading of 3D models) | Manual | Castle Game Engine , https://castle-engine.io/code-samples/view_3d_model_basic.lpr would just work.

Of course the solutions mentioned by @kagamma still apply, if you decide to use X3D model with Background for any reason – you can edit Background node in X3D, or you can not make the model a MainScene (then Background node inside is ignored).