Question

Sorry for this, may be this is very basic question, I have multiple small texture with different size and co-ordinate, and i want apply some transition on this. So i need to combine all this textures in a large texture to make one one single texture of screen size.

Was it helpful?

Solution

I'd say if you don't need this done real-time (i.e. the source textures don't change), then just do it in your favourite graphics editor (e.g. mspaint!).


If you do want to do this in-game, then see this question: Render buffer to texture2D object in XNA

OTHER TIPS

What you are looking for is called Texture Atlas

In realtime computer graphics, a texture atlas is a large image, or "atlas" which contains many smaller sub-images, each of which is a texture for some part of a 3D object

Google search will give you summary and tools for generating them.

Modify this for your task:

    /// <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;
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top