Exemplo n.º 1
0
        protected override void OnLoad()
        {
            GL.ClearColor(1f, 1f, 1f, 1.0f);

            VertexBufferObject = GL.GenBuffer();
            GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferObject);
            GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, BufferUsageHint.StaticDraw);

            VertexArrayObject = GL.GenVertexArray();
            GL.BindVertexArray(VertexArrayObject);
            GL.BindBuffer(BufferTarget.ArrayBuffer, VertexArrayObject);
            GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, BufferUsageHint.StaticDraw);

            ElementBufferObject = GL.GenBuffer();
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, ElementBufferObject);
            GL.BufferData(BufferTarget.ElementArrayBuffer, indices.Length * sizeof(uint), indices, BufferUsageHint.StaticDraw);

            GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 3 * sizeof(float), 0);
            GL.EnableVertexAttribArray(0);

            Shader = new Shader(
                Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"shaders\shader.vert.glsl")),
                Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"shaders\shader.frag.glsl")));

            Shader.Use();

            _timer = new Stopwatch();
            _timer.Start();

            base.OnLoad();
        }
Exemplo n.º 2
0
        private static int createVAO()
        {
            int vaoID = GL.GenVertexArray();

            VAOs.Add(vaoID);
            GL.BindVertexArray(vaoID);

            return(vaoID);
        }
Exemplo n.º 3
0
        protected override void OnUnload()
        {
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
            GL.BindVertexArray(0);
            GL.UseProgram(0);

            // Delete all the resources.
            GL.DeleteBuffer(VertexBufferObject);
            GL.DeleteVertexArray(VertexArrayObject);

            GL.DeleteProgram(Shader.Handle);
            base.OnUnload();
        }
Exemplo n.º 4
0
        protected override void OnRenderFrame(FrameEventArgs args)
        {
            GL.Clear(ClearBufferMask.ColorBufferBit);
            Shader.Use();

            #region Coloring

            var timeValue = _timer.Elapsed.TotalSeconds;
            GetColor(ref _greenValue, ref _redValue, ref _blueValue, ref timeValue);

            var vertexColorLocation = GL.GetUniformLocation(Shader.Handle, "ourColor");
            GL.Uniform4(vertexColorLocation, _redValue, _greenValue, _blueValue, 1.0f);

            #endregion

            GL.BindVertexArray(VertexArrayObject);
            GL.DrawArrays(PrimitiveType.Triangles, 0, 3);

            SwapBuffers();
            base.OnRenderFrame(args);
        }
Exemplo n.º 5
0
 public void Use()
 {
     GL.BindVertexArray(vertexArrayObject);
 }
Exemplo n.º 6
0
 private static void unbindVAO()
 {
     GL.BindVertexArray(0);
 }