Ejemplo n.º 1
0
        protected override void OnAfterRender()
        {
            WebGLContext context = this.canvasReference.CreateWebGL(new WebGLContextAttributes
            {
                PowerPreference = WebGLContextAttributes.POWER_PREFERENCE_HIGH_PERFORMANCE
            });

            context.ClearColor(0, 0, 0, 1);
            context.Clear(BufferBits.COLOR_BUFFER_BIT);

            var program = this.InitProgram(context, VS_SOURCE, FS_SOURCE);

            var vertexBuffer = context.CreateBuffer();

            context.BindBuffer(BufferType.ARRAY_BUFFER, vertexBuffer);

            var vertices = new[]
            {
                -0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f,
                0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f,
                0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f
            };

            context.BufferData(BufferType.ARRAY_BUFFER, vertices, BufferUsageHint.STATIC_DRAW);

            context.VertexAttribPointer(0, 3, DataType.FLOAT, false, 6 * sizeof(float), 0);
            context.VertexAttribPointer(1, 3, DataType.FLOAT, false, 6 * sizeof(float), 3 * sizeof(float));
            context.EnableVertexAttribArray(0);
            context.EnableVertexAttribArray(1);

            context.UseProgram(program);

            context.DrawArrays(Primitive.TRIANGLES, 0, 3);
        }
Ejemplo n.º 2
0
        public static void Main()
        {
            var target = Element.GetById("target");
            var canvas = new Canvas();

            target.AppendChild(canvas);

            initGL(canvas);
            initShaders();
            initBuffers();

            gl.ClearColor(0.0, 0.0, 0.0, 1.0);
            gl.Enable(gl.DepthTest);

            drawScene();
        }