
glControl Question
Posted Saturday, 22 March, 2008 - 04:37 by tuennes inHello, I am very excited about the glControl and its capabilities. I followed the tutorial but unfortunately my glControl still only shows junk, even though I cleaned the view port.
This is my program:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using OpenTK.OpenGL; using OpenTK.OpenGL.Enums; namespace WindowsApplication3 { public partial class Form1 : Form { bool loaded = false; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { loaded = true; GL.ClearColor(Color.SkyBlue); // Yey! .NET Colors can be used directly! SetupViewport(); } private void glControl1_Load(object sender, EventArgs e) { } private void glControl1_Resize(object sender, EventArgs e) { if (!loaded) return; } private void glControl1_Paint(object sender, PaintEventArgs e) { if (!loaded) // Play nice return; GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); GL.Color3(Color.Yellow); GL.Begin(BeginMode.Triangles); GL.Vertex2(10, 20); GL.Vertex2(100, 20); GL.Vertex2(100, 50); GL.End(); glControl1.SwapBuffers(); } private void SetupViewport() { int w = glControl1.Width; int h = glControl1.Height; GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); GL.Ortho(0, w, 0, h, -1, 1); // Bottom-left corner pixel has coordinate (0, 0) GL.Viewport(0, 0, w, h); // Use all of the glControl painting area } } }
Can someone give me an advice why I still only see junk ?
Thanks in advance
[moderator edit: code tags :)]


Comments
Re: glControl Question
Ok, it works.
I want to thank everybody for their help.
This is really awesome stuff.