我遵循了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();
}发布于 2012-02-25 05:23:20
你没有。
OpenGL窗口不是WPF窗口。他们是Win32 HWND。由OpenGL运行的HWND不能参与窗口到窗口的透明性。
https://stackoverflow.com/questions/9438199
复制相似问题