Beispiel #1
0
        //! On update window
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            this._period += 0.001; // TODO [...]

            (Matrix4 model_mat, bool update) = this._controls.Update();

            float angle  = 90.0f * (float)Math.PI / 180.0f;
            float aspect = (float)this.Size.X / (float)this.Size.Y;

            this._projection = Matrix4.CreatePerspectiveFieldOfView(angle, aspect, 0.1f, 100.0f);

            GL.Viewport(0, 0, this.Size.X, this.Size.Y);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            this._test_prog.Use();

            TMVP mvp = new TMVP(model_mat, this._view, this._projection);

            this._mvp_ssbo.Update(ref mvp);

            _test_vao.Draw(36);

            Context.SwapBuffers();
            base.OnUpdateFrame(e);
        }
Beispiel #2
0
        public void Draw(int cx, int cy, double app_t)
        {
            this._period = app_t;

            bool resized = this._cx != cx || this._cy != cy;

            if (resized)
            {
                this._cx = cx;
                this._cy = cy;
                GL.Viewport(0, 0, this._cx, this._cy);

                float angle  = 90.0f * (float)Math.PI / 180.0f;
                float aspect = (float)this._cx / (float)this._cy;
                this._projection = Matrix4.CreatePerspectiveFieldOfView(angle, aspect, 0.1f, 100.0f);
            }

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

            this._test_prog.Use();

            TMVP mvp = new TMVP(Matrix4.Identity, this._view, this._projection);

            this._mvp_ssbo.Update(ref mvp);

            _test_vao.Draw(36);
        }
Beispiel #3
0
        //! On update window
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            GL.Viewport(0, 0, this.Size.X, this.Size.Y);
            GL.Clear(ClearBufferMask.ColorBufferBit);

            int transformLocation = GL.GetUniformLocation(this._test_prog.Object, "u_transform");

            double diagonal   = Math.Sqrt(this.Size.X * this.Size.X + this.Size.Y * this.Size.Y);
            double dia_angle1 = Math.Atan2(this.Size.Y, this.Size.X) + angle * Math.PI / 180;
            double dia_angle2 = Math.Atan2(this.Size.Y, -this.Size.X) + angle * Math.PI / 180;
            double rot_w      = Math.Max(Math.Abs(diagonal * Math.Cos(dia_angle1)), Math.Abs(diagonal * Math.Cos(dia_angle2)));
            double rot_h      = Math.Max(Math.Abs(diagonal * Math.Sin(dia_angle1)), Math.Abs(diagonal * Math.Sin(dia_angle2)));
            double scale      = Math.Min(this.Size.X / rot_w, this.Size.Y / rot_h);

            Matrix4 transformMatrix =
                Matrix4.CreateScale((float)scale) *
                Matrix4.CreateScale(this.Size.X, this.Size.Y, 1.0f) *
                Matrix4.CreateRotationZ((float)(angle * Math.PI / 180)) *
                Matrix4.CreateScale(1.0f / this.Size.X, 1.0f / this.Size.Y, 1.0f);

            angle += 1;

            GL.UniformMatrix4(transformLocation, false, ref transformMatrix);

            _test_vao.Draw();

            Context.SwapBuffers();
            base.OnUpdateFrame(e);
        }
 /// <summary>
 /// Installs a given program as part of the current rendering state, then draws this array object.
 /// </summary>
 /// <typeparam name="TAttr1">The type of the 1st attribute buffer object of the VAO.</typeparam>
 /// <param name="vao">The VAO to use.</param>
 /// <param name="program">The program to use.</param>
 /// <param name="count">The number of vertices to draw, or -1 to draw all vertices.</param>
 public static void Draw <TAttr1>(
     this IVertexArrayObject <TAttr1> vao,
     GlProgram program,
     int count = -1)
     where TAttr1 : struct
 {
     program.Use();
     vao.Draw(count);
 }
        /// <inheritdoc />
        public void Draw(int count)
        {
            GL.Finish();

            indexBuffer.FlushChanges();
            this.attributeBuffer1.FlushChanges();

            vertexArrayObject.Draw(count);
        }
 /// <summary>
 /// Installs a given program as part of the current rendering state, then draws this array object.
 /// </summary>
 /// <typeparam name="TAttr1">The type of the 1st attribute buffer object of the VAO.</typeparam>
 /// <typeparam name="TDefaultUniformBlock">The type of the container used for default block uniforms for the given program.</typeparam>
 /// <param name="vao">The VAO to use.</param>
 /// <param name="program">The program to use.</param>
 /// <param name="defaultUniformBlock">The values for the uniforms in the default block.</param>
 /// <param name="count">The number of vertices to draw, or -1 to draw all vertices.</param>
 public static void Draw <TAttr1, TDefaultUniformBlock>(
     this IVertexArrayObject <TAttr1> vao,
     GlProgramWithDUB <TDefaultUniformBlock> program,
     TDefaultUniformBlock defaultUniformBlock,
     int count = -1)
     where TAttr1 : struct
     where TDefaultUniformBlock : struct
 {
     program.UseWithDefaultUniformBlock(defaultUniformBlock);
     vao.Draw(count);
 }
 /// <summary>
 /// Installs a given program as part of the current rendering state, then draws this array object.
 /// </summary>
 /// <typeparam name="TAttr1">The type of the 1st attribute buffer object of the VAO.</typeparam>
 /// <typeparam name="TAttr2">The type of the 2nd attribute buffer object of the VAO.</typeparam>
 /// <typeparam name="TUbo1">The type of the 1st uniform buffer object of the program.</typeparam>
 /// <param name="vao">The VAO to use.</param>
 /// <param name="program">The program to use.</param>
 /// <param name="count">The number of vertices to draw, or -1 to draw all vertices.</param>
 public static void Draw <TAttr1, TAttr2, TUbo1>(
     this IVertexArrayObject <TAttr1, TAttr2> vao,
     GlProgram <TUbo1> program,
     int count = -1)
     where TAttr1 : struct
     where TAttr2 : struct
     where TUbo1 : struct
 {
     program.Use();
     vao.Draw(count);
 }
