I got a texture loaded with Irrlicht, but it's go he wrong size. It's squarish, and I need it streched to each end of the screen. How I get the size of the screen I already know, but I have no idea of scaling the texture to the right size.
Oh, and is there a way to create new GUI-skins with some textures I already got?
Scaling textures?
Here is a function from my old sources.
I used it to load any image and return ITexture of desired size back.
Its able to load image like 4999x2999 size (non power-of-two & bigger that actual max-texture-size supported by current video driver).
It will return null if anything went wrong, like file not found, or not enough memory or failed to create texture.
Note: Game.Video is type of IVideoDriver*.
I used it to load any image and return ITexture of desired size back.
Its able to load image like 4999x2999 size (non power-of-two & bigger that actual max-texture-size supported by current video driver).
It will return null if anything went wrong, like file not found, or not enough memory or failed to create texture.
Note: Game.Video is type of IVideoDriver*.
Code: Select all
video::ITexture*
GameLoadTextureFromImage(const c8 *filename,
const core::dimension2d<s32> size,
bool keepAspectRatio)
{
video::ITexture *result_texture = NULL;
video::IImage *im1, *im2;
im1 = Game.Video->createImageFromFile(filename);
if (im1)
{
core::dimension2di im1size = im1->getDimension();
if (im1size.Width>0 && im1size.Height>0)
{
core::dimension2di im2size = size;
if (keepAspectRatio)
{
if (im1size.Width>im1size.Height)
{
im2size.Height = (im1size.Height*size.Width)/im1size.Width;
im2size.Width = size.Width;
}
else
{
im2size.Width = (im1size.Width*size.Height)/im1size.Height;
im2size.Height = size.Height;
}
}
s32 *im2buf = (s32*) malloc(sizeof(s32)*im2size.Width*im2size.Height);
if (im2buf)
{
im2 = Game.Video->createImageFromData(video::ECF_A8R8G8B8, core::dimension2di(im2size.Width,im2size.Height), im2buf);
if (im2)
{
im1->copyToScaling(im2);
result_texture = Game.Video->addTexture(filename, im2);
im2->drop();
}
free(im2buf);
}
}
im1->drop();
}
return result_texture;
}
OK, that helped me a lot. Thanks.greenya wrote:Here is a function from my old sources.
I used it to load any image and return ITexture of desired size back.
Its able to load image like 4999x2999 size (non power-of-two & bigger that actual max-texture-size supported by current video driver).
It will return null if anything went wrong, like file not found, or not enough memory or failed to create texture.
Note: Game.Video is type of IVideoDriver*.
Code: Select all
video::ITexture* GameLoadTextureFromImage(const c8 *filename, const core::dimension2d<s32> size, bool keepAspectRatio) { video::ITexture *result_texture = NULL; video::IImage *im1, *im2; im1 = Game.Video->createImageFromFile(filename); if (im1) { core::dimension2di im1size = im1->getDimension(); if (im1size.Width>0 && im1size.Height>0) { core::dimension2di im2size = size; if (keepAspectRatio) { if (im1size.Width>im1size.Height) { im2size.Height = (im1size.Height*size.Width)/im1size.Width; im2size.Width = size.Width; } else { im2size.Width = (im1size.Width*size.Height)/im1size.Height; im2size.Height = size.Height; } } s32 *im2buf = (s32*) malloc(sizeof(s32)*im2size.Width*im2size.Height); if (im2buf) { im2 = Game.Video->createImageFromData(video::ECF_A8R8G8B8, core::dimension2di(im2size.Width,im2size.Height), im2buf); if (im2) { im1->copyToScaling(im2); result_texture = Game.Video->addTexture(filename, im2); im2->drop(); } free(im2buf); } } im1->drop(); } return result_texture; }
But what's about the skins?