Is it possible to render VC++ OpenGL output to a panel in Winforms window created with C# ? I’m aware of Tao framework and OpenTK but I don’t want to rely on third party support. There is an article here but this is merely only pixel reproduction and I think this method does not guarantee user interaction with OpenGL scene.
Hiho,
I don’t know how your VC++ OpenGL output is realised, but I guess it will need a window (or device/rendering context) to work. So you’ll need a control in WinForms that acts as a canvas for OpenGL, any UserControl that set the class styles CS_VREDRAW, CS_HREDRAW and CS_OWNDC (and some WinForms control styles) should suffice. And since Control.Handle is set public, you can get the HWND handle (as IntPtr) there, and init your OpenGL output in VC++ with it.
public static class CS
{
/// <summary>
/// Redraws the entire window if a movement or size adjustment changes the height of the client area.
/// </summary>
public const int VREDRAW=0x00000001;
/// <summary>
/// Redraws the entire window if a movement or size adjustment changes the width of the client area.
/// </summary>
public const int HREDRAW=0x00000002;
/// <summary>
/// Allocates a unique device context for each window in the class.
/// </summary>
public const int OWNDC=0x00000020;
// ... more
}
public partial class DummyOpenGLControl : UserControl
{
/// <summary>
/// Constructes a new instance of this class.
/// </summary>
public DummyOpenGLControl()
{
SetStyle(ControlStyles.AllPaintingInWmPaint|ControlStyles.Opaque|ControlStyles.ResizeRedraw|ControlStyles.UserPaint, true);
SetStyle(ControlStyles.OptimizedDoubleBuffer, false);
InitializeComponent();
}
/// <summary>
/// Adds the class styles <see cref="CS.VREDRAW"/>, <see cref="CS.HREDRAW"/> and <see cref="CS.OWNDC"/> to support OpenGL rendering.
/// </summary>
protected override CreateParams CreateParams
{
get
{
CreateParams cp=base.CreateParams;
cp.ClassStyle|=CS.VREDRAW|CS.HREDRAW|CS.OWNDC;
// maybe cp.Style|=WS.CLIPCHILDREN|WS.CLIPSIBLINGS;
return cp;
}
}
// ... more
}
How you can connect your WinForms user interactions with your VC++ OpenGL output depends on the way it works, can’t help you there w/o more infos.
This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.