Beispiel #8
0
        //! On update window
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            GL.Viewport(0, 0, this.Size.X, this.Size.Y);
            GL.Clear(ClearBufferMask.ColorBufferBit);

            _test_texture.Bind(7);
            _test_vao.Draw();

            Context.SwapBuffers();
            base.OnUpdateFrame(e);
        }
Beispiel #9
0
        public void Draw(int cx, int cy, double app_t)
        {
            double delta_t = app_t - this._period;

            this._period = app_t;

            bool resized = this._cx != cx || this._cy != cy;

            if (resized)
            {
                this._cx = cx;
                this._cy = cy;
                GL.Viewport(0, 0, this._cx, this._cy);

                float angle  = 90.0f * (float)Math.PI / 180.0f;
                float aspect = (float)this._cx / (float)this._cy;
                this._projection = Matrix4.CreatePerspectiveFieldOfView(angle, aspect, 0.1f, 100.0f);
            }

            Vector3 move_vec = new Vector3(0, 0, 0);

            if (System.Windows.Input.Keyboard.IsKeyDown(System.Windows.Input.Key.Up))
            {
                move_vec.Y += 1.0f;
            }
            if (System.Windows.Input.Keyboard.IsKeyDown(System.Windows.Input.Key.Down))
            {
                move_vec.Y -= 1.0f;
            }
            if (System.Windows.Input.Keyboard.IsKeyDown(System.Windows.Input.Key.Right))
            {
                move_vec.X += 1.0f;
            }
            if (System.Windows.Input.Keyboard.IsKeyDown(System.Windows.Input.Key.Left))
            {
                move_vec.X -= 1.0f;
            }
            move_vec *= (float)delta_t;

            this._controls.Move(move_vec);

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

            this._test_prog.Use();

            TMVP mvp = new TMVP(Matrix4.Identity, this._view, this._projection);

            this._mvp_ssbo.Update(ref mvp);

            _test_vao.Draw(36);
        }
Beispiel #10
0
        public void Draw(int cx, int cy, double app_t)
        {
            this._period = app_t;

            bool resized = this._cx != cx || this._cy != cy;

            if (resized)
            {
                this._cx = cx;
                this._cy = cy;
                GL.Viewport(0, 0, this._cx, this._cy);

                float angle  = 90.0f * (float)Math.PI / 180.0f;
                float aspect = (float)this._cx / (float)this._cy;
                this._projection = Matrix4.CreatePerspectiveFieldOfView(angle, aspect, 0.1f, 100.0f);
            }

            this._spin.Update();
            Matrix4 model_mat = this._spin.autoModelMatrix * this._spin.orbit; // OpenTK `*`-operator is reversed

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

            this._parallax_prog.Use();

            this._tbos[0].Bind(1);
            this._tbos[2].Bind(2);

            float clip_scale    = (float)ViewModel.ClipScale / 100.0f;
            float height_scale  = (float)ViewModel.HeightScale / 500.0f;
            float quality_scale = (float)ViewModel.QualityScale / 100.0f;

            GL.Uniform4(1, -2.0f, -1.0f, -2.0f, clip_scale * 1.7321f);
            GL.Uniform1(2, height_scale);
            GL.Uniform2(3, quality_scale, (float)1.0);

            TMVP mvp = new TMVP(model_mat, this._view, this._projection);

            this._mvp_ssbo.Update(ref mvp);

            _cube_vao.Draw(36);
        }
Beispiel #11
0
        //! On update window
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            int    original_w      = 100;
            int    original_h      = 100;
            int    current_w       = this.Size.X;
            int    current_h       = this.Size.Y;
            double current_aspect  = (double)current_w / current_h;
            double original_aspect = (double)original_w / original_h;

            GL.Disable(EnableCap.ScissorTest);
            GL.Viewport(0, 0, current_w, current_h);
            GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            GL.Clear(ClearBufferMask.ColorBufferBit);

            GL.Enable(EnableCap.ScissorTest);
            if (current_aspect > original_aspect)
            {
                int w = (int)(current_w * original_aspect / current_aspect);
                int x = (current_w - w) / 2;
                GL.Scissor(x, 0, w, this.Size.Y);
                GL.Viewport(x, 0, w, this.Size.Y);
            }
            else
            {
                int h = (int)(current_h * current_aspect / original_aspect);
                int y = (current_h - h) / 2;
                GL.Scissor(0, y, this.Size.X, h);
                GL.Viewport(0, y, this.Size.X, h);
            }

            GL.ClearColor(0.2f, 0.3f, 0.3f, 1.0f);
            GL.Clear(ClearBufferMask.ColorBufferBit);

            _test_vao.Draw();

            Context.SwapBuffers();
            base.OnUpdateFrame(e);
        }