title: Draw Text with FreeType (DirectX 11)
body: <p>So I would like to draw text with FreeType (on DirectX 11). The problem is that I don't really understand how to create the my_draw_bitmap function (I follow <a href="https://www.freetype.org/freetype2/docs/tutorial/step1.html#section-1" rel="nofollow noreferrer">this tutorial</a>). </p>
  
  <p>I get all the glyphs then convert them to bitmap, but I don't see how to convert an FT_Bitmap* to a ID3D11Texture2D* (this would - <em>in theory</em> - allow me to render a text)</p>
  
  <p>Here is my code :</p>
  
  <p><strong>FontLoader.cpp</strong></p>
  
  <pre><code>    void FontLoader::RenderText(ID3D11Device* p_device, Text* p_text, Math::Vec2 p_position)
      {
      const char* text = p_text-&gt;GetText();
  
      FT_Face face = p_text-&gt;GetFont()-&gt;GetFace();
      FT_GlyphSlot slot = face-&gt;glyph;
  
      Math::Vec2 pen = p_position;
  
      for (unsigned int i = 0; i &lt; strlen(text); ++i)
      {
          if (FT_Load_Char(face, text[i], FT_LOAD_RENDER))
              continue;
  
          // draw to our target surface
          CreateTextureFromBitmap(p_device, &amp;slot-&gt;bitmap, Math::Vec2((float)slot-&gt;bitmap_left, (float)slot-&gt;bitmap_top));
  
          // Increment pen position
          pen._x += slot-&gt;advance.x &gt;&gt; 6;
      }
  }
  
  ID3D11Texture2D* FontLoader::CreateTextureFromBitmap(ID3D11Device* p_device, FT_Bitmap* p_bitmap, Math::Vec2 p_position)
  {
      D3D11_TEXTURE2D_DESC textureDesc;
      textureDesc.Width = p_bitmap-&gt;width;
      textureDesc.Height = p_bitmap-&gt;pitch;
      textureDesc.MipLevels = textureDesc.ArraySize = 1;
      textureDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
      textureDesc.SampleDesc.Count = 1;
      textureDesc.Usage = D3D11_USAGE_DYNAMIC;
      textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
      textureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
      textureDesc.MiscFlags = 0;
  
      ID3D11Texture2D *texture2D = NULL;
      // don't know how and when to use p_bitmap
      p_device-&gt;CreateTexture2D(&amp;textureDesc, NULL, &amp;texture2D);
  
      return texture2D;
  }
  </code></pre>
  
  <p>Thanks a lot !</p>