Topic was automatically imported from the old Question2Answer platform.
Asked By
Zylann
Old Version
Published before Godot 3 was released.
Just trying to do that, but I find no method for this in the documentation :s
General clear color (like the one on project settings) or you want to have many viewports with different clear color at the same time?
eons | 2016-10-19 22:47
I want to set the clear color of only this specific viewport (and different colors to others if needed)
Zylann | 2016-10-19 23:00
Clear color is something general, I don’t think you will be able to change it per viewport (but is possible to set transparent background on subviewport).
VisualServer has the setter for clear color, for individual viewports (if many) you will have to create a background image (frame/polygon/sprite).
eons | 2016-10-19 23:34
What is the point of being able to set a transparent background if setting a clear color doesn’t works? And why can you set a background color with the Environment if it doesn’t works anyways? I think there is something wrong here.
Make sure the “General” tab is selected, and select the “Render” section.
Check “default_clear_color” and select a background color.
I am using Godot Engine v2.2.alpha, so if this is not possible for you, it means you either have to wait for a newer release or get a more recent build.
This sets the global default clear color. I want to set the clear color of a specific viewport instead of the main one.
(refer to your answer in the linked thread for more details about the code)
THEN:
since you added a sprite to the control node, you can play around with the modulate option!
Note that the sprite can be empty (it is in my case) and serves only as reference and modulation.
It may be a solution, tell me what you think.
Thank you.
PEACE.
It’s another way of drawing a full-viewport rectangle using a texture, I was looking for something that uses an equivalent of glClear, because I doubt the background of Godot games is filled with a texture, right? So since the main window is a viewport, why can’t we set the background color of a Viewport node created manually, especially when there seem to be options to do so (but don’t work)?
Thanks for the answer anyways.
That’s another workaround, but not what I am searching for.
Zylann | 2018-03-29 18:35
And actually that doesn’t seem to work if one wants a transparent background (because the clear already has non-zero alpha, a zero alpha ColorRect has no effect).
To set the record for future questions on the subject, since at least Godot 2.1 you may use VisualServer.set_default_clear_color(Color)(Doc) to set the active viewport’s clear color.
Slightly related note: ProjectSettings (Doc) recommend you use the Viewport’s world.enviroment.background_mode/color variable for viewports however world and environment is a 3D viewport system, and the latter is assigned null in 2D environments and will not be used by the 2D engine, it appears individual viewport clear colors is a relatively noticeable oversight in Godot and it has to be hacked around codewise to properly apply it.