Exemplo n.º 1
0
        private void DXControl_Load(object sender, EventArgs e)
        {
            if (this.DesignMode)
            {
                return;
            }

            editorEngine = new VisualEngine(new StringBuilder("Editor"));

            // Add a relative path where the textures are located
            editorEngine.Textures.AddRelativePath("Textures");

            // The RenderTarget used for rendering

            renderRenderTarget = editorEngine.CreateSwapChainRenderTarget("SwapChain", this.Handle);

            renderView = editorEngine.RenderViews.Create(renderRenderTarget);

            renderView.DepthStencil = editorEngine.DepthStencils.Create(new StringBuilder("MainDepthStencil"), renderView.RenderTarget.Width, renderView.RenderTarget.Height);

            // When a resize of this control happens, i need to recreate this view
            onResizeMethods.Add((w, h) => renderView.Resize(w, h));

            this.ParentForm.FormClosed += ParentForm_FormClosed;

            OnInitializeRender();
        }
Exemplo n.º 2
0
        void Window1_Loaded(object sender, RoutedEventArgs e)
        {
            // The unloaded method is not working, so we attach to the parent window closing event the code to Destroy the resources
            Window.GetWindow(this).Closing += (s1, e1) => RenderControl_Closed(s1, e1);

            // We can use any resolution, because the OnResize event will be fired and the right dimensions will be set

            int anyWidth = 640;

            int anyHeight = 480;

            // For WPF we need to create a DX9RenderTarget.
            backBufferRenderTarget = editorEngine.CreateDX9SharedRenderTarget(renderName + ".DX9BackBuffer", anyWidth, anyHeight);

            // We need a View for Each RenderTarget. A View is the sum of a ViewPort, a RenderTarget and a DepthStencil
            // We do not need a DepthStencil for the Backbuffer has it's only used to copy the contents of the Render to a DX9 shader resource

            backBufferView = editorEngine.RenderViews.Create(backBufferRenderTarget);

            // We do not need to use the Depth because when all the render is ready, the renderview is copied to the backbufferview
            backBufferView.State.DepthEnabled = false;

            // When a resize of this control happens, i need to recreate this view
            onResizeMethods.Add((w, h) => backBufferView.Resize(w, h));

            // The RenderTarget used for rendering

            renderRenderTarget = editorEngine.RenderTargets.Create(renderName, anyWidth, anyHeight);

            renderView = editorEngine.RenderViews.Create(renderRenderTarget);

            renderView.DepthStencil = editorEngine.DepthStencils.Create(new StringBuilder("MainDepthStencil"), renderView.RenderTarget.Width, renderView.RenderTarget.Height);

            // When a resize of this control happens, i need to recreate this view
            onResizeMethods.Add((w, h) => renderView.Resize(w, h));

            /* Create a new D3DImageEx class */
            m_d3DImageEx = new D3DImageEx();

            /* Set our image's source to our D3DImage9Ex */
            d3dScene.Source = m_d3DImageEx;

            /* Set the backbuffer, which is a ID3D10Texture2D pointer */
            m_d3DImageEx.SetBackBufferEx(D3DResourceTypeEx.ID3D10Texture2D, backBufferRenderTarget.Texture.InternalTexture2D.GetTexturePtr());

            OnInitializeRender();

            // Create the timer

            dispatcherTimer          = new System.Windows.Threading.DispatcherTimer();
            dispatcherTimer.Tick    += new EventHandler(dispatcherTimer_Tick);
            dispatcherTimer.Interval = TimeSpan.FromMilliseconds(33);
            dispatcherTimer.Start();

            // Add the OnDraw event for this control
            CompositionTarget.Rendering += CompositionTarget_Rendering;
        }