Sign in to follow this  
Radons

DirectWrite Alpha Textures

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[i] = (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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this