OpenTK3完整例子1_显示绿色背景
代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Input;
using OpenTK.Graphics.OpenGL;
namespace WindowsFormsApp1
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main() {
using (Game game = new Game(600, 300, "Hello OpenTK!"))
{
game.Run(30.0);
}
}
}
class Game : GameWindow
{
public Game(int width, int height, string title) : base(width, height, GraphicsMode.Default, title)
{
}
protected override void OnUpdateFrame(FrameEventArgs e)
{
base.OnUpdateFrame(e);
KeyboardState input = Keyboard.GetState();
if (input.IsKeyDown(Key.Escape))
{
Exit();
}
}
protected override void OnLoad(EventArgs e)
{
GL.ClearColor(0.0f, 1.0f, 0.0f, 1.0f);
//Code goes here
base.OnLoad(e);
}
protected override void OnRenderFrame(FrameEventArgs e)
{
GL.Clear(ClearBufferMask.ColorBufferBit);
//Code goes here.
Context.SwapBuffers();
base.OnRenderFrame(e);
}
}
}
结果


浙公网安备 33010602011771号