# overlay/transparency issue with QVTKOpenGLNativeWidget

**URL:** https://discourse.vtk.org/t/overlay-transparency-issue-with-qvtkopenglnativewidget/196
**Category:** Support
**Created:** [February 1, 2019, 4:46pm UTC](https://discourse.vtk.org/t/overlay-transparency-issue-with-qvtkopenglnativewidget/196 "2019-02-01T16:46:50Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![mikewho](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/f1d935/32.png) [@mikewho](https://discourse.vtk.org/u/mikewho)
#### Post date: [February 1, 2019, 4:46pm UTC](https://discourse.vtk.org/t/overlay-transparency-issue-with-qvtkopenglnativewidget/196/1 "2019-02-01T16:46:50Z")

</div>

I had previously been using QVTKWidget in VTK 7.1.0 with no issues. I decided to upgrade to VTK 8.2.0 and try out QVTKOpenGLNativeWidget. However I am noticing that with the new widget when I overlay two vtkImageActors, the opacity on the top one is reduced for some reason. You can see the attached example. The blue was full opacity before (as it was meant to be), but now is reduced. I’ve put some code below. Any help would be much appreciated! Thanks.

 ![example](https://discourse.vtk.org/uploads/default/original/1X/74a8c3cd5b50b39db848886f8e20e341d424f05a.jpeg)

And here is a snippet of code that should give an idea of my pipeline:

```
    QVTKOpenGLNativeWidget *window = new QVTKOpenGLNativeWidget();
	window->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
	window->setMinimumSize(QSize(580, 330));
	window->enableHiDPI();
	
	vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();

	for (int i = 0; i < 2; ++i)
	{
		// map
		vtkSmartPointer<vtkImageMapToColors> imapper = vtkSmartPointer<vtkImageMapToColors>::New();
		imapper->SetLookupTable(lut[i]); // custom lookup tables (one is just normal grayscale, the other is blue with full transparency on the low end and no transparency on the high end
		imapper->PassAlphaToOutputOn();
		// im[0] and im[1] are my vtkImageData that I load up from saved images
		imapper->SetInputData(im[i]); 
		imapper->Update();

		// actor
		vtkSmartPointer<vtkImageActor> iactor = vtkSmartPointer<vtkImageActor>::New();
		iactor->GetMapper()->SetInputConnection(imapper->GetOutputPort());

		renderer->AddActor(iactor);
	}
	
	renderer->ResetCameraClippingRange();

	window->GetRenderWindow()->AddRenderer(renderer);
	window->GetRenderWindow()->Render();

```

This is on Windows 10, 64-bit. Using Visual Studio 2017.

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [February 1, 2019, 6:26pm UTC](https://discourse.vtk.org/t/overlay-transparency-issue-with-qvtkopenglnativewidget/196/2 "2019-02-01T18:26:52Z")

</div>

You might need to enable depth peeling to ensure rendering of semi-transparent polygons in the correct order.

---

<div class="post-metadata">

### Author: ![mikewho](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/f1d935/32.png) [@mikewho](https://discourse.vtk.org/u/mikewho)
#### Post date: [February 1, 2019, 6:49pm UTC](https://discourse.vtk.org/t/overlay-transparency-issue-with-qvtkopenglnativewidget/196/3 "2019-02-01T18:49:46Z")

</div>

Thanks for the suggestion! Depth peeling helped but still produced some odd opacity issues. However after offsetting the images very slightly (1e-6) the depth peeling was then able to process them correctly. Thanks.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [February 4, 2019, 10:19am UTC](https://discourse.vtk.org/t/overlay-transparency-issue-with-qvtkopenglnativewidget/196/4 "2019-02-04T10:19:46Z")

</div>

Did you try with QVTKOpenGLWidget as well ?

---

<div class="post-metadata">

### Author: ![mikewho](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/f1d935/32.png) [@mikewho](https://discourse.vtk.org/u/mikewho)
#### Post date: [February 4, 2019, 11:44am UTC](https://discourse.vtk.org/t/overlay-transparency-issue-with-qvtkopenglnativewidget/196/5 "2019-02-04T11:44:58Z")

</div>

Yes, I found that QVTKOpenGLWidget had the same issues, but also had some other issues with Qt (like overlaying Qt widgets) that the Native version didn’t have.

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [February 5, 2019, 5:05pm UTC](https://discourse.vtk.org/t/overlay-transparency-issue-with-qvtkopenglnativewidget/196/6 "2019-02-05T17:05:38Z")

</div>

If you have multiple things exactly in the same position then you need to apply one of the coincident topology resolution techniques. See for example [http://vtk.1045678.n5.nabble.com/Coincident-topology-questions-td5746090.html](http://vtk.1045678.n5.nabble.com/Coincident-topology-questions-td5746090.html)

---

<div class="post-metadata">

### Author: ![mikewho](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/f1d935/32.png) [@mikewho](https://discourse.vtk.org/u/mikewho)
#### Post date: [March 4, 2019, 8:47pm UTC](https://discourse.vtk.org/t/overlay-transparency-issue-with-qvtkopenglnativewidget/196/7 "2019-03-04T20:47:51Z")

</div>

Unfortunately it appears that the use of depth peeling slows down image rendering substantially. For now I will have to revert back to VTK 7.1.0.

---

<div class="post-metadata">

### Author: ![mikewho](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/f1d935/32.png) [@mikewho](https://discourse.vtk.org/u/mikewho)
#### Post date: [March 5, 2019, 8:20pm UTC](https://discourse.vtk.org/t/overlay-transparency-issue-with-qvtkopenglnativewidget/196/8 "2019-03-05T20:20:33Z")

</div>

For anyone who is curious, I found a solution for this using VTK 8.2.0. In the function vtkOpenGLRenderer::DeviceRenderTranslucentPolygonalGeometry() you uncomment the line after the “// old code” line, and comment out the block below that which starts with “// new approach”. It looks like it was an attempt to improve how translucent geometry was rendered, but made it necessary to use depth peeling (much slower) to get proper translucent effects.
