예제 #1
0
        // Tutorial38::RenderSceneCB()
        protected override void OnRenderFrame(FrameEventArgs args)
        {
            RunningTime += args.Time;

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

            GL.UseProgram(ShaderProgram);

            // Camera MVP

            var model      = OpenToolkit.Mathematics.Matrix4.Identity;
            var view       = Camera.View;
            var projection = Camera.Projection;

            var wvp = model * view * projection;

            var wvpLocation = GL.GetUniformLocation(ShaderProgram, "gWVP");

            GL.UniformMatrix4(wvpLocation, false, ref wvp);

            // Mesh transforms

            var transforms = new List <OpenToolkit.Mathematics.Matrix4>();

            for (int i = 0; i < Mesh.NumBones; i++)
            {
                transforms.Add(new OpenToolkit.Mathematics.Matrix4());
            }

            Mesh.BoneTransforms((float)RunningTime / 1000f, ref transforms);

            for (int i = 0; i < transforms.Count; i++)
            {
                var m        = transforms[i];
                var location = GL.GetUniformLocation(ShaderProgram, $"gBones[{i}]");
                GL.UniformMatrix4(location, false, ref m);
            }

            Mesh.Render();

            SwapBuffers();

            base.OnRenderFrame(args);
        }