Beispiel #1
0
        private void DrawFilledBox(int x1, int y1, int x2, int y2, Color col)
        {
            VertexBuffer Vertices = new VertexBuffer(dxDevice, 6 * Marshal.SizeOf(typeof(Vertex)), Usage.WriteOnly, VertexFormat.None, Pool.Managed);

            DataStream stream = Vertices.Lock(0, 0, LockFlags.None);
            Vertex[] vertexData = new Vertex[6];
            vertexData[0].Position = new Vector4(x1, y1, 0f, 1f);
            vertexData[0].Color = col.ToArgb();
            vertexData[1].Position = new Vector4(x2, y1, 0f, 1f);
            vertexData[1].Color = col.ToArgb();
            vertexData[2].Position = new Vector4(x2, y2, 0f, 1f);
            vertexData[2].Color = col.ToArgb();

            vertexData[3].Position = new Vector4(x2, y2, 0f, 1f);
            vertexData[3].Color = col.ToArgb();
            vertexData[4].Position = new Vector4(x1, y2, 0f, 1f);
            vertexData[4].Color = col.ToArgb();
            vertexData[5].Position = new Vector4(x1, y1, 0f, 1f);
            vertexData[5].Color = col.ToArgb();
            stream.WriteRange(vertexData);
            Vertices.Unlock();

            dxDevice.SetStreamSource(0, Vertices, 0, Marshal.SizeOf(typeof(Vertex)));
            dxDevice.VertexFormat = VertexFormat.PositionRhw | VertexFormat.Diffuse | VertexFormat.Texture1;

            dxDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 2);

            stream.Close();
            Vertices.Dispose();
        }
Beispiel #2
0
        private void DrawMap(int x_block, int y_block, int z)
        {
            MapData map = GetMapFile(x_block, y_block, z);

            if (map == null)
            {
                return;
            }
            if (map.dxTexture == null)
            {
                return;
            }

            int lx = GetScaledX(map.UpperX);
            int ly = GetScaledY(map.UpperY);
            int mx = GetScaledX(map.LowerX);
            int my = GetScaledY(map.LowerY);

            int _lx = lx;
            int _ly = ly;
            int _mx = mx;
            int _my = my;

            if ((mx < 0) || (my < 0) || (lx > Width) || (ly > Height))
            {
                //culling
                return;
            }

            float Tu1 = 0, Tv1 = 0, Tu2 = 1, Tv2 = 1;

            //scale the texture coords
            float texture_width = Math.Abs(lx) + Math.Abs(mx);
            float texture_height = Math.Abs(ly) + Math.Abs(my);

            if (lx < 0)
            {
                Tu1 = ((float)(0 - _lx)) / ((float)(_mx - _lx));
                lx = 0;
            }

            if (ly < 0)
            {
                Tv1 = ((float)(0 - _ly)) / ((float)(_my - _ly));
                ly = 0;
            }

            if (mx > Width)
            {
                Tu2 = ((float)(Width - _lx)) / ((float)(_mx - _lx));
                mx = Width;
            }

            if (my > Height)
            {
                Tv2 = ((float)(Height - _ly)) / ((float)(_my - _ly));
                my = Height;
            }

            VertexBuffer Vertices = new VertexBuffer(dxDevice, 6 * Marshal.SizeOf(typeof(Vertex)), Usage.WriteOnly, VertexFormat.None, Pool.Managed);

            DataStream stream = Vertices.Lock(0, 0, LockFlags.None);
            Vertex[] vertexData = new Vertex[6];
            vertexData[0].Position = new Vector4(lx, ly, 0f, 1f);
            vertexData[0].Color = Color.White.ToArgb();
            vertexData[0].Tu = Tu1;
            vertexData[0].Tv = Tv1;

            vertexData[1].Position = new Vector4(mx, my, 0f, 1f);
            vertexData[1].Color = Color.White.ToArgb();
            vertexData[1].Tu = Tu2;
            vertexData[1].Tv = Tv2;

            vertexData[2].Position = new Vector4(lx, my, 0f, 1f);
            vertexData[2].Color = Color.White.ToArgb();
            vertexData[2].Tu = Tu1;
            vertexData[2].Tv = Tv2;

            vertexData[3].Position = new Vector4(mx, my, 0f, 1f);
            vertexData[3].Color = Color.White.ToArgb();
            vertexData[3].Tu = Tu2;
            vertexData[3].Tv = Tv2;

            vertexData[4].Position = new Vector4(lx, ly, 0f, 1f);
            vertexData[4].Color = Color.White.ToArgb();
            vertexData[4].Tu = Tu1;
            vertexData[4].Tv = Tv1;

            vertexData[5].Position = new Vector4(mx, ly, 0f, 1f);
            vertexData[5].Color = Color.White.ToArgb();
            vertexData[5].Tu = Tu2;
            vertexData[5].Tv = Tv1;
            stream.WriteRange(vertexData);
            Vertices.Unlock();

            switch (Globals.Texture_Mode)
            {
                case 1:
                    dxDevice.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Linear);
                    break;
                case 2:
                    dxDevice.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.GaussianQuad);
                    break;
                default:
                    dxDevice.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Point);//TextureFilter.None
                    break;
            }

            dxDevice.SetTexture(0, map.dxTexture);
            dxDevice.SetStreamSource(0, Vertices, 0, Marshal.SizeOf(typeof(Vertex)));
            dxDevice.VertexFormat = VertexFormat.PositionRhw | VertexFormat.Diffuse | VertexFormat.Texture1;

            dxDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 2);
            dxDevice.SetTexture(0, null);

            stream.Close();
            Vertices.Dispose();
        }