ITexture manipulation

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
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

ITexture manipulation

Post by Seven »

looking to manipulate an ITexture and trying to do something like the below.
is this the proper way to do this?

Code: Select all

 
        ITexture* tex = getDriver()->addTexture(dimension2d<u32>(200,200), "somename");
        
        // something like ???????????????????????????
        int pixels[4000] = tex->lock();
 
        for (int x = 0; x < 200; x++)
        for (int y = 0; y < 200; y++)
        {
             // manipulate pixels here, but how to access each pixel?
             pixels[x*y] = some color
        }
        tex->unlock();
 
mikkis
Posts: 64
Joined: Mon Jan 28, 2013 2:38 pm
Location: Fi

Re: ITexture manipulation

Post by mikkis »

Almost right.

Code: Select all

 
 
        ITexture* tex = getDriver()->addTexture(dimension2d<u32>(200,200), "somename");
        
        int *pixels= (int*)tex->lock();
 
        for (int x = 0; x < 200; x++)
        for (int y = 0; y < 200; y++)
        {
             pixels[ y*200 +x] = pixel's color in RGBA format (I think)
        }
        tex->unlock();
 
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: ITexture manipulation

Post by CuteAlien »

Still not correct as you also need to regard pitch (lines can internally be longer than width). Take a look at the implementation of CImage::setPixel (in source/Irrlicht/CImage.cpp). It should probably be done that way.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Re: ITexture manipulation

Post by Seven »

perfect. thanks all.
Post Reply