C# 使用SlimDX从RGBA值创建纹理

C# 使用SlimDX从RGBA值创建纹理,c#,slimdx,texture2d,C#,Slimdx,Texture2d,这是我第一篇关于堆栈溢出的帖子! 我正在使用SlimDX进行我的团队正在制作的游戏,我遇到了一个问题。我正在尝试从Color4对象中的RGBA值创建ShaderResourceView。我一直在寻找我的问题的答案,这是我所能得到的 private ShaderResourceView GetTexture(Device device, int width, int height, Color4 color) { //create the texture

这是我第一篇关于堆栈溢出的帖子! 我正在使用SlimDX进行我的团队正在制作的游戏,我遇到了一个问题。我正在尝试从Color4对象中的RGBA值创建ShaderResourceView。我一直在寻找我的问题的答案,这是我所能得到的

    private ShaderResourceView GetTexture(Device device, int width, int height, Color4 color)
    {
        //create the texture
        Texture2D texture = null;
        Texture2DDescription desc2 = new Texture2DDescription();
        desc2.SampleDescription = new SlimDX.DXGI.SampleDescription(1, 0); 
        desc2.Width = width;
        desc2.Height = height;
        desc2.MipLevels = 1;
        desc2.ArraySize = 1;
        desc2.Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm;
        desc2.Usage = ResourceUsage.Dynamic;
        desc2.BindFlags = BindFlags.ShaderResource;
        desc2.CpuAccessFlags = CpuAccessFlags.Write;
        texture = new Texture2D(device, desc2);


        // fill the texture with rgba values
        DataRectangle rect = texture.Map(0, MapMode.WriteDiscard, MapFlags.None);
        if (rect.Data.CanWrite)
        {
            for (int row = 0; row < texture.Description.Height; row++)
            {
                int rowStart = row * rect.Pitch;
                rect.Data.Seek(rowStart, System.IO.SeekOrigin.Begin);
                for (int col = 0; col < texture.Description.Width; col++)
                {
                    rect.Data.WriteByte((byte)color.Red);
                    rect.Data.WriteByte((byte)color.Green);
                    rect.Data.WriteByte((byte)color.Blue);
                    rect.Data.WriteByte((byte)color.Alpha);
                }
            }
        }
        texture.Unmap(0);

        // create shader resource that is what the renderer needs
        ShaderResourceViewDescription desc = new ShaderResourceViewDescription();
        desc.Format = texture.Description.Format;
        desc.Dimension = ShaderResourceViewDimension.Texture2D;
        desc.MostDetailedMip = 0;
        desc.MipLevels = 1;
        ShaderResourceView srv = new ShaderResourceView(device, texture, desc);

        return srv;
    }
private ShaderResourceView GetTexture(设备设备、int-width、int-height、Color4-color)
{
//创建纹理
Texture2D texture=null;
Texture2DDescription desc2=新的Texture2DDescription();
desc2.SampleDescription=新SlimDX.DXGI.SampleDescription(1,0);
描述2.宽度=宽度;
描述2.高度=高度;
desc2.mipglevels=1;
desc2.ArraySize=1;
desc2.Format=SlimDX.DXGI.Format.R8G8B8A8_UNorm;
desc2.Usage=ResourceUsage.Dynamic;
desc2.BindFlags=BindFlags.ShaderResource;
desc2.CpuAccessFlags=CpuAccessFlags.Write;
纹理=新纹理2d(设备,描述2);
//使用rgba值填充纹理
DataRectangle rect=texture.Map(0,MapMode.WriteDiscard,MapFlags.None);
if(rect.Data.CanWrite)
{
对于(int row=0;row

我相信纹理的数据正在设置,但我不能确定,因为没有显示任何内容。我知道我的渲染器可以很好地从文件加载纹理,但我似乎有一个找不到的问题。提前谢谢你的帮助

我一直都有正确的代码。我觉得自己像个白痴,但我发现了我的问题,我没有设置纹理的alpha值,所以它实际上是在绘制,我只是看不到它>\u如果您在使用SlimDX渲染内容时遇到问题,您可以使用它来调试实际像素。在出现意外行为(例如屏幕上没有显示任何内容)的情况下,查看像素历史记录非常有用。但是请注意,您只能使用PIX.Hi调试32位版本的SlimDX。我知道你刚才问过这个问题,但我是DirectX和SlimDX的新手,不知道你能否告诉我你是如何为此初始化设备的。