C#表单上的OpenGL视图 [英] OpenGL view on C# Form

查看:177
本文介绍了C#表单上的OpenGL视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Windows窗体中显示一个过滤窗口?

How to display a glut window inside Windows Form?

glutCreateWindow(Example)创建另一个表单

glutCreateWindow("Example") create another form,

glutCreateSubWindow(hwnd,0,0, 100),其中hwnd在C#中处理我的主窗口窗体,我得到一个AccessViolation异常。

glutCreateSubWindow(hwnd, 0, 0, 100, 100), where hwnd is handle to my main Window Form in C#, i get an AccessViolation Exception.

Glut程序在一个C ++ DLL中。我的应用程序是在C#WPF。我需要在我的C#表单中显示glut视图

The Glut program is in a C++ DLL. My application is on C# WPF. I need to display glut view at my C# Form

C ++代码:

extern "C"
    {
        __declspec(dllexport) int InitGlut(int hwnd, int top, int left, int width, int height)
        {
            glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
            glutInitWindowPosition(top,left);
            glutInitWindowSize(320,320);
            //glutCreateWindow("Example");
            glutCreateSubWindow(hwnd, top, left, width, height);
            glutDisplayFunc(renderScene);
            glutMainLoop();
            return 0;
        }
    }

C#代码:

const string pathToDll = "../../../Release/MyDLL.dll";
[DllImport(pathToDll)]
public static extern int InitGlut(IntPtr hwnd, int top, int left, int width, int height);

private void Window_Loaded(object sender, RoutedEventArgs e)
{
     IntPtr hwnd = new WindowInteropHelper(Application.Current.MainWindow).Handle;
     InitGlut(hwnd, 0, 0, 100, 100);
}


推荐答案

看起来你正在托管一个WPF表单中的Win32对象。是的,这需要解决方法。

Looks like you're hosting a Win32 object in a WPF form. Yes, this requires workarounds.

您是否看过MSDN上的WPF和Win32互操作指南?

Have you seen the WPF and Win32 Interoperation guide on MSDN?

http://msdn.microsoft.com/en-us/library/ms742522.aspx

您还需要查看HwndHost类:

You'll need to check out the HwndHost class, too:

http://msdn.microsoft.com/en-us/library/system。 windows.interop.hwndhost.aspx

这篇关于C#表单上的OpenGL视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