luca-piccioni / OpenGL.Net

Modern OpenGL bindings for C#.
MIT License
574 stars 109 forks source link

How to ask Control to draw triangle when I click a button on winform? #150

Closed linstudionet closed 4 years ago

linstudionet commented 4 years ago

Hi, I am looking at your code provided here: https://github.com/luca-piccioni/OpenGL.Net/wiki/GL-%5C-OpenGL.GlControl-(System.Windows.Forms)

private void RenderControl_ContextCreated(object sender, GlControlEventArgs e)
{
    // Here you can allocate resources or initialize state
    Gl.MatrixMode(MatrixMode.Projection);
    Gl.LoadIdentity();
    Gl.Ortho(0.0, 1.0f, 0.0, 1.0, 0.0, 1.0);

    Gl.MatrixMode(MatrixMode.Modelview);
    Gl.LoadIdentity();
}

private void RenderControl_Render(object sender, GlControlEventArgs e)
{
    Control senderControl = (Control)sender;

    Gl.Viewport(0, 0, senderControl.ClientSize.Width, senderControl.ClientSize.Height);
    Gl.Clear(ClearBufferMask.ColorBufferBit);

    Gl.Begin(PrimitiveType.Triangles);
    Gl.Color3(1.0f, 0.0f, 0.0f); Gl.Vertex2(0.0f, 0.0f);
    Gl.Color3(0.0f, 1.0f, 0.0f); Gl.Vertex2(0.5f, 1.0f);
    Gl.Color3(0.0f, 0.0f, 1.0f); Gl.Vertex2(1.0f, 0.0f);
    Gl.End();
}

private void RenderControl_ContextDestroying(object sender, GlControlEventArgs e)
{
    // Here you can dispose resources allocated in RenderControl_ContextCreated
}

From what I see, these are event functions raised by GLControlEventArgs. But what if I want to make a button when I click it, OpenGL will draw a triangle on winform.

The method should look like this:

        private void RadioButton_Checked(object sender, RoutedEventArgs e)
        {

        }
linstudionet commented 4 years ago

No longer needed