C#面板中的OpenGL 4.0或WPF WinFormsHost(VS 2022)

3htmauhk  于 2022-11-04  发布在  C#
关注(0)|答案(1)|浏览(158)

我想把OpenGL放在C# Winform的面板中,或者我想把它放在WPF的WinFormsHost面板中,但是我总是得到一个错误。当我查看旧的示例时,它们不起作用,因为版本已经过时了。只要一个在面板中运行OpenGL主窗口的示例就足够了。我能在当前的OpenGL4.0中找到这样的示例吗?

rqqzpn5f

rqqzpn5f1#

错误:没有可用的设备或呈现上下文!enter image description here

namespace Yontem2
{
    public partial class Form1 : Form
    {

        private static int widthEkran = 300, heightEkran = 300;

        static int panel;

        public Form1()
        {
            InitializeComponent();

        }

        private void simpleOpenGlControl1_Paint(object sender, PaintEventArgs e)
        {
            // create an OpenGL window
            Glut.glutInit();
            Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH);
            Glut.glutInitWindowSize(Width, Height);

            Glut.glutInitWindowPosition(100, 100);
            //glutInitWindowSize(800, 800);

            Glut.glutCreateWindow("");
            //panel = Glut.glutCreateWindow("");
            //Glut.glutCreateSubWindow(panel, 10, 10, 300, 300);

            // provide the Glut callbacks that are necessary for running this tutorial
            Glut.glutIdleFunc(OnRenderFrame);
            Glut.glutDisplayFunc(OnDisplay);

            Glut.glutMainLoop();   

            simpleOpenGlControl1.Refresh();
        }

        public static void OnDisplay()
        {

        }

        public static void OnRenderFrame()
        {
            // set up the OpenGL viewport and clear both the color and depth bits
            Gl.Viewport(0, 0, widthEkran, heightEkran);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            Glut.glutSwapBuffers();
        }

    }
}

相关问题