Пример #1
0
        private void SetupGrahpicsResources(GraphicsDevice device)
        {
            this.vertexBuffer.Generate();

            this.layout = device.CreateVertexLayout();

            var attribute = new VertexAttribute();

            attribute.Index  = 0;
            attribute.Offset = 0;
            attribute.Stride = Marshal.SizeOf <Vertex>();
            attribute.Format = VertexAttributeFormat.Vector2f;
            attribute.Usage  = VertexAttributeUsage.Position;
            this.layout.SetAttribute(attribute);

            attribute.Index  = 1;
            attribute.Offset = Marshal.SizeOf <Vector2>();
            attribute.Stride = Marshal.SizeOf <Vertex>();
            attribute.Format = VertexAttributeFormat.Vector4f;
            attribute.Usage  = VertexAttributeUsage.Colour;
            this.layout.SetAttribute(attribute);

            var asm      = typeof(GLShapeRenderer).Assembly;
            var vertpath = $"{nameof(GLShapeRenderer)}.vert.glsl";
            var fragpath = $"{nameof(GLShapeRenderer)}.frag.glsl";

            this.program = (GLShader)device.CreateShader(ShaderFormat.GLSL, asm.GetManifestResourceStream(vertpath), asm.GetManifestResourceStream(fragpath));

            this.program.SetVertexData(this.vertexBuffer, this.layout);
        }
Пример #2
0
        private void SetupShaderProgram(GraphicsDevice device)
        {
            var asm      = typeof(GLSpriteRenderer).Assembly;
            var vertpath = $"{nameof(GLSpriteRenderer)}.vert.glsl";
            var fragpath = $"{nameof(GLSpriteRenderer)}.frag.glsl";

            this.program = (GLShader)device.CreateShader(ShaderFormat.GLSL, asm.GetManifestResourceStream(vertpath), asm.GetManifestResourceStream(fragpath));
        }
Пример #3
0
        private void SetupGrahpicsResources(GLGraphicsDevice device)
        {
            this.vertexBuffer.Generate();

            this.layout = device.CreateVertexLayout();

            var attribute = new VertexAttribute();

            attribute.Index  = 0;
            attribute.Offset = 0;
            attribute.Stride = Marshal.SizeOf <Vertex2>();
            attribute.Format = VertexAttributeFormat.Vector2f;
            attribute.Usage  = VertexAttributeUsage.Position;
            layout.SetAttribute(attribute);


            attribute.Index  = 1;
            attribute.Offset = Marshal.SizeOf <Vector2>();
            attribute.Stride = Marshal.SizeOf <Vertex2>();
            attribute.Format = VertexAttributeFormat.Vector2f;
            attribute.Usage  = VertexAttributeUsage.TextureCoordinate;
            layout.SetAttribute(attribute);

            attribute.Index  = 2;
            attribute.Offset = Marshal.SizeOf <Vector2>() * 2;
            attribute.Stride = Marshal.SizeOf <Vertex2>();
            attribute.Format = VertexAttributeFormat.Vector4f;
            attribute.Usage  = VertexAttributeUsage.Colour;
            layout.SetAttribute(attribute);

            var asm      = typeof(GLTextRenderer).Assembly;
            var vertpath = $"{nameof(GLTextRenderer)}.vert.glsl";
            var fragpath = $"{nameof(GLTextRenderer)}.frag.glsl";

            this.program = (GLShader)device.CreateShader(ShaderFormat.GLSL, asm.GetManifestResourceStream(vertpath), asm.GetManifestResourceStream(fragpath));

            this.program.SetVertexData(this.vertexBuffer, this.layout);

            this.fontTexture        = device.CreateTexture2D(new Vector2i(1024, 2048), PixelFormat.GrayScale);
            this.fontTexture.Filter = TextureFilter.Linear;
            this.program.SetUniform("Texture", this.fontTexture, 0);
        }