2011-01-18 11:40:49 +00:00
|
|
|
|
// This code was written for the OpenTK library and has been released
|
|
|
|
|
// to the Public Domain.
|
|
|
|
|
// It is provided "as is" without express or implied warranty of any kind.
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2009-08-14 13:13:28 +00:00
|
|
|
|
using OpenTK.Graphics.OpenGL;
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
|
|
namespace Examples.WinForms
|
|
|
|
|
{
|
2010-10-02 18:52:34 +00:00
|
|
|
|
[Example("GLControl Simple", ExampleCategory.OpenTK, "GLControl", 1, Documentation="GLControlSimple")]
|
2009-04-20 09:48:33 +00:00
|
|
|
|
public partial class SimpleForm : Form
|
2009-02-22 10:43:35 +00:00
|
|
|
|
{
|
2009-04-20 09:48:33 +00:00
|
|
|
|
public SimpleForm()
|
2009-02-22 10:43:35 +00:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Events
|
|
|
|
|
|
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnLoad(e);
|
|
|
|
|
|
|
|
|
|
glControl1_Resize(this, EventArgs.Empty); // Ensure the Viewport is set up correctly
|
|
|
|
|
GL.ClearColor(Color.Crimson);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void redButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
GL.ClearColor(Color.Crimson);
|
|
|
|
|
glControl1.Invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void greenButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
GL.ClearColor(Color.ForestGreen);
|
|
|
|
|
glControl1.Invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void blueButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
GL.ClearColor(Color.RoyalBlue);
|
|
|
|
|
glControl1.Invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void glControl1_Paint(object sender, PaintEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
glControl1.MakeCurrent();
|
|
|
|
|
|
|
|
|
|
GL.Clear(ClearBufferMask.ColorBufferBit);
|
|
|
|
|
glControl1.SwapBuffers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void glControl1_Resize(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (glControl1.ClientSize.Height == 0)
|
|
|
|
|
glControl1.ClientSize = new System.Drawing.Size(glControl1.ClientSize.Width, 1);
|
|
|
|
|
|
|
|
|
|
GL.Viewport(0, 0, glControl1.ClientSize.Width, glControl1.ClientSize.Height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void glControl1_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
switch (e.KeyData)
|
|
|
|
|
{
|
|
|
|
|
case Keys.Escape:
|
|
|
|
|
this.Close();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region public static void Main()
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Entry point of this example.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[STAThread]
|
|
|
|
|
public static void Main()
|
|
|
|
|
{
|
2009-04-20 09:48:33 +00:00
|
|
|
|
using (SimpleForm example = new SimpleForm())
|
2009-02-22 10:43:35 +00:00
|
|
|
|
{
|
|
|
|
|
Utilities.SetWindowTitle(example);
|
|
|
|
|
example.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|