I copyed ogre's code (most from OgreFont), but because of ogre made a RenderSystem API Abstraction Layer,(we only use DirectX)so I implemented the part which should be done with DirectX API(create Texture ).And the rendering of Ogre Font use the basic renderOperation, instead I use ID3DXSprite.
Here is the code of creating Texture:
Code: Select all
void Font::load(const std::string& name){
.......
// Advance a column
l += (advance + char_spacer);
// If at end of row
if( mWidth - 1 < l + ( advance ) )
{
m += ( max_height >> 6 ) + char_spacer;
l = 0;
}
}
}
HRESULT hr = 0;
hr = D3DXCreateTexture(RenderCore::getInstancePtr()->getDevice(),
mWidth, mHeight,
D3DX_DEFAULT,0,
D3DFMT_A8L8,D3DPOOL_MANAGED,&mTexture);
if(FAILED(hr)){
string msg = DXGetErrorDescriptionA(hr);
FA_EXCEPT(ERR_FONT, "Create font Texture failed: " + msg);
}
D3DLOCKED_RECT lockedRect;
mTexture->LockRect(0, &lockedRect,0, 0);
//使用类型注意
uchar* TexData = (uchar*)lockedRect.pBits; //here is the change
for(uint i = 0; i < mHeight; ++i)
{
for(uint j = 0; j < mWidth; ++j)
{
//Pitch数据的总长度
int index = i * lockedRect.Pitch / 2 + j;
TexData[index] = imageData[index]; //here is the change
}
}
mTexture->UnlockRect(0);
FT_Done_FreeType(ftLibrary);
}


When you look into my code , you will see I create the texture then save it into disk as jpg picture,then load it again.First if I don't save it then reload, no text will be outputed(screenshot1). And If I don't save it into jpg format(yes, even though jpg does not have alpha channel ,but if I saved it into png,nothing outputs. and I use DirectX Texture Viewer to check them ,found png and jpg image is black inalpha channal but in the luminance of jpg is the right font picture(maybe right)(screenshot2) ), also no text will be outputed.
Today I thought there are some place may occur this problem:
1, I saved the texture in wrong format(I use D3DFMT_A8L8, I see Ogre use PF_BYTE_LA, is that a problem of different order)
2, Maybe I made some errors among LockRect/UnLockRect of Texture.
Sorry guys, these clues are what I try best to figure out, today I have spent 6 hours on this problem,I thought it is a very simple bug,but it really confused me
Fixed it, I show the fixed code in the comments.