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를 사용하여 SlimDX의 32 비트 버전 만 디버깅 할 수 있습니다. –
안녕하세요. 잠시 전에 당신이 이걸 물어 보았습니다 만, DirectX와 SlimDX에 익숙하지 않아서 당신이이 장치를 어떻게 초기화했는지 알려 주실 수 있는지 궁금합니다. – KairisCharm