Font color stuck as black using Freetype
Closed this issue · 2 comments
We currently only have black fonts as the colors set are ignored. We can't use the methods from Direct3D8 that were previously used.
I think the following fix would work but this is disabled in the Xbox 360s version of Direct3D 9.
If you want to use the vertex colors as input to the lighting calculation, you need to set the render state D3DRS_AMBIENTMATERIALSOURCE to D3DMCS_COLOR1 (for the diffuse vertex color). The same applies to the other color components.
https://github.com/brentdc-nz/XBMC-360/blob/master/xbmc360/guilib/GUIFontTTF.cpp
Using the following very nasty hack to set the color, problem is it's very very slow and makes the font look distorted and fuzzy.
`#if 0 // Hack start - Very ugly temporary fix for font color (also slow!)
// This also makes the fonts look distorted/fuzzy.
// the plan is to resolve this as soon as possible
{
g_graphicsContext.TLock();
m_pD3DDevice->SetTexture( 0, NULL);
g_graphicsContext.TUnlock();
D3DSURFACE_DESC desc;
g_graphicsContext.TLock();
m_texture->GetLevelDesc(0, &desc);
g_graphicsContext.TUnlock();
D3DLOCKED_RECT rect;
g_graphicsContext.TLock();
m_texture->LockRect(0, &rect, NULL, 0);
g_graphicsContext.TUnlock();
char* pCurrPixel = (char*)rect.pBits;
for (int y = 0; y < (int)desc.Height; y++)
{
for (int x = 0; x < (int)desc.Width; x++)
{
if((pCurrPixel[0] != 0) || (pCurrPixel[1] != 0) || (pCurrPixel[2] != 0))
{
pCurrPixel[0] = ((dwColor>>16)&255);
pCurrPixel[1] = ((dwColor>>12)&255);
pCurrPixel[2] = (dwColor&255);
pCurrPixel[3] = 255;
}
pCurrPixel += 4;
}
}
g_graphicsContext.TLock();
m_texture->UnlockRect(0);
g_graphicsContext.TUnlock();
g_graphicsContext.TLock();
m_pD3DDevice->SetTexture( 0, m_texture );
g_graphicsContext.TUnlock();
}
#endif //Hack end`
Have now written a pixel shader that fixed this after learning some basic HLSL. Commit coming soon!