mcb_'s picture

Drawing directly in a windows Control without gamewindow or GLCONTROL.

I was trying to draw directly in a windows control( splitter panel) , When i add GLCONTROL it can draw to direcly windows panel.But when i remove glcontrol it again draw but with out filling pixels.

        private void splitContainer1_Panel2_Paint(object sender, PaintEventArgs e)
        {
            splitContainer1.Panel2.Invoke(new MethodInvoker(delegate { windowHandle = splitContainer1.Panel2.Handle; }));
            //windowHandle = splitContainer1.Panel2.Handle;
            IWindowInfo winfo = Utilities.CreateWindowsWindowInfo(windowHandle); // Similar methods exist for X11 and Carbon
            IGraphicsContext context = new GraphicsContext(GraphicsMode.Default, winfo);
 
            context.MakeCurrent(winfo);
 
 
 
 
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            GL.Ortho(-1.0, 1.0, -1.0, 1.0, 0.0, 4.0);
 
            GL.Begin(PrimitiveType.Triangles);
 
            GL.Color3(Color.MidnightBlue);
            GL.Vertex2(-1.0f, 1.0f);
            GL.Color3(Color.SpringGreen);
            GL.Vertex2(0.0f, -1.0f);
            GL.Color3(Color.Ivory);
            GL.Vertex2(1.0f, 1.0f);
 
            GL.End();
 
            context.SwapBuffers();
        }

How can i solve my problem? I dont want to use GLCONTROL or i dont want to see its black window,when i make its window visible=false , its does not draw anything again.


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mcb_'s picture

I solve my problem, i added LoadAll() after the makecurrent() Not its draws to where i want.

            splitContainer1.Panel2.Invoke(new MethodInvoker(delegate { windowHandle = splitContainer1.Panel2.Handle; }));
            IWindowInfo winfo = Utilities.CreateWindowsWindowInfo(windowHandle); // Similar methods exist for X11 and Carbon
            IGraphicsContext context = new GraphicsContext(GraphicsMode.Default, winfo);
            context.MakeCurrent(winfo);
 
            context.LoadAll();
 
 
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            GL.Ortho(-1.0, 1.0, -1.0, 1.0, 0.0, 4.0);
 
            GL.Begin(PrimitiveType.Triangles);
 
            GL.Color3(Color.MidnightBlue);
            GL.Vertex2(-1.0f, 1.0f);
            GL.Color3(Color.SpringGreen);
            GL.Vertex2(0.0f, -1.0f);
            GL.Color3(Color.Ivory);
            GL.Vertex2(1.0f, 1.0f);
 
            GL.End();
 
            context.SwapBuffers();
            context.Update(winfo);
the Fiddler's picture

GLControl shows up black in the designer because black is the default clear color for OpenGL.

You can change how it looks in the designer using the "BackColor" property in the designer properties, or in code:

glControl1.BackColor = SystemColors.Control; // use the default system color for controls

You can also change the OpenGL background color using:

GL.ClearColor(SystemColors.Control);

You can generally instantiate an OpenGL context on any WinForms control that inherits from System.Windows.Forms.Control, as long as you set its OwnerDraw property to true. If you try to use OpenGL on a control that performs its own GDI+ or GDI rendering, the results will be undefined. It may work on some systems but will flicker heavily on others.

For this reason, I'd recommend using the GLControl instead and changing its background color to match what you need.