Ejemplo n.º 1
0
        public DX11IndexedGeometry QuadColor(Vector2 size)
        {
            DX11IndexedGeometry geom = new DX11IndexedGeometry(context);

            DataStream ds = new DataStream(4 * Pos4Col4Tex2Vertex.VertexSize, true, true);

            ds.Position = 0;

            float sx = 0.5f * size.X;
            float sy = 0.5f * size.Y;

            Pos4Col4Tex2Vertex v = new Pos4Col4Tex2Vertex();

            v.Position  = new Vector4(-sx, sy, 0.0f, 1.0f);
            v.Color     = new Vector4(1, 1, 1, 1);
            v.TexCoords = new Vector2(0, 0);
            ds.Write <Pos4Col4Tex2Vertex>(v);

            v.Position  = new Vector4(sx, sy, 0.0f, 1.0f);
            v.TexCoords = new Vector2(1, 0);
            ds.Write <Pos4Col4Tex2Vertex>(v);

            v.Position  = new Vector4(-sx, -sy, 0.0f, 1.0f);
            v.TexCoords = new Vector2(0, 1);
            ds.Write <Pos4Col4Tex2Vertex>(v);

            v.Position  = new Vector4(sx, -sy, 0.0f, 1.0f);
            v.TexCoords = new Vector2(1, 1);
            ds.Write <Pos4Col4Tex2Vertex>(v);

            var vertices = BufferHelper.CreateDynamicVertexBuffer(context, ds, true);

            var indexstream = new DataStream(24, true, true);

            indexstream.WriteRange(new int[] { 0, 1, 3, 3, 2, 0 });


            geom.VertexBuffer  = vertices;
            geom.IndexBuffer   = new DX11IndexBuffer(context, indexstream, false, true);
            geom.InputLayout   = Pos4Col4Tex2Vertex.Layout;
            geom.Topology      = PrimitiveTopology.TriangleList;
            geom.VerticesCount = 4;
            geom.VertexSize    = Pos4Col4Tex2Vertex.VertexSize;

            geom.HasBoundingBox = true;
            geom.BoundingBox    = new BoundingBox(new Vector3(-sx, -sy, 0.0f), new Vector3(sx, sy, 0.0f));

            return(geom);
        }
Ejemplo n.º 2
0
        public DX11IndexedGeometry QuadColor(Vector2 size)
        {
            DX11IndexedGeometry geom = new DX11IndexedGeometry(context);

            DataStream ds = new DataStream(4 * Pos4Col4Tex2Vertex.VertexSize, true, true);
            ds.Position = 0;

            float sx = 0.5f * size.X;
            float sy = 0.5f * size.Y;

            Pos4Col4Tex2Vertex v = new Pos4Col4Tex2Vertex();
            v.Position = new Vector4(-sx, sy, 0.0f, 1.0f);
            v.Color = new Vector4(1, 1, 1, 1);
            v.TexCoords = new Vector2(0, 0);
            ds.Write<Pos4Col4Tex2Vertex>(v);

            v.Position = new Vector4(sx, sy, 0.0f, 1.0f);
            v.TexCoords = new Vector2(1, 0);
            ds.Write<Pos4Col4Tex2Vertex>(v);

            v.Position = new Vector4(-sx, -sy, 0.0f, 1.0f);
            v.TexCoords = new Vector2(0, 1);
            ds.Write<Pos4Col4Tex2Vertex>(v);

            v.Position = new Vector4(sx, -sy, 0.0f, 1.0f);
            v.TexCoords = new Vector2(1, 1);
            ds.Write<Pos4Col4Tex2Vertex>(v);

            var vertices = BufferHelper.CreateDynamicVertexBuffer(context, ds, true);

            var indexstream = new DataStream(24, true, true);
            indexstream.WriteRange(new int[] { 0, 1, 3, 3, 2, 0 });

            geom.VertexBuffer = vertices;
            geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true);
            geom.InputLayout = Pos4Col4Tex2Vertex.Layout;
            geom.Topology = PrimitiveTopology.TriangleList;
            geom.VerticesCount = 4;
            geom.VertexSize = Pos4Col4Tex2Vertex.VertexSize;

            geom.HasBoundingBox = true;
            geom.BoundingBox = new BoundingBox(new Vector3(-sx, -sy, 0.0f), new Vector3(sx, sy, 0.0f));

            return geom;
        }