简体   繁体   English

使用SharpGL和WPF创建透明背景

[英]Creating a transparent backdrop using SharpGL and WPF

I followed this code project tutorial for using SharpGL with WPF to create a control which allows you to render OpenGL into it. 我遵循了此代码项目教程,将SharpGL与WPF一起使用来创建一个控件,该控件允许您将OpenGL渲染到其中。 Excellent, everything works fine. 太好了,一切正常。

However, I am rendering video behind the SharpGL WPF control and so need the backdrop of the render to be transparent. 但是,我在SharpGL WPF控件后面渲染视频,因此需要渲染的背景透明。 How can I go about this? 我该怎么办?

Code: 码:

<Window x:Class="MyProject.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sharpGL="clr-namespace:SharpGL.WPF;assembly=SharpGL.WPF"
    Title="MainWindow" Height="600" Width="800" Loaded="Window_Loaded">
    <Canvas Height="580" Width="780" Name="CentreCanvas">
        <Image Canvas.Left="0" Canvas.Top="0" Height="565" Name="imageVideoControl" Stretch="Fill" Width="780" />
        <Image Canvas.Left="580" Canvas.Top="0" Height="150" Name="imageDepthControl" Stretch="Fill" Width="200" />
        <sharpGL:OpenGLControl OpenGLDraw="OpenGLControl_OpenGLDraw" Height="565" Width="780"></sharpGL:OpenGLControl>
    . . . 
    </Canvas>
</Window>

private void OpenGLControl_OpenGLDraw(object sender, OpenGLEventArgs args)
{
    // Get the OpenGL instance being pushed to us.
    gl = args.OpenGL;

    // Clear the colour and depth buffers.
    gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

    // Reset the modelview matrix.
    gl.LoadIdentity();

    // Move the geometry into a fairly central position.
    gl.Translate(1.5f, 0.0f, -6.0f);

    // Draw a quad.
    gl.Begin(OpenGL.GL_QUADS);

        // Set colour to red.
        gl.Color(1.0f, 0.0f, 0.0f);

        // Draw some quad...
        . . . 
        . . .

    gl.End();
}

You don't. 你不知道

OpenGL windows are not WPF windows. OpenGL窗口不是WPF窗口。 They are Win32 HWNDs. 它们是Win32 HWND。 And HWNDs run by OpenGL cannot participate in window-to-window transparency. 并且由OpenGL运行的HWND无法参与窗口到窗口的透明性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM