I'm creating a texture is DirectX 11 from bitmap fonts. I realize that I can use DXTK, but this is an exercise for me, not in learning another library. My sample code looks like this.
// Object Declarations
Texture2D g_MeshTexture; // Color texture for mesh
SamplerState MeshTextureSampler
{
Filter = MIN_MAG_MIP_LINEAR;
AddressU = Wrap;
AddressV = Wrap;
};
float4 PS(VS_OUTPUT input) : SV_TARGET
{
return g_MeshTexture.Sample(MeshTextureSampler, input.uv);
}
The texture of the rendered font produces strange blue artifacts where the text should have alpha values but instead appear as blue.
I did try gamma color correction with the code
float4 PS(VS_OUTPUT input) : SV_TARGET
{
float4 sRGBA = g_MeshTexture.Sample(MeshTextureSampler, input.uv);
float3 sRGB = float3(sRGBA.x, sRGBA.y, sRGBA.z);
float3 gRGB = pow(sRGB, 1/2.2);
return float4(gRGB.x, gRGB.y, gRGB.z, sRGBA.w);
}
However this did not provide results any different from what the image showed above. I sample the text from the bitmap data and store it in a vector when then is used to create the texture with CreateTexture2D.
for (long y = 0; y < m_texture_height; y++)
{
for (long x = 0; x < m_texture_width; x++)
{
BYTE alpha = (bitmap_bits[m_texture_width * y + x] & 0xff);
if (alpha > 0)
pixel_data.push_back(0xFFFFFF00 + alpha);
else
pixel_data.push_back(0);
}
}
My back buffer uses DXGI_FORMAT_R32G32B32A32_FLOAT, however I have tried DXGI_FORMAT_R8G8B8A8_UNORM and experienced no change. If there's any other information I should provide please let me know.