repeat texture instead of scaling it

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
mike1
Posts: 9
Joined: Fri May 25, 2012 6:42 pm

repeat texture instead of scaling it

Post by mike1 »

Hi,
I want to create dynamically-sized walls in my game. I am able to achieve that using a (1,1,1) sized box and scaling it to the right size. However, I do not wish the texture of the wall to get scaled as well. I'd like it to repeat. Is this possible?
Thanks
gerdb
Posts: 194
Joined: Wed Dec 02, 2009 8:21 pm
Location: Dresden, Germany

Re: repeat texture instead of scaling it

Post by gerdb »

your texture is not scaled, it is mapped one time to your scaled box. (u=1,v=1)

so you have to scale your uv-coords to get repetition by say u=width, v=height times.

so:

core::matrix4 scale;
scale.setTextureScale( (f32)width/10.0f, (f32)height / 10.0f);
node->getMaterial(0).setTextureMatrix(0, scale);
CuteAlien
Admin
Posts: 9929
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: repeat texture instead of scaling it

Post by CuteAlien »

In SMaterial you can change the wrap-mode for each texture in the corresponding TextureLayer. There is TextureWrapU and TextureWrapV which take one of the values from E_TEXTURE_CLAMP: http://irrlicht.sourceforge.net/docu/na ... f84b39811f
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
mike1
Posts: 9
Joined: Fri May 25, 2012 6:42 pm

Re: repeat texture instead of scaling it

Post by mike1 »

Thanks for the replies!

I tried to play with setTextureScale() for a while, but I can't get it to work for all 3 dimensions.

Here's what I'm trying to to:

data->SceneNode = m_SceneManager->addCubeSceneNode( 1.0f, NULL, -1, IrrUtils::Convert(wall->GetLocation()) );
data->SceneNode->setScale( wall->GetSizes() );
data->SceneNode->setMaterialTexture( 0, m_Driver->getTexture("Data/Graphics/Textures/wall.jpg") );

core::matrix4 scale;
scale.setTextureScale( wall->GetSizes().x / 10.0f, wall->GetSizes().y / 10.0f );
data->SceneNode->getMaterial(0).setTextureMatrix( 0, scale );

I can see the mistake - assuming the wall is scaled (0.5, 2.0, 25) I'm ignoring the Y scaling. However, I'm not sure how to fix this without neglecting one of the axises.

Do you have an idea?
Thanks
mike1
Posts: 9
Joined: Fri May 25, 2012 6:42 pm

Re: repeat texture instead of scaling it

Post by mike1 »

In other words - perhaps I'd like to have every face of the cube to treat the texture independently. Is that possible?
CuteAlien
Admin
Posts: 9929
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: repeat texture instead of scaling it

Post by CuteAlien »

If the sides need to be completely independent then you need one meshbuffer for each side (more or less the definition of a meshbuffer - a part of the mesh with an own material). Meaning you have to create your own cube.
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
mike1
Posts: 9
Joined: Fri May 25, 2012 6:42 pm

Re: repeat texture instead of scaling it

Post by mike1 »

where can I see an example of creating a cube (or any other mesh) from scratch?
I found something called MeshWriter, but i don't think it's what i need...

Thanks!
CuteAlien
Admin
Posts: 9929
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: repeat texture instead of scaling it

Post by CuteAlien »

I think example 23.MeshHandling is about creating a mesh from scratch.
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
Post Reply