Open TK difference on RenderFrame and onUpdateFrame?

I am currently programming Jump n 'Run in C # using the OpenTK Framework and OpenGL.

Open TK provides predefined features such as GameWindow.Run();orGameWindow.onUpdateFrame(); onRenderFrame();

As I understand it, all actions that draw OpenGL elements or primitives should be included in the onRenderFrame, while game events, such as moving players, should be executed in onUpdateFrame, so these actions can be calculated in advance before creating a new frame.

I'm right? Was it important to complete all the actions in the onRenderFrame method? OpenTK offers not to cancel these methods and subscribe to their events (onRenderFrameEvent).

http://www.opentk.com/files/doc/class_open_t_k_1_1_game_window.html#abc3e3a8c21a36d226c9d899f094152a4]

What is a subscription and how can 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();
}
+4
source share
1 answer

This is pretty much as the comments say: refresh your world in the event UpdateFrameand take it to RenderFrame.

, , . 15 . 60fps. 120 , 120 , .

, .

- UpdateFrame GameWindow.Run():

using (var game = new GameWindow())
{
     game.VSync = VSyncMode.Adaptive;
     game.Run(60.0, 0.0);
}

OpenTK 60 UpdateFrame RenderFrame , , . OpenTK RenderFrame, 60 UpdateFrame . " ".

. , .

. Quake 3, RenderFrame ( : Quake 3, fps .)

: . #. :

using (var game = new GameWindow())
{
    game.RenderFrame += (sender, e) =>
    {
        GL.Clear(ClearBufferMask.ColorBufferBit);
        game.SwapBuffers();
    };
}

GameWindow.RenderFrame GameWindow OnRenderFrame. , .

+5

Source: https://habr.com/ru/post/1539760/


All Articles