Render Background white and transparent

Dear colleagues,

I need to set the render background to white (until then everything is OK with renderer->SetBackground(1.0,1.0,1.0)) and TRANSPARENT (otherwise my image doesn’t appear, it is everything white).
That’s the problem, I can’t manage to have a white transparten background. I am sure this should be an easy question but I didn’t find a solution for that anywhere.

Thank you in advance!!

I have written an example for you (3.5 KB) . In this a cube is rendered on a Silver non-transparent background and a cone is rendered on MidnightBlue background. You will see that the background is indeed Silver showing that the layer one background is transparent. The proof is that the cube is visible and the background is Silver. I hope this example shows you what to do.

If you need a C++ version, I can translate this for you.

Dear Andrew Maclean,

Is was very useful!! thank you!!

Dear Andrew Maclean,
I need a C++ version .Hope you can translate it for me .Thank you.

I’ll have a look tomorrow and get back to you. I’m pretty sure I added a C++ version to the VTKExamples master.

Andrew Maclean

Thank you🙏

If you had the C++ version already,can you send me a web link? I’d searched your nickname in github but not found.

@lllaa Here are the files: (4.1 KB) . I have also included an updated Python version here. Sometime, over the next few days, I will add these to the VTKExamples site where you will find them in the Rendering section.

It is now in the VTKExamples master. Unfortunately at this stage it will not appear on the web pages. If you ckeck out VTKExamples, look for src/Python/Rendering/ and src/Cxx/Rendering/TransparentBackground.cxx.



Dear Andrew Maclean,
thank for your help.May I ask you another question?
I used QvtkWidget in QT designer.
But the QvtkWidget had a black background when I created it on the “MainWindow”.It makes my photo has a black background.
I want to make the black background diappeared.But I failed to find the way from your code.
I put the pics below.
Wish for your reply.
1 2