So I started writing them and I am going to publish them here
I have written them in MSVC++6 - so they maybe have to be worked out for cross-platform development
(maybe you got some Improvments)
Code: Select all
video::ITexture* dplTexture(video::ITexture *tex, c8* name)
// Duplicates a texture.
// parameters: the Texture to Duplicate and the name for the new one
{
if (!tex) return NULL;
video::ITexture *tmp = device->getVideoDriver()->addTexture(tex->getDimension(),name);
if (tex->getColorFormat() != tmp->getColorFormat()) return NULL;
s32 pitch = tex->getPitch() ;
s32 height = tex->getDimension().Height;
c8 *s = (c8*) tex->lock();
c8 *d = (c8*) tmp->lock();
memcpy(d ,s ,pitch*height);
tmp->unlock();
tex->unlock();
return tmp;
};
s32 BlitTexture(video::ITexture *dest, video::ITexture *src, core::rect<s32> destrec, core::rect<s32> srcrec )
//Blits a texture (or a part of it) to another
//parameters: destination and source texture and the destiantion and source rectangle
{
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;
};
s32 StretchTextureFast(video::ITexture *dest, video::ITexture *src, core::rect<s32> destrec, core::rect<s32> srcrec )
//Stretch a textures (to size of destrec) and blits it to another
//parameters: destination and source texture and the destiantion and source rectangle
//Remarks: Its so fast because of fix point arithmethic and NO filtering (means pixel doubling)
{
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;
u32 yscale = (destrec.getHeight() << 16) / srcrec.getHeight();
u32 xscale = (destrec.getWidth() << 16) / srcrec.getWidth();
c8 *s = (c8*) src->lock();
c8 *d = (c8*) dest->lock();
for (s32 i = 0; i < destrec.getHeight(); i++)
for (s32 j = 0; j < destrec.getWidth();j++)
{
memcpy(
d + ((destrec.UpperLeftCorner.Y + i) * dpitch) + (pixsize * (destrec.UpperLeftCorner.X + j)) ,
s + ((srcrec.UpperLeftCorner.Y + ((i << 16) / yscale)) * spitch) + (pixsize * (srcrec.UpperLeftCorner.X + ((j << 16) / xscale))),
pixsize);
}
src->unlock();
dest->unlock();
return 1;
};
--sorry for my bad english, i am from germany--