I followed this code project tutorial for using SharpGL with WPF to create a control which allows you to render OpenGL into it. 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. 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. They are Win32 HWNDs. And HWNDs run by OpenGL cannot participate in window-to-window transparency.