2012-03-07 9 views
2

C# 게임을 OpenTK (OpenGL)에서 SharpDX (DirectX)로 변환하여 Visual Studio 2010에서 실행하고 있습니다. Visual Studio 11에서 Visual Studio 11을 실행하고 있습니다. Metro, Windows 8 개발자 미리보기. 그러나 Metro 빌드에는 텍스처가 부족하기 때문에 지금은 다각형이 색칠되어 있습니다. 문제는 이미지를로드하는 데 사용 된 메소드가 Metro DLL에 없다는 것입니다. 이러한 방법은 모든 Windows 스토어 앱에 (리소스 클래스에서 상속)을 Texture2D 클래스에서 누락 :Windows에서 SharpDX로 텍스처로드 Store App

SharpDX.Direct3D11.Resource.FromStream 
SharpDX.Direct3D11.Resource.FromFile 
SharpDX.Direct3D11.Resource.FromMemory 
이 결국 지하철에서 구현 될 경우

사람이 알고 있나요? 아니면 내가 사용할 수있는 대체 방법이 있습니까? 이 전에는 DirectX 나 SharpDX에 대해 전혀 몰랐다는 것을 명심하십시오. 그래서 나는이 모든 것을 가지고 여전히 귀 뒤에 젖어 있습니다.

SharpDX에 대한 도움말이나 정보를 찾는 것이 쉽지 않습니다. 이는 C#을 사용하는 Metro의 3D에 훌륭한 솔루션 인 것처럼 보이기 때문에 부끄러운 일입니다.

+0

을 게시 할 수있다, 그들은 여기 사람들보다 미래의 계획을 더 잘 인식 할 수 있습니다. – ssube

+0

그들은 자신의 포럼이나 메일 링리스트를 가지고 있지 않습니다. =/http://code.google.com/p/sharpdx/ – msedore

+0

바보입니다. 어쩌면 문제를 제기 할 수 있을까요? 나는 꽤 최근의 것들을 보지만, 그들이 반응하는지는 모른다. – ssube

답변

2

좋은 소식! SharpDX의 저자 인 Alexandre Mutel은 Microsoft가 Direct3D11에서 "도우미 메서드"를 제거했다는 사실을 알려주었습니다. SharpDX에 의한 누락이 아니 었습니다. 그리고 그는 또한 올바른 방향으로 나를 지적했습니다. WIC를 사용하여 내 텍스처를로드하는 방법. 난 그냥 방법이 필요

http://crazylights.googlecode.com/svn/CLReach/win8/SDX_CLGC/clgc.cs

: LoadBitmap()와 CreateTex2DFromBitmap() 나는 샘플 여기에 코드를 발견했다. "R8G8B8A8_UNorm_SRgb"을 "R8G8B8A8_UNorm"으로 변경해야했지만 궁극적으로는 제대로 작동했습니다. 이제 내 게임은 메트로에서 멋지게 보입니다. 모든 텍스처가 제 위치에 있습니다! :)

6

내가 명확하게 질문을 이해했는지 모르겠지만 SharpDX 샘플에서 'LoadBitmap'과 'CreateTexture2DFromBitmap'의 두 가지 메서드가있는 'TextureLoader'클래스를 발견했습니다. 봐, 당신은 .jpg 파일을, .png를, .BMP에서 BitmapSource는로드이 기능을 사용할 수 있습니다

public static Texture2D CreateTexture2DFromBitmap(Device device, BitmapSource bitmapSource) 
    { 
     // Allocate DataStream to receive the WIC image pixels 
     int stride = bitmapSource.Size.Width * 4; 
     using (var buffer = new SharpDX.DataStream(bitmapSource.Size.Height * stride, true, true)) 
     { 
      // Copy the content of the WIC to the buffer 
      bitmapSource.CopyPixels(stride, buffer); 
      return new SharpDX.Direct3D11.Texture2D(device, new SharpDX.Direct3D11.Texture2DDescription() 
      { 
       Width = bitmapSource.Size.Width, 
       Height = bitmapSource.Size.Height, 
       ArraySize = 1, 
       BindFlags = SharpDX.Direct3D11.BindFlags.ShaderResource, 
       Usage = SharpDX.Direct3D11.ResourceUsage.Immutable, 
       CpuAccessFlags = SharpDX.Direct3D11.CpuAccessFlags.None, 
       Format = SharpDX.DXGI.Format.R8G8B8A8_UNorm, 
       MipLevels = 1, 
       OptionFlags = SharpDX.Direct3D11.ResourceOptionFlags.None, 
       SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0), 
      }, new SharpDX.DataRectangle(buffer.DataPointer, stride)); 
     } 
    } 

및 순서에 :

public static BitmapSource LoadBitmap(ImagingFactory2 factory, string filename) 
    { 
     var bitmapDecoder = new SharpDX.WIC.BitmapDecoder(
      factory, 
      filename, 
      SharpDX.WIC.DecodeOptions.CacheOnDemand 
      ); 

     var result = new SharpDX.WIC.FormatConverter(factory); 

     result.Initialize(
      bitmapDecoder.GetFrame(0), 
      SharpDX.WIC.PixelFormat.Format32bppPRGBA, 
      SharpDX.WIC.BitmapDitherType.None, 
      null, 
      0.0, 
      SharpDX.WIC.BitmapPaletteType.Custom); 

     return result; 
    } 

BitmapSource는에서 Texture2D를 얻으려면 당신이 이것을 사용할 수 있습니다

 public static Texture2D LoadFromFile(Device device, ImagingFactory2 factory, string fileName) 
     { 
      var bs = LoadBitmap(factory, fileName); 
      var texture = CreateTexture2DFromBitmap(device, bs); 
      return texture; 
     } 
3

당신은 또한 BitmapImage (이 지하철에서 작동에서 그들을 만들 수 있습니다, 지하철에서 텍스처를로드하는 WIC를 사용할 필요가 없습니다 및 덜 빌려 : 그것은 쉽게,이 기능을 만들었습니다 licated) :

public static Texture2D FromImage(BitmapImage image, GraphicsDevice device) 
{ 
    WriteableBitmap bitmap = new WriteableBitmap(image); 

    return FromImageData(bitmap.Pixels, bitmap.PixelWidth, 
          bitmap.PixelHeight, device); 
} 

public static Texture2D FromImageData(int[] data, int width, int height, GraphicsDevice device) 
{ 
    Texture2D texture = Texture2D.New(device, width, height, 
            PixelFormat.B8G8R8A8.UNorm); 

    texture.SetData<int>(data); 

    return texture; 
} 

여기에 내 대답을 참조하십시오 :이 더 나은 자신의 포럼이나 메일 링리스트에 SharpDX load a texture in Windows Phone 8