예제 #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);
        }
예제 #2
0
        private static void drawScene()
        {
            gl.Viewport(0, 0, viewportWidth, viewportHeight);
            gl.Clear(gl.ColorBufferBit | gl.DepthBufferBit);
            pMatrix = Matrix4.Perspective(45, viewportWidth / viewportHeight, 0.1, 100.0);

            // Draw triangle
            mvMatrix = Matrix4.Translate(-1.5, 0.0, -7.0);
            gl.BindBuffer(gl.ArrayBuffer, triangleVertexPositionBuffer.Buffer);
            gl.VertexAttributePointer(vertexPositionAttribute, triangleVertexPositionBuffer.ItemSize, gl.Float, false, 0, 0);
            setMatrixUniforms();
            gl.DrawArrays(gl.Triangles, 0, triangleVertexPositionBuffer.NumItems);

            // Draw square
            mvMatrix = Matrix4.Translate(1.5, 0.0, -7.0);
            gl.BindBuffer(gl.ArrayBuffer, squareVertexPositionBuffer.Buffer);
            gl.VertexAttributePointer(vertexPositionAttribute, squareVertexPositionBuffer.ItemSize, gl.Float, false, 0, 0);
            setMatrixUniforms();
            gl.DrawArrays(gl.TriangleStrip, 0, squareVertexPositionBuffer.NumItems);
        }
예제 #3
0
 public void Bind()
 {
     context.BindBuffer(this);
 }