user3430914
user3430914

Reputation: 1

How do I compile a texture for SharpDX toolkit

I am trying to compile a texture for the SharpDX toolkit using tkfxc.exe grass_top.png. It works OK, but it gives me a 42 byte file called grass_top.tkb, while the original file was ~5KB. If I try

Texture2D grass_top=Content.Load<Texture2D>("grass_top");

it says An unhandled exception of type 'System.NotSupportedException' occurred in SharpDX.Toolkit.dll. Additional information: Unable to load content. Thanks :)

Upvotes: 0

Views: 615

Answers (2)

Der_Meister
Der_Meister

Reputation: 5007

I wrote a small tool to precompile textures.

using SharpDX.Toolkit.Graphics;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace tktex
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Usage: tktex <texture file>");
                return;
            }

            try
            {
                string fileName = args[0];
                string newName = Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName) + ".tktx");

                var image = Image.Load(fileName);
                image.Save(newName, ImageFileType.Tktx);

                Console.WriteLine(fileName + " => " + newName);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
    }
}

https://github.com/dermeister0/SharpDX.Tools

Upvotes: 0

xoofx
xoofx

Reputation: 3762

tkfxc is used to compile shaders, so it is expecting a hlsl file. Looks like it was able to read the png as an empty string, reason why you got an empty shader bytecode. Check toolkit samples on how to integrate textures, but they are basically copied to the content directory without any further processing. Samples are using the build action ToolkitTexture to copy the texture to the output (so that in the future, if there are some processing, it will work out of the box)

Upvotes: 2

Related Questions