Hi, I am trying to use VTK in Avalonia for Windows application development (Avalonia version: 11.0.10, VTK version: 9.3). According to HelloVTKAvalonia provided in official Examples, I need to set RenderingMode to Wgl:
.With(new Win32PlatformOptions { RenderingMode = new[] { Win32RenderingMode.Wgl } })
.With(new X11PlatformOptions { RenderingMode = new[] { X11RenderingMode.Glx } });
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Kitware.AvaloniaControls;
using Kitware.VTK;
using System;
namespace HelloVTKAvalonia
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
RenderWindowControl ctrl = this.FindControl<RenderWindowControl>("VTKControl");
if (ctrl != null)
{
ctrl.AttachedToVisualTree += InitVTKScene;
}
}
public void InitVTKScene(object? sender, EventArgs args)
{
RenderWindowControl? mainView = sender as RenderWindowControl;
vtkRenderWindow renderWindow = mainView.RenderWindow;
vtkRenderer renderer = vtkRenderer.New();
renderer.SetBackgroundAlpha(1.0);
renderWindow.AddRenderer(renderer);
vtkInteractorStyleTrackballCamera interactorStyle = vtkInteractorStyleTrackballCamera.New();
renderWindow.GetInteractor().SetInteractorStyle(interactorStyle);
vtkSphereSource src = vtkSphereSource.New();
vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
mapper.SetInputConnection(src.GetOutputPort());
vtkActor actor = vtkActor.New();
actor.SetMapper(mapper);
renderer.AddActor(actor);
}
}
}
However, Wgl mode does not support transparency, making it impossible to present good-looking themes in Avalonia, such as Fluent Theme. But if I don’t add this setting, VTK won’t be able to render.
If not use Wgl, is there a better choice here?