예제 #1
0
파일: Quad.cs 프로젝트: rtshadow/miscs
        public static void Create()
        {
            //without texcoord
            DataStream stream = new DataStream(12 * 6, true, true);
            stream.Write<Vector3>(new Vector3(-1, -1, 1));
            stream.Write<Vector3>(new Vector3(-1, 1, 1));
            stream.Write<Vector3>(new Vector3(1, 1, 1));
            stream.Write<Vector3>(new Vector3(1, 1, 1));
            stream.Write<Vector3>(new Vector3(1, -1, 1));
            stream.Write<Vector3>(new Vector3(-1, -1, 1));
            elements[0] = new SlimDX.Direct3D10.InputElement("POSITION", 0, SlimDX.DXGI.Format.R32G32B32_Float, 0, 0);
            stream.Position = 0;
            buffer = new SlimDX.Direct3D10.Buffer(Game.gameClass.GetDevice(), stream, (int)stream.Length, D3D10.ResourceUsage.Immutable,
                D3D10.BindFlags.VertexBuffer, D3D10.CpuAccessFlags.None, D3D10.ResourceOptionFlags.None);
            binding = new SlimDX.Direct3D10.VertexBufferBinding(buffer, 12, 0);
            stream.Close();

            //with texcoord
            stream = new DataStream(12 * 6*2, true, true);
            stream.Write<Vector3>(new Vector3(-1, -1, 1));
            stream.Write<Vector3>(Vector3.Zero);
            stream.Write<Vector3>(new Vector3(-1, 1, 1));
            stream.Write<Vector3>(Vector3.Zero);
            stream.Write<Vector3>(new Vector3(1, 1, 1));
            stream.Write<Vector3>(Vector3.Zero);
            stream.Write<Vector3>(new Vector3(1, 1, 1));
            stream.Write<Vector3>(Vector3.Zero);
            stream.Write<Vector3>(new Vector3(1, -1, 1));
            stream.Write<Vector3>(Vector3.Zero);
            stream.Write<Vector3>(new Vector3(-1, -1, 1));
            stream.Write<Vector3>(Vector3.Zero);

            elementsWithTexCoord[0] = new SlimDX.Direct3D10.InputElement("POSITION", 0, SlimDX.DXGI.Format.R32G32B32_Float, 0, 0);
            elementsWithTexCoord[1] = new SlimDX.Direct3D10.InputElement("TEXCOORD", 0, SlimDX.DXGI.Format.R32G32B32_Float, 12, 0);
            stream.Position = 0;
            bufferWithTexCoord = new SlimDX.Direct3D10.Buffer(Game.gameClass.GetDevice(), stream, (int)stream.Length, D3D10.ResourceUsage.Dynamic,
                D3D10.BindFlags.VertexBuffer, D3D10.CpuAccessFlags.Write, D3D10.ResourceOptionFlags.None);
            bindingWithTexCoord = new SlimDX.Direct3D10.VertexBufferBinding(bufferWithTexCoord, 24, 0);
            stream.Close();
        }
예제 #2
0
파일: Terrain.cs 프로젝트: rtshadow/miscs
        private void CreateVertexBuffer()
        {
            //create vertex buffer
                int size = 8 * quadSize * quadSize * 6; //end size of each quad will be quadSize+1
                DataStream stream = new DataStream(size, true, true);
                for (int i = 0; i < quadSize; i++)
                    for (int j = 0; j < quadSize; j++)
                    {
                        stream.Write(new Vector2(i, j));
                        stream.Write(new Vector2(i, j + 1));
                        stream.Write(new Vector2(i + 1, j + 1));

                        stream.Write(new Vector2(i + 1, j + 1));
                        stream.Write(new Vector2(i + 1, j));
                        stream.Write(new Vector2(i, j));
                    }
                stream.Position = 0;

                vertexBuffer = new SlimDX.Direct3D10.Buffer(Game.gameClass.GetDevice(), stream, size, SlimDX.Direct3D10.ResourceUsage.Immutable,
                    SlimDX.Direct3D10.BindFlags.VertexBuffer, SlimDX.Direct3D10.CpuAccessFlags.None, SlimDX.Direct3D10.ResourceOptionFlags.None);
                stream.Close();

            instances = new Vector4[(Globals.mapSize / quadSize) * (Globals.mapSize / quadSize)];
            vertexBufferBinding = new SlimDX.Direct3D10.VertexBufferBinding(vertexBuffer, sizeof(float) * 2, 0);
        }