using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Drawing; using Drawing3d; using System.Windows.Forms; namespace Example { public partial class Form1 : Form { Timer timer = new Timer(); OpenTK.GLControl Renderer = null; OpenGlDevice Device = null; public void Add() { Renderer = new OpenTK.GLControl(); Device = new Drawing3d.OpenGlDevice(Renderer); Device.Draw += Device_Draw; Device.ContextCreated += Device_ContextCreated; Renderer.SizeChanged += Renderer_SizeChanged; Renderer.Dock = System.Windows.Forms.DockStyle.Fill; Renderer.Parent = this; Renderer.Paint += Renderer_Paint; Renderer.MouseDown += Renderer_MouseDown; Renderer.MouseMove += Renderer_MouseMove; Renderer.MouseUp += Renderer_MouseUp; Renderer.MouseWheel += Renderer_MouseWheel; Renderer.KeyPress += Renderer_KeyPress; Renderer.KeyUp += Renderer_KeyUp; Renderer.KeyDown += Renderer_KeyDown; timer.Enabled = true; timer.Interval = 20; timer.Tick += Timer_Tick; } private void Renderer_Paint(object sender, PaintEventArgs e) { Device.Refresh(); } private void Renderer_KeyDown(object sender, KeyEventArgs e) { Device.OnKeyDown((Drawing3d.Keys)e.KeyCode); } private void Renderer_KeyUp(object sender, KeyEventArgs e) { Device.OnKeyUp((Drawing3d.Keys)e.KeyCode); } private void Renderer_KeyPress(object sender, KeyPressEventArgs e) { Device.OnKeyPress(e.KeyChar); } private void Device_ContextCreated(object sender, EventArgs e) { // wird aufgerufen, wenn ein gültiger Context creiert wurde } private void Timer_Tick(object sender, EventArgs e) { Device.Refresh(); } private void Device_Draw(object sender, EventArgs e) { Device.drawSphere(4); } private void Renderer_MouseWheel(object sender, MouseEventArgs e) { Device.OnMouseWheel(Drawing3d.MouseButtons.Left, e.Delta, e.X, e.Y, 0); } private void Renderer_MouseUp(object sender, MouseEventArgs e) { Device.OnMouseUp(Drawing3d.MouseButtons.Left, 1, e.X, e.Y, 0); } private void Renderer_MouseMove(object sender, MouseEventArgs e) { Device.OnMouseMove(Drawing3d.MouseButtons.Left, 1, e.X, e.Y, 0); } private void Renderer_MouseDown(object sender, MouseEventArgs e) { Device.OnMouseDown(Drawing3d.MouseButtons.Left, 1, e.X, e.Y, 0); } private void Renderer_SizeChanged(object sender, EventArgs e) { Device.SizeChanged(Renderer.Width, Renderer.Height); } } }