Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

OpenGL Rendering with WPF

$
0
0

Hi

I have read the other post and forum on using windows form host control on how to Render OpenGL in WPF.

I am using a CAD kernel(Open cascade) based on C++ and i have created C# wrappers using SWIG.

I am able to run CAD viewer (based on OpenGL  provided by open cascade) in winform and using host control in WPF too.

I am bit curies to understand what will happen if i directly pass WPF MainWindow handle into SWIG wrapper class(without form host control). i did the same i have noticed following behavior as shown in image. 

After few seconds the window rendered with white layer (OpenGL drawing got erased by white color as i understood. My understanding could be wrong also)

I would like to know why / how the opengl painting (based on GDI) taken place initially and then its replaced  with WPF presentation layer.

Code Snippet

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using OCCWrappers.View;
using OCCWrappers.AIS;
using OCCWrappers.Quantity;
using OCCWrappers.Aspect;
using System.Windows.Interop;

namespace OCCTestWPF
{
    /// <summary>
    /// Interaction logic for OCCWPF.xaml
    /// </summary>
    public partial class OCCWPF : Window
    {
        Display3d display;
        Handle_V3d_Viewer _hViewer;
        Handle_V3d_View _hView;
        V3d_Viewer _viewer;
        V3d_View _view;
        Handle_AIS_InteractiveContext _hContext;
        AIS_InteractiveContext _context;

        public OCCWPF()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(OCCWPF_Loaded);
        }

        void OCCWPF_Loaded(object sender, RoutedEventArgs e)
        {
            IntPtr _handle = new WindowInteropHelper(Application.Current.MainWindow).Handle;
            SetUpOcc(_handle);
            
        }
        protected override void OnRender(DrawingContext drawingContext)
        {
            //base.OnRender(drawingContext);
        }

        private void SetUpOcc(IntPtr Handle)
        {
            display = new Display3d();
            display.Init(Handle);
            _hViewer = display.GetViewer();
            _viewer = _hViewer.GetObject();
            _viewer.SetDefaultLights();
            _hView = display.GetView();
            _view = _hView.GetObject();
            display.Test();
            display.TestCircle();
            display.ShowCoordinateAxis();
            _view.SetProj(V3d_TypeOfOrientation.V3d_Xneg);
            _view.SetBackgroundColor(Quantity_NameOfColor.Quantity_NOC_BLACK);
            _view.FitAll();
            _view.TriedronDisplay(Aspect_TypeOfTriedronPosition.Aspect_TOTP_LEFT_LOWER, Quantity_NameOfColor.Quantity_NOC_WHITE, 1e-1, V3d_TypeOfVisualization.V3d_ZBUFFER);
            _view.Update();
            _hContext = display.GetContext();
            _context = _hContext.GetObject();
        }
    }
}


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>