[iOS] Getting POT texture from iOS-Photo

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
IrrlichtForiOS
Posts: 61
Joined: Mon Oct 08, 2012 1:46 pm

[iOS] Getting POT texture from iOS-Photo

Post by IrrlichtForiOS »

Hey Guys,

while we try to load an iPad-Photo with an resolution of 2592x1936 as an background Texture, we are always getting an white rectangle as background...

So we implemented code, that transforms the texture to POT. As a result we get a Texture with 2048x1024, but the rectangle es even white.

What are we doing wrong?

Code: Select all

video::ITexture *E3DCLoadImage::getPOTTextureForTexture( video::ITexture *backgroundTexture, stringc path )
{
    video::ITexture *POTText;
    
    
    int width = backgroundTexture->getSize().Width;
    int height = backgroundTexture->getSize().Height;
    
    printf("original - w:%i h:%i", width, height);
    
    int kMaxWidth = 2048;
    int kMaxHeight = 1024;
    
    int i;
    bool sizeToFit = false;
    
    // Scale image width to next pot size
    if( (width != 1) && (width & (width - 1)) )
    {
        i = 1;
        while( (sizeToFit ? 2 * i : i) < width )
            i *= 2;
        width = i;
    }
    
    // Scale image height to next pot size
    if( (height != 1) && (height & (height - 1)) )
    {
        i = 1;
        while( (sizeToFit ? 2 * i : i) < height )
            i *= 2;
        height = i;
    }
    
    // Scale image down if now larger than the maximum texture size
    while( width > kMaxWidth )
    {
        width /= 2;
        //imageWidth *= 0.5;
        //imageHeight *= 0.5;
    }
    while( height > kMaxHeight )
    {
        height /= 2;
    }
    
    printf("calculated - w:%i h:%i", width, height);
    
    core::vector2d<s32> pos = core::vector2d<s32>(0,0);
    core::dimension2d<u32> size = core::dimension2d<u32>(backgroundTexture->getSize().Width, backgroundTexture->getSize().Height);
    IImage *backimage = driver->createImage(backgroundTexture, pos, size);
    
    //IImage *backimage = driver->createImageFromFile( "fassade.jpg" );
    
    IImage *imagesmall = driver->createImage(ECF_A16B16G16R16F,core::dimension2d<u32>(512, 512));
   // backimage->copyToScaling(imagesmall, 2048, 2048);
    backimage->copyTo(imagesmall);
    
    //imagesmall->fill(video::SColor(255,181,154,109));
 
    //driver->writeImageToFile(imagesmall, "newimage.jpg");
    
    driver->addTexture(L"imagesmall.jpg", imagesmall);
    //imagesmall->drop();
    
    //IWriteFile *imagefile;
    //driver->writeImageToFile(imagesmall, imagefile);
    
    //writefile readfile
    //IReadFile *readfile = imagefile->
    POTText = driver->getTexture("imagesmall.jpg");
    
    return POTText;
}
Last edited by IrrlichtForiOS on Thu Sep 24, 2015 10:20 am, edited 1 time in total.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Getting POT texture from iOS-Photo

Post by hendu »

The software blitter does not support float textures. Try to use irr's native POT arguments.
IrrlichtForiOS
Posts: 61
Joined: Mon Oct 08, 2012 1:46 pm

Re: Getting POT texture from iOS-Photo

Post by IrrlichtForiOS »

hendu wrote:The software blitter does not support float textures. Try to use irr's native POT arguments.
Could you explain this a bit more detailed?

Thanks. :)
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: [iOS] Getting POT texture from iOS-Photo

Post by Nadro »

You can try to set TextureWrapU and TextureWrapV to ETC_CLAMP_TO_EDGE and disable mipmapping for this texture. With that settings you can use NPOT textures in OpenGL ES2 without any extensions like a GL_OES_texture_npot.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
Post Reply