将多个小纹理组合成大纹理

时间:2011-09-05 07:02:13

标签: c# directx textures managed-directx

对不起,可能这是非常基本的问题,我有多个不同大小和协调的小纹理,我想在此应用一些过渡。所以我需要在大纹理中组合所有这些纹理,以制作一个单一的屏幕尺寸纹理。

3 个答案:

答案 0 :(得分:1)

您要找的是Texture Atlas

  

在实时计算机图形学中,纹理图集是一个大图像,或“地图集”,其中包含许多较小的子图像,每个子图像都是3D对象某些部分的纹理

Google搜索会为您提供摘要和生成它们的工具。

答案 1 :(得分:0)

我会说如果你不需要实时完成(即源纹理不会改变),那么只需在你最喜欢的图形编辑器中进行(例如mspaint!)。


如果您确实想在游戏中执行此操作,请参阅此问题:Render buffer to texture2D object in XNA

答案 2 :(得分:0)

针对您的任务进行修改:

    /// <summary>
    /// Line up the textures in list horizontally. Warning: All textures MUST BE one height and in strong order
    /// </summary>
    /// <param name="device">D3D device</param>
    /// <param name="textures">List of textures</param>
    /// <returns>Combined texture</returns>
    public static Texture LineUpTexturesHorizontally ( Device device, List < Texture > textures )
    {
        int dstWidth = textures.Select ( texture => texture.GetSurfaceLevel ( 0 ) ).Select ( surface => surface.Description.Width ).Sum ( );
        int dstHeight = textures [ 0 ].GetSurfaceLevel ( 0 ).Description.Height;
        Texture dstTexture = CreateTexture ( device, dstWidth, dstHeight, Color.Orange, TexMipLevels, true );
        Surface dstSurface = dstTexture.GetSurfaceLevel ( 0 );
        Point insPoint = new Point ( 0, 0 );
        for ( int i = 0; i < textures.Count; i++ )
        {
            PaletteEntry [ ] pal; // = new PaletteEntry[ 256 ];
            Texture srcTexture = textures [ i ];
            Surface srcSurface = srcTexture.GetSurfaceLevel ( 0 );
            int srcWidth = srcSurface.Description.Width;
            int srcHeight = srcSurface.Description.Height;
            Rectangle srcRectangle = new Rectangle ( 0, 0, srcWidth, srcHeight );
            Rectangle dstRectangle = new Rectangle ( insPoint, new Size ( srcWidth, srcHeight ) );
            SurfaceLoader.FromSurface ( dstSurface, out pal, dstRectangle, srcSurface, out pal, srcRectangle, Filter.None, 0 );
            insPoint.X += srcWidth;
        }
        return dstTexture;
    }