OpenGL 4.0在c#面板或WPF WinFormsHost (VS 2022)



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

错误:没有可用的设备或渲染上下文!输入图片描述

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();
}


}
}

最新更新