save more than one image to one imagefile

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
gamescore
Posts: 35
Joined: Sun Jan 29, 2012 10:21 pm

save more than one image to one imagefile

Post by gamescore »

in the last few days is programmed a programm that creates sprite sheets from 3d models.
now i want to combine more than one IImages to save it to one image file. (through screenshots)
in the end it should look like this:
Image
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: save more than one image to one imagefile

Post by REDDemon »

IImage API provide methods for copying portion of images to other portion of other images. check the available methods.


directly from IImage.h file inside irrlicht include folder

Code: Select all

 
        //! copies this surface into another
        virtual void copyTo(IImage* target, const core::position2d<s32>& pos=core::position2d<s32>(0,0)) =0;
 
        //! copies this surface into another
        virtual void copyTo(IImage* target, const core::position2d<s32>& pos, const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect=0) =0;
 
        //! copies this surface into another, using the alpha mask and cliprect and a color to add with
        virtual void copyToWithAlpha(IImage* target, const core::position2d<s32>& pos,
                        const core::rect<s32>& sourceRect, const SColor &color,
                        const core::rect<s32>* clipRect = 0) =0;
 
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
gamescore
Posts: 35
Joined: Sun Jan 29, 2012 10:21 pm

Re: save more than one image to one imagefile

Post by gamescore »

that is exactly what i need, i will take a try and post my results and probably some further questions
gamescore
Posts: 35
Joined: Sun Jan 29, 2012 10:21 pm

Re: save more than one image to one imagefile

Post by gamescore »

oh thanks :D
gamescore
Posts: 35
Joined: Sun Jan 29, 2012 10:21 pm

Re: save more than one image to one imagefile

Post by gamescore »

Another question, how can i convert Itextur to Iimage to save it?
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: save more than one image to one imagefile

Post by serengeor »

Probably with this

Code: Select all

virtual IImage *        createImage (ITexture *texture, const core::position2d< s32 > &pos, const core::dimension2d< u32 > &size)=0 
Creates a software image from a part of a texture.
Working on game: Marrbles (Currently stopped).
gamescore
Posts: 35
Joined: Sun Jan 29, 2012 10:21 pm

Re: save more than one image to one imagefile

Post by gamescore »

thank you, but it just works, when nodell is loaded (its a render target texture) :S

declaration:

Code: Select all

video::ITexture* prevSprite;
create:

Code: Select all

void scene_initPrevTexture(){
    if (driver->queryFeature(video::EVDF_RENDER_TO_TARGET)){
        prevSprite = driver->addRenderTargetTexture(core::dimension2d<u32>(512,512), "RTT1");
 
        // add fixed camera
        fixedCam = smgr->addCameraSceneNode(0, core::vector3df(0,0,-150));
    }
    else{
                error(L"Your driver cannot render to texture"); 
    }
}
update:

Code: Select all

void scene_updatePrevTexture(){
    // set render target texture
    driver->setRenderTarget(prevSprite, true, true, rendercolor);
 
    // make cube invisible and set fixed camera as active camera
    smgr->setActiveCamera(fixedCam);
 
    // draw whole scene into render buffer
    smgr->drawAll();
 
    // set back old render target
    // The buffer might have been distorted, so clear it
    driver->setRenderTarget(0, true, true, 0);
 
    // make the cube visible and set the user controlled camera as active one
    smgr->setActiveCamera(cam);
}
finally save the image:

Code: Select all

void save(){
        video::IImage* export_img = driver->createImage(prevSprite,core::vector2d<s32>(0,0),core::dimension2d<u32>(512, 512));
        driver->writeImageToFile(export_img, L"one.dds");
}
But it works if no model is loaded and drawing works too.

Code: Select all

    while (device->run()){
                driver->beginScene(true, true, rendercolor);
                
                //smgr->drawAll();
 
                scene_updatePrevTexture();
                driver->draw2DRectangle(video::SColor(100,255,255,255), core::rect<s32>(0, 0, resX, resY));
                driver->draw2DImage(prevSprite, core::position2d<s32>(4,24), core::rect<s32>(0,0,512,512), 0, video::SColor(255,255,255,255)/*, true*/);
 
                gui_render();
            //smgr->drawAll();
                guienv->drawAll();
                
                driver->endScene();
    }
gamescore
Posts: 35
Joined: Sun Jan 29, 2012 10:21 pm

Re: save more than one image to one imagefile

Post by gamescore »

ok, it works :D

How can i create an alpha chanel from a color for saving an image?
Post Reply