【发布时间】: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();
}
【问题讨论】: