protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            glControl1_Resize(this, EventArgs.Empty);   // Ensure the Viewport is set up correctly
            GLHelper.ClearColor(PixelFarm.Drawing.Color.LightGray);
        }
        public override void Load()
        {
            //draw 1
            FormTestWinGLControl form = new FormTestWinGLControl();
            var canvas = PixelFarm.Drawing.DrawingGL.CanvasGLPortal.P.CreateCanvas(0, 0, 800, 600);

            form.SetGLPaintHandler((o, s) =>
            {
                //-----------------------------
                //see:  lazyfoo.net/tutorials/OpenGL/26_the_stencil_buffer/index.php
                //-----------------------------
                //test gradient brush
                //set value for clear color
                GLHelper.ClearColor(PixelFarm.Drawing.Color.White);
                GL.ClearStencil(0); //set value for clearing stencil buffer
                //actual clear here
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.StencilBufferBit);
                //-------------------
                //disable rendering to color buffer
                GL.ColorMask(false, false, false, false);
                //start using stencil
                GL.Enable(EnableCap.StencilTest);
                //place a 1 where rendered
                GL.StencilFunc(StencilFunction.Always, 1, 1);
                //replace where rendered
                GL.StencilOp(StencilOp.Replace, StencilOp.Replace, StencilOp.Replace);
                //render  to stencill buffer
                GL.Begin(BeginMode.Triangles);
                {
                    GL.Vertex2(20, 20);
                    GL.Vertex2(100, 20);
                    GL.Vertex2(60, 80);
                }
                GL.End();
                //-----------------
                //render color
                GL.ColorMask(true, true, true, true);
                //where a 1 was not rendered
                GL.StencilFunc(StencilFunction.Equal, 1, 1);
                //keep the pixel
                GL.StencilOp(StencilOp.Keep, StencilOp.Keep, StencilOp.Keep);
                //draw
                GL.Begin(BeginMode.Quads);
                {
                    GL.Color3(1f, 0, 0);
                    GL.Vertex2(5, 5);
                    GL.Color3(1f, 1, 0);
                    GL.Vertex2(100, 5);
                    GL.Color3(1f, 0, 1);
                    GL.Vertex2(100, 100);
                    GL.Color3(1f, 1, 1);
                    GL.Vertex2(5, 100);
                }
                GL.End();
                GL.Disable(EnableCap.StencilTest);
            });
            form.Show();
        }
        /// <summary>
        /// Setup OpenGL and load resources here.
        /// </summary>
        /// <param name="e">Not used.</param>
        protected override void OnLoad(EventArgs e)
        {
            GLHelper.ClearColor(PixelFarm.Drawing.Color.White);
            //GL.Enable(EnableCap.PolygonSmooth);
            //GL.Enable(EnableCap.Blend);
            //GL.BlendFunc(BlendingFactorSrc.SrcAlphaSaturate, BlendingFactorDest.One);
            //GL.Hint(HintTarget.PolygonSmoothHint, HintMode.DontCare);

            //glCullFace(GL_BACK);
            //GL.BlendFunc(BlendingFactorSrc.SrcAlphaSaturate, BlendingFactorDest.One);
            //glEnable(GL_CULL_FACE);
            //glBlendFunc(GL_SRC_ALPHA_SATURATE, GL_ONE);
            //glClearColor(0.0, 0.0, 0.0, 0.0);

            //glEnable(GL_LINE_SMOOTH);
            //glEnable(GL_BLEND);
            //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
            //glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
        }
 private void greenButton_Click(object sender, EventArgs e)
 {
     GLHelper.ClearColor(PixelFarm.Drawing.Color.Green);
     glControl1.Invalidate();
 }
 protected void GLClearColor(System.Drawing.Color c)
 {
     GLHelper.ClearColor(PixelFarm.Drawing.Conv.ToColor(c));
 }