I am currently programming a Jump n' Run game in C# using OpenTK Framework and OpenGL.
Open TK provides preset functions like GameWindow.Run();
or GameWindow.onUpdateFrame();
onRenderFrame();
As far as i thought through it, all actions that draw OpenGL elements or primitives should belong into onRenderFrame, whereas game events like player movement should be performed in onUpdateFrame, so these actions can be calculated in advance before rendering a new frame.
Am I right? Would it make a difference to perform all actions in the onRenderFrame method? OpenTK suggests not to override these methods and subscribing to their Events (onRenderFrameEvent) instead.
What is subscribing and how would i subscribe to an event instead of overriding a method?
protected override void OnUpdateFrame(FrameEventArgs e)
{
base.OnUpdateFrame(e);
this.gameObjects.moveObjects();
this.player.Move();
if (this.player.jumpstate == true) this.player.Jump();
}
protected override void OnRenderFrame(FrameEventArgs e)
{
base.OnRenderFrame(e);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
Matrix4 modelview = Matrix4.LookAt(Vector3.Zero, Vector3.UnitZ, Vector3.UnitY);
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadMatrix(ref modelview);
GL.LoadIdentity();
GL.Translate(0.0f, 0.0f, -3.5f);
this.gameObjects.drawObjects();
this.player.Draw();
SwapBuffers();
}