O'Reilly logo

Qt 5 Projects by Marco Piccolino

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding custom lighting and changing the background color

We can also add a custom light source to the composition. There are a few types of light sources, exposed by the Qt3D.Render module: DirectionalLight, PointLight, and SpotLight. We will choose a DirectionalLight (https://doc.qt.io/qt-5.9/qml-qt3d-render-directionallight.html). In Qt 3D, lights are not entities but components. We should thus add it as a component to the composition.

Finally, we want to be able to change the composition's background color from the GUI. To do so, we expose the clearColor property of ForwardRenderer as part of the Composition API:

// Composition.qmlimport Qt3D.Core 2.0import Qt3D.Render 2.0import Qt3D.Input 2.0import Qt3D.Extras 2.0Entity { id: composition ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required