【问题标题】:Creating a transparent backdrop using SharpGL and WPF使用 SharpGL 和 WPF 创建透明背景
【发布时间】:2012-02-25 05:23:19
【问题描述】:

我按照this code project 教程使用 SharpGL 和 WPF 创建了一个控件,允许您将 OpenGL 渲染到其中。太好了,一切正常。

但是,我在 SharpGL WPF 控件后面渲染视频,因此需要渲染的背景是透明的。我该怎么办?

代码:

<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();
}

【问题讨论】:

    标签: c# wpf opengl


    【解决方案1】:

    你没有。

    OpenGL 窗口不是 WPF 窗口。它们是 Win32 HWND。并且 OpenGL 运行的 HWND 不能参与窗口到窗口的透明度。

    【讨论】:

    • 所以我想我对您的回复的后续问题是,有没有办法将我的视频输出渲染到 OpenGL 视图的背景上?
    • @bobble14988:您可以获取视频图像,将其作为纹理加载到 OpenGL,然后使用 GL 命令进行绘制。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-12
    • 1970-01-01
    • 2016-04-21
    • 1970-01-01
    • 2020-09-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多