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.

save more than one image to one imagefile

Postby gamescore » Sun Mar 18, 2012 5:54 am

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
gamescore
 
Posts: 35
Joined: Sun Jan 29, 2012 10:21 pm

Re: save more than one image to one imagefile

Postby REDDemon » Sun Mar 18, 2012 9:14 am

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
cpp 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;
 
OpenGL is not hard. What you have to do is just explained in specifications. What is hard is dealing with poor OpenGL implementations.
User avatar
REDDemon
 
Posts: 831
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: save more than one image to one imagefile

Postby gamescore » Sun Mar 18, 2012 9:52 am

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

Postby RdR » Sun Mar 18, 2012 11:58 am

Also take a look here: viewtopic.php?f=6&t=25397
User avatar
RdR
Competition winner
 
Posts: 259
Joined: Tue Mar 29, 2011 2:58 pm

Re: save more than one image to one imagefile

Postby gamescore » Sun Mar 18, 2012 1:33 pm

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

Re: save more than one image to one imagefile

Postby gamescore » Sat Mar 24, 2012 9:26 am

Another question, how can i convert Itextur to Iimage to save it?
gamescore
 
Posts: 35
Joined: Sun Jan 29, 2012 10:21 pm

Re: save more than one image to one imagefile

Postby serengeor » Sat Mar 24, 2012 9:52 am

Probably with this
cpp 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).
User avatar
serengeor
 
Posts: 1695
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: save more than one image to one imagefile

Postby gamescore » Sat Mar 24, 2012 10:04 am

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

declaration:
cpp Code: Select all
video::ITexture* prevSprite;

create:
cpp 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:
cpp 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:
cpp 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.
cpp 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

Postby gamescore » Sat Mar 24, 2012 9:18 pm

ok, it works :D

How can i create an alpha chanel from a color for saving an image?
gamescore
 
Posts: 35
Joined: Sun Jan 29, 2012 10:21 pm


Return to Beginners Help

Who is online

Users browsing this forum: trivtn and 1 guest