Ejemplo n.º 1
0
        public async Task RenderFrame()
        {
            await _context.ClearColorAsync(0, 0, 0, 1);

            await _context.ClearAsync(BufferBits.COLOR_BUFFER_BIT);


            Buffer.BlockCopy(spriteEngine.vertices, 0, byteArr, 0, byteArr.Length);
            await _context.BufferDataAsync(BufferType.ARRAY_BUFFER, byteArr, BufferUsageHint.DYNAMIC_DRAW);

            // this matrix will convert from pixels to clip space
            Matrix4x4 myMatrix = Matrix4x4.CreateOrthographic(_canvasReference.Width, _canvasReference.Height, 1, -1);

            // this matrix will translate our quad to dstX, dstY
            Matrix4x4 transMatrix = Matrix4x4.CreateTranslation(transVector);

            myMatrix = Matrix4x4.Multiply(myMatrix, transMatrix);

            // Set the matrix.
            await _context.UniformMatrixAsync(u_matrix_location, false, new float[16] {
                myMatrix.M11, myMatrix.M12, myMatrix.M13, myMatrix.M14, myMatrix.M21, myMatrix.M22, myMatrix.M23, myMatrix.M24, myMatrix.M31, myMatrix.M32, myMatrix.M33, myMatrix.M34, myMatrix.M41, myMatrix.M42, myMatrix.M43, myMatrix.M44
            });

            await _context.DrawArraysAsync(Primitive.TRIANGLES, 0, 6 *spriteEngine.spriteCount);


            spriteEngine.spriteCount = 0;
        }