首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用SharpGL和WPF创建透明背景

使用SharpGL和WPF创建透明背景
EN

Stack Overflow用户
提问于 2012-02-25 05:18:41
回答 1查看 1.7K关注 0票数 0

我遵循了this code project教程,使用SharpGL和WPF来创建一个控件,允许您将OpenGL呈现到其中。太好了,一切都很好。

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

代码:

代码语言:javascript
复制
<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();
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-02-25 05:23:20

你没有。

OpenGL窗口不是WPF窗口。他们是Win32 HWND。由OpenGL运行的HWND不能参与窗口到窗口的透明性。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9438199

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档