i've tried to code it on my own...
but i alwas get an acces violation error....
CGUIFont.cpp: (changed header files are not shown)
Code: Select all
void CGUIFont::drawTexture(video::ITexture* dest, const wchar_t* text, const core::rect<s32>& position, video::SColor color, bool hcenter, bool vcenter)
{
if ((!Driver) || (!dest))
return;
core::dimension2d<s32> textDimension;
core::position2d<s32> offset = position.UpperLeftCorner;
if (hcenter || vcenter)
{
textDimension = getDimension(text);
if (hcenter)
offset.X = ((position.getWidth() - textDimension.Width)>>1) + offset.X;
if (vcenter)
offset.Y = ((position.getHeight() - textDimension.Height)>>1) + offset.Y;
}
u32 n;
while(*text)
{
n = (*text) - 32;
if ( n > Positions.size())
n = WrongCharacter;
BlitTexture(dest,Texture,core::rect<s32>(offset.X,offset.Y,dest->getDimension().Width,dest->getDimension().Height),Positions[n] );
offset.X += Positions[n].getWidth();
++text;
}
}
(is not supporting transparency)
Code: Select all
s32 BlitTexture(video::ITexture *dest, video::ITexture *src, core::rect<s32> destrec, core::rect<s32> srcrec )
{
if ( (!dest) || (!src)) return 0;
if (src->getColorFormat() != dest->getColorFormat()) return 0;
s32 spitch = src->getPitch();
s32 dpitch = dest->getPitch();
s32 pixsize = spitch / src->getDimension().Width;
if (pixsize != (dpitch / dest->getDimension().Width)) return 0;
destrec.clipAgainst(core::rect<s32>(core::position2d<s32>(0,0),dest->getDimension()) );
srcrec.clipAgainst(core::rect<s32>(core::position2d<s32>(0,0),src->getDimension()) );
core::rect<s32> cprec(srcrec);
cprec.clipAgainst(destrec);
s32 newpitch = pixsize * cprec.getWidth();
c8 *s = (c8*) src->lock();
c8 *d = (c8*) dest->lock();
for (s32 i = 0; i < cprec.getHeight(); i++)
memcpy(
d + ((destrec.UpperLeftCorner.Y + i) * dpitch) + (pixsize * destrec.UpperLeftCorner.X) ,
s + ((srcrec.UpperLeftCorner.Y + i) * spitch) + (pixsize * srcrec.UpperLeftCorner.X),newpitch );
src->unlock();
dest->unlock();
return 1;
};