OpenTKでそれを行う適切な方法は、GameWindow
クラスから継承してから、とをオーバーライドすることだOnUpdateFrame
と思いますOnRenderFrame
。トランクをチェックアウトし、ファイルをチェックするときに含まれるクイックスタートソリューションがありGame.cs
ます。
[編集]さらに明確にするために、OpenTK.GameWindow
クラスは( OpenTK.Input.KeyboardDeviceKeyboard
タイプの)プロパティを提供します。これは内部で読み取る必要があります。キーボードイベントは基本クラスによってすでに処理されているため、個別に処理する必要はありません。OnUpdateFrame
/// <summary>
/// Called when it is time to setup the next frame. Add you game logic here.
/// </summary>
protected override void OnUpdateFrame(FrameEventArgs e)
{
base.OnUpdateFrame(e);
TimeSlice();
// handle keyboard here
if (Keyboard[Key.Escape])
{
// escape key was pressed
Exit();
}
}
また、より複雑な例については、Webページからさらに別のスターターキットをダウンロードしてください。クラスは次のようになります。
// Note: Taken from http://www.opentk.com
// Yet Another Starter Kit by Hortus Longus
// (http://www.opentk.com/project/Yask)
partial class Game : GameWindow
{
/// <summary>Init stuff.</summary>
public Game()
: base(800, 600, OpenTK.Graphics.GraphicsMode.Default, "My Game")
{ VSync = VSyncMode.On; }
/// <summary>Load resources here.</summary>
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
// load stuff
}
/// <summary>Called when your window is resized.
/// Set your viewport/projection matrix here.
/// </summary>
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
// do resize stuff
}
/// <summary>
/// Called when it is time to setup the next frame. Add you game logic here.
/// </summary>
protected override void OnUpdateFrame(FrameEventArgs e)
{
base.OnUpdateFrame(e);
TimeSlice();
// handle keyboard here
}
/// <summary>
/// Called when it is time to render the next frame. Add your rendering code here.
/// </summary>
protected override void OnRenderFrame(FrameEventArgs e)
{
base.OnRenderFrame(e);
// do your rendering here
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
using (Game game = new Game())
{
game.Run(30.0);
}
}
}
Yaskをダウンロードして、そこでどのように実装されているかを確認することをお勧めします。