2007-07-23 00:15:18 +00:00
|
|
|
|
#region --- License ---
|
|
|
|
|
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
|
|
|
|
* See license.txt for license info
|
|
|
|
|
*/
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region --- Using directives ---
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
using OpenTK;
|
2008-04-13 16:45:56 +00:00
|
|
|
|
using OpenTK.Graphics;
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
namespace Examples.WinForms
|
|
|
|
|
{
|
2007-11-11 18:44:10 +00:00
|
|
|
|
[Example("Simple GLControl", ExampleCategory.WinForms, 1)]
|
|
|
|
|
public partial class W01_First_Window : Form
|
2007-07-23 00:15:18 +00:00
|
|
|
|
{
|
|
|
|
|
public W01_First_Window()
|
|
|
|
|
{
|
2008-02-28 13:57:48 +00:00
|
|
|
|
InitializeComponent();
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-11-11 18:44:10 +00:00
|
|
|
|
#region Events
|
|
|
|
|
|
2007-08-20 12:25:48 +00:00
|
|
|
|
protected override void OnLoad(EventArgs e)
|
2007-08-04 12:17:30 +00:00
|
|
|
|
{
|
2007-08-20 12:25:48 +00:00
|
|
|
|
base.OnLoad(e);
|
|
|
|
|
|
2007-11-11 19:39:09 +00:00
|
|
|
|
glControl1_Resize(this, EventArgs.Empty); // Ensure the Viewport is set up correctly
|
2007-09-02 08:08:12 +00:00
|
|
|
|
GL.ClearColor(Color.Crimson);
|
2007-08-04 12:17:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-07-23 00:15:18 +00:00
|
|
|
|
private void redButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2007-09-02 08:08:12 +00:00
|
|
|
|
GL.ClearColor(Color.Crimson);
|
2007-08-20 14:12:57 +00:00
|
|
|
|
glControl1.Invalidate();
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void greenButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2007-09-02 08:08:12 +00:00
|
|
|
|
GL.ClearColor(Color.ForestGreen);
|
2007-08-20 14:12:57 +00:00
|
|
|
|
glControl1.Invalidate();
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void blueButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2007-09-02 08:08:12 +00:00
|
|
|
|
GL.ClearColor(Color.RoyalBlue);
|
2007-08-20 14:12:57 +00:00
|
|
|
|
glControl1.Invalidate();
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void glControl1_Paint(object sender, PaintEventArgs e)
|
|
|
|
|
{
|
2008-11-26 21:49:05 +00:00
|
|
|
|
glControl1.MakeCurrent();
|
|
|
|
|
|
2007-11-04 15:32:24 +00:00
|
|
|
|
GL.Clear(ClearBufferMask.ColorBufferBit);
|
2007-08-20 14:12:57 +00:00
|
|
|
|
glControl1.SwapBuffers();
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-11-11 19:39:09 +00:00
|
|
|
|
private void glControl1_Resize(object sender, EventArgs e)
|
2007-07-23 00:15:18 +00:00
|
|
|
|
{
|
2007-08-20 14:12:57 +00:00
|
|
|
|
if (glControl1.ClientSize.Height == 0)
|
|
|
|
|
glControl1.ClientSize = new System.Drawing.Size(glControl1.ClientSize.Width, 1);
|
2007-07-23 00:15:18 +00:00
|
|
|
|
|
2007-08-20 14:12:57 +00:00
|
|
|
|
GL.Viewport(0, 0, glControl1.ClientSize.Width, glControl1.ClientSize.Height);
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void glControl1_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
switch (e.KeyData)
|
|
|
|
|
{
|
|
|
|
|
case Keys.Escape:
|
|
|
|
|
this.Close();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-08-04 12:09:58 +00:00
|
|
|
|
|
2007-11-11 18:44:10 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region public static void Main()
|
2007-08-04 12:09:58 +00:00
|
|
|
|
|
2007-11-11 18:44:10 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Entry point of this example.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[STAThread]
|
|
|
|
|
public static void Main()
|
2007-08-04 12:09:58 +00:00
|
|
|
|
{
|
2007-11-11 18:44:10 +00:00
|
|
|
|
using (W01_First_Window example = new W01_First_Window())
|
|
|
|
|
{
|
2008-01-22 14:54:00 +00:00
|
|
|
|
Utilities.SetWindowTitle(example);
|
2007-11-11 18:44:10 +00:00
|
|
|
|
example.ShowDialog();
|
|
|
|
|
}
|
2007-08-04 12:09:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
2007-08-10 09:27:13 +00:00
|
|
|
|
}
|