Texture as Sprites

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
Bardor
Posts: 23
Joined: Wed Jan 16, 2008 9:51 pm
Location: Germany

Texture as Sprites

Post by Bardor »

Hi together,

is there an easy way to split a texture into smaller ones (just like sprites) ?

At the moment i'm using some code from the special FX tutorial to have an animated Effect from several textures.
This code loads a number (data.s_Frames) of single textures into an array an uses this to animate an effect.

To load a texture array from a single file im looking for a solution, to:
1. load a single texture
2. split this texture into an arry of (data.s_Frames) elements
(usuallay when this single texture contains 16 Frames they are 4x4 frames of the same size).

Code: Select all

 
        /*  
        Next we add a volumetric light node, which adds a glowing fake area light to
        the scene. Like with the billboards and particle systems we also assign a
        texture for the desired effect, though this time we'll use a texture animator
        to create the illusion of a magical glowing area effect.*/
    
        //*edit add an animated effect
        //*old scene::IVolumeLightSceneNode * n
        L_node = smgr_main->addVolumeLightSceneNode(0, -1,
                    32,                 // Subdivisions on U axis
                    32,                 // Subdivisions on V axis
                    data.sColor,        // foot color
                    data.eColor);       // tail color
 
        if (L_node)
        {
            L_node->setScale(data.Scale);
            L_node->setPosition(vector3df((pos.X*255.f), data.emitArea.Y, (pos.Y*-255.f)));
 
            // load textures for animation
            core::array<video::ITexture*> textures;
            for (s32 g=data.s_Frames; g > 0; --g)
            {
                core::stringc tmp;
                tmp = data.t_texture;
                tmp += g;
                tmp += ".png";
                video::ITexture* t = driver->getTexture( tmp.c_str() );
                driver->makeColorKeyTexture(t, core::position2d<s32>(1,1));
                textures.push_back(t);
            }
 
            // create texture animator
            scene::ISceneNodeAnimator* glow = smgr_main->createTextureAnimator(textures, 150);
            // add the animator
            L_node->addAnimator(glow);
            L_node->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
 
            // drop the animator because it was created with a create() function
            glow->drop();
 
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Texture as Sprites

Post by hybrid »

Yes, you can use the code from example 5 (2d rendering) or directly use the texture matrix, which can scale and transform matrices arbitrarily.
Bardor
Posts: 23
Joined: Wed Jan 16, 2008 9:51 pm
Location: Germany

Re: Texture as Sprites

Post by Bardor »

Thanks for your fast answer.

I looked at example 5 but i'm still not sure how to use this for my problem.
Example 5 is using a function to draw a 2d image manually, but i just want to use "smgr_main->createTextureAnimator(textures, 150)".

Can you help me with a short example of using a texture matrix ?
I don't know how to use them.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Texture as Sprites

Post by hybrid »

Well, you said 'like a sprite' and that will perfectly work as shown in example 5. Simply put these render functions into a function and it's well hidden. For texture matrix, you also have to update the values manually each time you want to change the texture portion you tke for rendering.
You can access the texture matrices in SMaterialLayer of the material you want to alter. There are matrix function for texture matrices in the matrix4 class. You have to scale the texture values (for a 4x4 texture atlas by factor 1/4) and set the translation properly in those functions. The mesh you render onto needs no further change, as long as it does not tile the texture.
Post Reply