using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Tao.OpenGl; namespace UI.Winforms { public partial class WorldWindow : Form { public WorldWindow() { InitializeComponent(); OpenGLContext.Visible = true; OpenGLContext.Dock = DockStyle.Fill; } private void WorldWindow_Load(object sender, EventArgs e) { } private void WorldWindow_FormClosing(object sender, FormClosingEventArgs e) { //We don't want the user closing down this form by clicking the X button if (e.CloseReason == CloseReason.UserClosing) { //Ideally, we'd call the main menu and "click" the World button //in the Window menu to hide the form e.Cancel = true; } } private void OpenGLContext_Load(object sender, EventArgs e) { WorldWindow_Resize(); } private void OpenGLContext_Paint(object sender, PaintEventArgs e) { OpenGLPaint(); } private void WorldWindow_VisibleChanged(object sender, EventArgs e) { if (Visible) { OpenGLContext.InitializeContexts(); WorldWindow_Resize(); } } private void FramesPerSecondTimer_Tick(object sender, EventArgs e) { //Ideally we need something to dynamically cap the //drawing FPS to the Engine's FPS unless the user is //moving around the world, changing their view OpenGLPaint(); } private void OpenGLPaint() { Gl.glClear(Gl.GL_COLOR_BUFFER_BIT); Gl.glLoadIdentity(); Gl.glBegin(Gl.GL_TRIANGLES); Gl.glVertex2f(0, 0); Gl.glVertex2f(.5f, 1); Gl.glVertex2f(1, 0); Gl.glEnd(); } private void OpenGLResize(int Width, int Height) { float AspectRatio = (float)Width / (float)Height; Gl.glViewport(0, 0, Width, Height); Gl.glMatrixMode(Gl.GL_PROJECTION); Gl.glLoadIdentity(); Gl.glOrtho(0, AspectRatio, 0, 1, 10, -10); Gl.glMatrixMode(Gl.GL_MODELVIEW); } private void WorldWindow_Resize(object sender, EventArgs e) { WorldWindow_Resize(); } private void WorldWindow_Resize() { int Width = System.Math.Max(1, OpenGLContext.Size.Width); int Height = System.Math.Max(1, OpenGLContext.Size.Height); OpenGLResize(Width, Height); } private void WorldWindow_Shown(object sender, EventArgs e) { WorldWindow_Resize(); } } }