3
這是我第一次發佈堆棧溢出! 我正在使用SlimDX製作我的團隊正在製作的遊戲,並且遇到了問題。我試圖從Color4對象中的RGBA值創建一個ShaderResourceView。我搜索過尋找我的問題的答案,這是我得到的。使用SlimDX從RGBA值創建紋理
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;
}
我相信紋理的數據正在設置,但我不能確定,因爲沒有任何顯示。我知道我的渲染器能夠正常工作,因爲我可以從文件中加載紋理,但我似乎遇到了一個我找不到的問題。感謝您的幫助!
如果您在使用SlimDX呈現內容時遇到問題,可以使用[PIX](http://blogs.msdn.com/b/manders/archive/2006/12/15/a-painless-introduction-to -pix-for-windows.aspx)來調試實際像素。在出現意想不到的行爲的情況下查看像素歷史記錄會很有用,例如屏幕上不顯示任何內容。但請注意,您只能使用PIX調試32位版本的SlimDX。 –
嗨。前一陣子我可以看到你問這個問題,但我是DirectX和SlimDX的新手,並想知道你是否可以讓我知道你是如何初始化你的設備的。 – KairisCharm