Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何为SharpDX工具箱编译纹理_C#_.net_Directx_Toolkit_Sharpdx - Fatal编程技术网

C# 如何为SharpDX工具箱编译纹理

C# 如何为SharpDX工具箱编译纹理,c#,.net,directx,toolkit,sharpdx,C#,.net,Directx,Toolkit,Sharpdx,我正在尝试使用tkfxc.exe grass\u top.png为SharpDX工具包编译纹理。它工作正常,但它给了我一个42字节的文件,名为grass\u top.tkb,而原始文件是~5KB。如果我尝试 Texture2D grass_top=Content.Load<Texture2D>("grass_top"); Texture2D grass_top=Content.Load(“grass_top”); 它表示,在SharpDX.Toolkit.dll中发生了类型为“S

我正在尝试使用tkfxc.exe grass\u top.png为SharpDX工具包编译纹理。它工作正常,但它给了我一个42字节的文件,名为grass\u top.tkb,而原始文件是~5KB。如果我尝试

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

它表示,在SharpDX.Toolkit.dll中发生了类型为“System.NotSupportedException”的未处理异常。其他信息:无法加载内容。谢谢:)

tkfxc
用于编译着色器,因此它需要一个hlsl文件。看起来它能够以空字符串的形式读取png,这就是为什么会得到空着色器字节码的原因。检查工具箱示例,了解如何集成纹理,但它们基本上是复制到内容目录中的,无需进一步处理。示例正在使用构建操作
ToolkitTexture
将纹理复制到输出(以便将来,如果有一些处理,它将开箱即用)

我编写了一个用于预编译纹理的小工具

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());
            }
        }
    }
}
使用SharpDX.Toolkit.Graphics;
使用制度;
使用System.Collections.Generic;
使用System.IO;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
名称空间tktex
{
班级计划
{
静态void Main(字符串[]参数)
{
如果(args.Length==0)
{
Console.WriteLine(“用法:tktex”);
返回;
}
尝试
{
字符串文件名=args[0];
字符串newName=Path.Combine(Path.GetDirectoryName(fileName),Path.GetFileNameWithoutExtension(fileName)+“.tktx”);
var image=image.Load(文件名);
Save(newName,ImageFileType.Tktx);
Console.WriteLine(文件名+“=>”+新名称);
}
捕获(例外e)
{
Console.WriteLine(如ToString());
}
}
}
}