how to integrate the opengl window in windows form application

2.5k Views Asked by At

I am using OpenGL and TaoFramework in c# . I created a window for openGL excluding the windows form and I dont know how can I integrate this window in windows form.

  [STAThread]
        static void Main()
        {




            Glut.glutInit();
            Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_RGB | Glut.GLUT_DEPTH);
            Glut.glutGetWindow();
            Glut.glutInitWindowSize(600, 600);
            Glut.glutInitWindowPosition(700, 100);
            Glut.glutCreateWindow("Lang Yuzer Robot Arm");

            Gl.glEnable(Gl.GL_COLOR_MATERIAL);
            Gl.glEnable(Gl.GL_LIGHTING);
            Gl.glEnable(Gl.GL_LIGHT0);
            Gl.glEnable(Gl.GL_DEPTH_TEST);
            Gl.glEnable(Gl.GL_NORMALIZE);
            Gl.glEnable(Gl.GL_CULL_FACE);

            Glut.glutDisplayFunc(Form1.myDisplay);
            Glut.glutReshapeFunc(Form1.myReshape);
            Glut.glutIdleFunc(Form1.myIdle);


            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());

                  Glut.glutMainLoop();


    }
    }
2

There are 2 best solutions below

1
On

Without messing around with Window handles, I would suggest using OpenTK, which uses the Tao Framework. This library has an OpenGLControl which makes integrating OpenGL graphics into a windows form.

0
On

GLUT is a windowing toolkit; WinForms is a different windowing toolkit. Unless GLUT allows reparenting (unlikely), there is no straightforward way to combine the two.

The best solution would be to use OpenTK.GLControl, which is cross-platform and well maintained. NuGet version available here: https://www.nuget.org/packages/OpenTK.GLControl/

Another solution would be to use Tao.SimpleGlControl, which is windows-only and no longer maintained.