I have very high quality textures (for example 1024x1024).
And I have a lot of them and all of them must be loaded.
I'm checking available memory in the system and deciding to load all of them with lower resolution.
Is there any ability to load certain texture with specified dimensions (for example 512x512 or 256x256) ?
Thank You.
How to load hires texture in lower resolution
would be nice if getTexture also takes an int that devides its size 
My Blog: http://www.freakybytes.org
For people how will search for the solution on this topic:
Here is the function, that will load any-dimension texture with necessary dimensions:
how does it works?
if keepAspectRatio is false then it will load texture scaled to size.Windth x size.Height, otherwise it will load textures with keeping aspect ration but width will not exceed size.Width and height will not exceed size.Height. If you have test.jpg with 3000x2000 dimensions and you want to scale it to 512, you can:
this code will load it with dim. 512x341 (512*2000/3000=~341). If you will execute the same code with keepAspectRatio false (which is default) you will get 512x512 texture.
Notes
- function returns NULL if loading failed.
- after executing "LoadTextureFromImage(test.jpg..." you can execute "video->getTexture(test.jpg)" as much as you want -- it will give you your previously loaded texture (so do not execute everywhere "LoadTextureFromImage(test.jpg...", but use it only at first-time loading).
Here is the function, that will load any-dimension texture with necessary dimensions:
Code: Select all
video::ITexture*
LoadTextureFromImage(IrrlichtDevice *device,
const c8 *filename,
const core::dimension2d<s32> size,
const bool keepAspectRatio=false)
{
video::ITexture *result_texture = NULL;
video::IImage *im1, *im2;
im1 = device->getVideoDriver()->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 = device->getVideoDriver()->addTexture(filename, im2);
im2->drop();
}
free(im2buf);
}
}
im1->drop();
}
return result_texture;
}
if keepAspectRatio is false then it will load texture scaled to size.Windth x size.Height, otherwise it will load textures with keeping aspect ration but width will not exceed size.Width and height will not exceed size.Height. If you have test.jpg with 3000x2000 dimensions and you want to scale it to 512, you can:
Code: Select all
LoadTextureFromImage(device,"test.jpg",core::dimension2d<s32>(512,512),true);Notes
- function returns NULL if loading failed.
- after executing "LoadTextureFromImage(test.jpg..." you can execute "video->getTexture(test.jpg)" as much as you want -- it will give you your previously loaded texture (so do not execute everywhere "LoadTextureFromImage(test.jpg...", but use it only at first-time loading).
-
MolokoTheMole
- Posts: 109
- Joined: Tue Jan 09, 2007 1:18 pm
Cool thanks.
Crimson Glory full Irrlicht game source code!
What I Do - my blog & dev log
Currently developing Link-Dead
What I Do - my blog & dev log
Currently developing Link-Dead