Karl Hansson
Karl Hansson

Reputation: 237

Font Outline Beizier Spline Contoures and DirectWrite

I'm considering maybe using DirectWrite for a project that will be coming in a DirectX 11 version and a OpenGL 3.1+ version.

From what understand, DirectWrite uses Direct2D which sits on top of Direct3D 10.1 (until DirectX 11.1 is released). This means that to use DirectWrite with Direct3D 11, currently, I would have to create one Direct3D 10.1 device and a Direct3D 11 device and then share the resources between these two devices, which comes with some synchronization overhead it seems. Another problem is that I won't seem to be able to render the text directly to the d3d11 backbuffer with this set up, right...?

Also I have no idea if it is even possible to combine DirectWrite with OpenGL in any practical sense..? My guess is not...

Sooo... I'm also considering writing my own font renderer and I would like to be able to render the fonts based on their Bezier spline outlines for resolution independence. I know about the GetGlyphOutline() function but it seems to be in the process of being deprecated and "...should not be used in new applications" according to MSDN library. And looking at DirectWrites reference pages at MSDN, I can't see any way of getting the same in Bezier spline information like you can with GetGlyphOutline(). You can get the outline information wrapped in a ID2D1SimplifiedGeometrySink, but I can't see how you get the pure Bezier curve, control points, information from the ID2D1SimplifiedGeometrySink, you can only use it for drawing using D2D (D3D10.1) which I am not so much interested in at this point.

Is there a way to get the font outline contours using a non-deprecated method, DirectWrite or otherwise?

I'm not that familiar with either DirectWrite and Direct2D as you can probably tell. I'm trying to figure out what direction to take. Whether it is worth going down the DirectWrite/D2D road, or to make my own font renderer, or some other brilliant idea :). Any suggestions?

PS I'm currently developing for the Win7 platform and will migrate to Win8 when it is released.

Upvotes: 0

Views: 1204

Answers (1)

Rick Brewster
Rick Brewster

Reputation: 3504

Fortunately you have it a little backwards. Direct2D uses DirectWrite, not the other way around. You can technically use DirectWrite on its own (see: IDWriteBitmapRenderTarget). If you're at the prototyping stage, it may be easier to use Direct2D to do software rendering into an IWICBitmap created through IWICImagingFactory::CreateBitmap() (or just wrap a bitmap you've already created, and implement IWICBitmap yourself). You use ID2D1Factory::CreateWicBitmapRenderTarget(), call ID2D1RenderTarget::BeginDraw(), then create your IDWriteTextFormat and/or IDWriteTextLayout via IDWriteFactory, and then call DrawText() or DrawTextLayout() on the render target, then EndDraw(). Then you copy into a hardware texture and draw it however you like.

Upvotes: 3

Related Questions