Jump to content
  • Advertisement
Sign in to follow this  

DirectWrite Alpha Textures

This topic is 3209 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I recently started working with Direct3D 11 and I want to implement text rendering through DirectWrite. I'm looking for a decent way to do it and I already managed to implement two versions where I got it working properly with Direct2D. 1) With sharing a device with Direct3D 10.1. 2) By using the GDI interop stuff. However, I would really like to ditch Direct2D and let Direct3D do all the work. I've been trying to obtain alpha textures from DirectWrite through IDWriteGlyphRunAnalysis. But I'm having trouble understanding how it works. Or how to get it into a Direct3D 11 texture. Something is going wrong. I'm hoping that some one here has some experience with these rather new API's. Thanks!

Share this post

Link to post
Share on other sites
Alright, today I had some time to give this another shot and I managed to get it to render into a texture fairly quickly. However, I'm a bit disappointed with the quality of the glyph. Overall it looks OK, but the edges are not so smooth as I had hoped. I'm calling CreateGlyphRunAnalysis with DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL and DWRITE_MEASURING_MODE_NATURAL, but changing them to other values did not really affect anything at all.

Anyway, here's a quick run down of what I'm doing right now:

// direct path; for testing
dwrite_factory->CreateFontFileReference(L"C:\\Windows\\Fonts\\Arial.ttf", NULL, &font_file);
dwrite_factory->CreateFontFace(DWRITE_FONT_FACE_TYPE_TRUETYPE, 1, &font_file, 0, DWRITE_FONT_SIMULATIONS_NONE, &font_face);
dwrite_factory->CreateGlyphRunAnalysis(&glyph_run, 1.0f, NULL, DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL, DWRITE_MEASURING_MODE_NATURAL, 0.0f, 0.0f, &glyph_run_analysis);
glyph_run_analysis->GetAlphaTextureBounds(DWRITE_TEXTURE_CLEARTYPE_3x1, &rect);
glyph_run_analysis->CreateAlphaTexture(DWRITE_TEXTURE_CLEARTYPE_3x1, &rect, glyph_data, glyph_size);
// rgb average
for (int i = 0; i < glyph_size / 3; ++i) {
alpha_data = (glyph_data[i * 3] + glyph_data[i * 3 + 1] + glyph_data[i * 3 + 2]) / 3;
// create a texture with DXGI_FORMAT_A8_UNORM

Here's the output: http://img683.imageshack.us/img683/2139/resulte.png

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!