Guest User

Not Even Getting to DirectWrite

a guest
Jul 24th, 2018
1,210
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. In my mission to use DirectWrite as a font rasterizer on Windows I have gone down many roads.
  3.  
  4. Today on this mission I learned to:
  5. Initialize D3D10 and D3D10_1
  6. Create a D3D10 texture
  7. Get a DXGI surface
  8. Set a debug mode flag on a D2D factory
  9.  
  10. What I never even got around to before I ran out of ideas on how to get the below code to work:
  11. Initializing DirectWrite
  12.  
  13. Any advice would be appreciated: @AllenWebster4th
  14. */
  15.  
  16. int main(){
  17. HRESULT error = 0;
  18.  
  19. ID3D10Device1 *d3d_device = 0;
  20. error = D3D10CreateDevice1(0,
  21. D3D10_DRIVER_TYPE_HARDWARE,
  22. 0,
  23. D3D10_CREATE_DEVICE_SINGLETHREADED|
  24. D3D10_CREATE_DEVICE_DEBUG|
  25. D3D10_CREATE_DEVICE_BGRA_SUPPORT|
  26. 0,
  27. D3D10_FEATURE_LEVEL_10_0,
  28. D3D10_1_SDK_VERSION,
  29. &d3d_device);
  30.  
  31. D3D10_TEXTURE2D_DESC d3d_texture_desc = {0};
  32. d3d_texture_desc.Width = 200;
  33. d3d_texture_desc.Height = 200;
  34. d3d_texture_desc.MipLevels = 1;
  35. d3d_texture_desc.ArraySize = 1;
  36. d3d_texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UINT;
  37. d3d_texture_desc.SampleDesc.Count = 1;
  38. d3d_texture_desc.SampleDesc.Quality = 0;
  39. d3d_texture_desc.Usage = D3D10_USAGE_STAGING;
  40. d3d_texture_desc.BindFlags = 0;
  41. d3d_texture_desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ|D3D10_CPU_ACCESS_WRITE;
  42. d3d_texture_desc.MiscFlags = 0;
  43.  
  44. ID3D10Texture2D *d3d_texture = 0;
  45. error = d3d_device->CreateTexture2D(&d3d_texture_desc, 0, &d3d_texture);
  46.  
  47. IDXGISurface *dxgi_surface = 0;
  48. error = d3d_texture->QueryInterface(__uuidof(IDXGISurface), (void**)&dxgi_surface);
  49.  
  50. D2D1_FACTORY_OPTIONS d2d_factory_options = {};
  51. d2d_factory_options.debugLevel = D2D1_DEBUG_LEVEL_INFORMATION;
  52.  
  53. ID2D1Factory *d2d_factory = 0;
  54. error = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory), &d2d_factory_options, (void**)&d2d_factory);
  55.  
  56. D2D1_RENDER_TARGET_PROPERTIES render_target_properties = {};
  57. render_target_properties.type = D2D1_RENDER_TARGET_TYPE_DEFAULT;
  58. render_target_properties.pixelFormat = D2D1::PixelFormat(DXGI_FORMAT_R8G8B8A8_UINT, D2D1_ALPHA_MODE_IGNORE);
  59. render_target_properties.dpiX = 96.f;
  60. render_target_properties.dpiY = 96.f;
  61. render_target_properties.usage = D2D1_RENDER_TARGET_USAGE_NONE;
  62. render_target_properties.minLevel = D2D1_FEATURE_LEVEL_10;
  63.  
  64. ID2D1RenderTarget *render_target = 0;
  65. error = d2d_factory->CreateDxgiSurfaceRenderTarget(dxgi_surface, render_target_properties, &render_target);
  66.  
  67. return(0);
  68. }
RAW Paste Data