# Render Background white and transparent

**URL:** https://discourse.vtk.org/t/render-background-white-and-transparent/2480
**Category:** Support
**Created:** [January 22, 2020, 12:35pm UTC](https://discourse.vtk.org/t/render-background-white-and-transparent/2480 "2020-01-22T12:35:18Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Ana\_Margarida\_Mota](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ana_margarida_mota/32/1287_2.png) [@Ana\_Margarida\_Mota](https://discourse.vtk.org/u/Ana_Margarida_Mota)
#### Post date: [January 22, 2020, 12:35pm UTC](https://discourse.vtk.org/t/render-background-white-and-transparent/2480/1 "2020-01-22T12:35:18Z")

</div>

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!!

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [January 24, 2020, 4:33am UTC](https://discourse.vtk.org/t/render-background-white-and-transparent/2480/3 "2020-01-24T04:33:23Z")

</div>

I have written an example for you [TransparentBackground.py](https://discourse.vtk.org/uploads/short-url/5602PREMhqASGA181RSfYpKUCI4.py) (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.

 ![TransparentBackground](https://discourse.vtk.org/uploads/default/original/2X/6/6766340599d4fefb94c859c6a7ce813dc64dca54.png)  
If you need a C++ version, I can translate this for you.

---

<div class="post-metadata">

### Author: ![Ana\_Margarida\_Mota](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ana_margarida_mota/32/1287_2.png) [@Ana\_Margarida\_Mota](https://discourse.vtk.org/u/Ana_Margarida_Mota)
#### Post date: [February 10, 2020, 3:04pm UTC](https://discourse.vtk.org/t/render-background-white-and-transparent/2480/4 "2020-02-10T15:04:52Z")

</div>

Dear Andrew Maclean,

Is was very useful!! thank you!!

---

<div class="post-metadata">

### Author: ![lllaa](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/l/aca169/32.png) [@lllaa](https://discourse.vtk.org/u/lllaa)
#### Post date: [June 18, 2020, 9:51am UTC](https://discourse.vtk.org/t/render-background-white-and-transparent/2480/5 "2020-06-18T09:51:35Z")

</div>

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

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [June 18, 2020, 10:14am UTC](https://discourse.vtk.org/t/render-background-white-and-transparent/2480/6 "2020-06-18T10:14:11Z")

</div>

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

---

<div class="post-metadata">

### Author: ![lllaa](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/l/aca169/32.png) [@lllaa](https://discourse.vtk.org/u/lllaa)
#### Post date: [June 18, 2020, 10:15am UTC](https://discourse.vtk.org/t/render-background-white-and-transparent/2480/7 "2020-06-18T10:15:45Z")

</div>

Thank you🙏

---

<div class="post-metadata">

### Author: ![lllaa](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/l/aca169/32.png) [@lllaa](https://discourse.vtk.org/u/lllaa)
#### Post date: [June 18, 2020, 10:53am UTC](https://discourse.vtk.org/t/render-background-white-and-transparent/2480/8 "2020-06-18T10:53:34Z")

</div>

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

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [June 18, 2020, 11:34pm UTC](https://discourse.vtk.org/t/render-background-white-and-transparent/2480/9 "2020-06-18T23:34:33Z")

</div>

@lllaa Here are the files: [TransparentBackground.zip](https://discourse.vtk.org/uploads/short-url/3Hlp6NMpnF10Hhqm8ZX9JBt3Mr5.zip) (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.

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [June 19, 2020, 12:04am UTC](https://discourse.vtk.org/t/render-background-white-and-transparent/2480/10 "2020-06-19T00:04:30Z")

</div>

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/TransparentBackground.py` and `src/Cxx/Rendering/TransparentBackground.cxx`.

Regards  
Andrew

---

<div class="post-metadata">

### Author: ![lllaa](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/l/aca169/32.png) [@lllaa](https://discourse.vtk.org/u/lllaa)
#### Post date: [June 19, 2020, 7:16am UTC](https://discourse.vtk.org/t/render-background-white-and-transparent/2480/12 "2020-06-19T07:16:39Z")

</div>

a

---

<div class="post-metadata">

### Author: ![lllaa](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/l/aca169/32.png) [@lllaa](https://discourse.vtk.org/u/lllaa)
#### Post date: [June 19, 2020, 7:18am UTC](https://discourse.vtk.org/t/render-background-white-and-transparent/2480/13 "2020-06-19T07:18:03Z")

</div>

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](https://discourse.vtk.org/uploads/default/original/2X/4/446c5fc25a7b98340c1661bcacb090a83b7c7f15.png) ![2](https://discourse.vtk.org/uploads/default/original/2X/a/a2649efb99f4c136a219704a84b605bbe6409c96.png)
