basic opengl window in csharp

main.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenTK.Graphics.OpenGL;

namespace OpenGLExample
{
    class Program : GameWindow
    {
        static void Main(string[] args)
        {
            using (Program window = new Program())
            {
                window.Run(30);
            }
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            GL.ClearColor(0f, 0f, 0f, 1f);
        }

        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);

            GL.Viewport(0, 0, Width, Height);
        }

        protected override void OnRenderFrame(FrameEventArgs e)
        {
            base.OnRenderFrame(e);

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            // render code here

            SwapBuffers();
        }
    }
}
983 chars
47 lines

This code sets up an OpenTK window and clears the screen with a black color every frame. To render something, you would add code in the OnRenderFrame method. This is just a basic template to get you started with OpenGL in C#.

gistlibby LogSnag