Пример #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();

            hdc = g.GetHdc();

            PixelFormatDescriptor m_pfd = new PixelFormatDescriptor();

            m_pfd.Flags     = (uint)(WGL.PFD_FLAGS.DOUBLEBUFFER | WGL.PFD_FLAGS.DRAW_TO_WINDOW | WGL.PFD_FLAGS.SUPPORT_OPENGL | WGL.PFD_FLAGS.TYPE_RGBA);
            m_pfd.PixelType = 0;
            m_pfd.ColorBits = 24;
            m_pfd.DepthBits = 32;
            m_pfd.LayerType = 0;

            Int32 pf = m_wgl.ChoosePixelFormat(hdc, m_pfd);

            if (pf == 0)
            {
                throw new Exception("ChoosePixelFormat failed");
            }

            Int32 spf = m_wgl.SetPixelFormat(hdc, pf, m_pfd);

            if (spf != 1)
            {
                throw new Exception("SetPixelFormat failed");
            }

            IntPtr ctx = m_wgl.CreateContext(hdc);

            m_wgl.MakeCurrent(hdc, ctx);

            m_gl.MatrixMode(GL.GL_FLAGS.PROJECTION);
            m_gl.Frustum(-0.5F, 0.5F, -0.5F, 0.5F, 1.0F, 3.0F);

            m_gl.MatrixMode(GL.GL_FLAGS.MODELVIEW);
            m_gl.Translatef(0.0F, 0.0F, -2.0F);

            m_gl.Rotatef(30.0F, 1.0F, 0.0F, 0.0F);
            m_gl.Rotatef(30.0F, 0.0F, 1.0F, 0.0F);

            m_gl.Enable(GL.GL_FLAGS.DEPTH_TEST);
            m_gl.Enable(GL.GL_FLAGS.COLOR_MATERIAL);
            m_gl.Enable(GL.GL_FLAGS.LIGHTING);
            m_gl.Enable(GL.GL_FLAGS.LIGHT0);

            m_gl.ColorMaterial(GL.GL_FLAGS.FRONT_AND_BACK, GL.GL_FLAGS.AMBIENT_AND_DIFFUSE);

            this.Invalidate();
        }