Animated Texture Demo

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
Virion
Competition winner
Posts: 2148
Joined: Mon Dec 18, 2006 5:04 am

Animated Texture Demo

Post by Virion »

i realized that I didn't touch c++ for a long time (and almost forget everything)... so i playing around with it.

http://www.zerocore.net/demo.zip

I think we can also make animated particles? I will check it out soon.

p/s. i'm currently an art student so hardly got time for programming... damn i've forgotten most of the things about c++! :lol:

add:

Code: Select all

#include <irrlicht.h>
#include "main.h"

using namespace irr;

using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

u32 oldNow;
u32 time;
u32 now;
u32 elapsed;

int main()
{
    IrrlichtDevice *device = createDevice(EDT_OPENGL, dimension2d<s32>(512, 512), 32, false, false, false, 0);
    device->setWindowCaption(L"Irrlicht Animated Texture Demo");

    IVideoDriver* driver = device->getVideoDriver();
    ISceneManager* smgr = device->getSceneManager();
    IGUIEnvironment* guienv = device->getGUIEnvironment();

    oldNow = device->getTimer()->getRealTime();
    time = 0;

    int i = 1;
    ITexture* img[i];

    img[1] = driver->getTexture("beast1.jpg");
    img[2] = driver->getTexture("beast2.jpg");
    img[3] = driver->getTexture("beast3.jpg");
    img[4] = driver->getTexture("beast4.jpg");
    img[5] = driver->getTexture("beast5.jpg");

    IAnimatedMesh* mesh = smgr->getMesh("beast.b3d");
    IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh);
    node->setMaterialFlag(EMF_LIGHTING,false);
    node->setFrameLoop(1, 25);

    smgr->addCameraSceneNode(0, vector3df(100,100,-150), vector3df(0,5,0));

    while(device->run())
    {
        now = device->getTimer()->getRealTime();
        elapsed = now - oldNow;
        oldNow = now;
        time += elapsed;

        if (time<1000)
        {
            i = 1;
        }
        if (time>1000)
        {
            i = 2;
        }
        if (time>2000)
        {
            i = 3;
        }
        if (time>3000)
        {
            i = 4;
        }
        if (time>4000)
        {
            i = 5;
        }
        if (time>5000)
        {
            time = 0;
        }

        node->setMaterialTexture( 0,img[i]);


        driver->beginScene(true, true, SColor(255,100,101,140));

        smgr->drawAll();
        guienv->drawAll();
        driver->endScene();

    }
    device->drop();
    return 0;

}
Last edited by Virion on Sat Jul 19, 2008 10:36 pm, edited 3 times in total.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Thanks for sharing, but this might be better in Code Snippets than Project Announcements.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
grayman
Posts: 69
Joined: Thu May 12, 2005 10:48 am
Location: colombia

Post by grayman »

dude, ill really like to see the source, that could be useful to animate sprites! or play animations on planes, could you share the code ?
System

AMD X2 4200
nvidia 7600gs 256mb
2GB ram DDR2
Virion
Competition winner
Posts: 2148
Joined: Mon Dec 18, 2006 5:04 am

Post by Virion »

ok... maybe someone should move this thread to code snippet.

code added at the first post.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Sorry if I came across as negative; I'm sure this is great stuff.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Virion
Competition winner
Posts: 2148
Joined: Mon Dec 18, 2006 5:04 am

Post by Virion »

the code could be expanded further and enhanced by someone who has more experience in c++ than an art student. :wink:
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Virion wrote:the code could be expanded further and enhanced by someone who has more experience in c++ than an art student. :wink:
well, just a little enhancement so you can use any amount of textures you want to ;) :

Code: Select all

#include <irrlicht.h>
#include "main.h"

using namespace irr;

using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

u32 oldNow;
u32 time;
u32 now;
u32 elapsed;

int main(){
    IrrlichtDevice *device = createDevice(EDT_OPENGL, dimension2d<s32>(512, 512), 32, false, false, false, 0);
    device->setWindowCaption(L"Irrlicht Animated Texture Demo");

    IVideoDriver* driver = device->getVideoDriver();
    ISceneManager* smgr = device->getSceneManager();
    IGUIEnvironment* guienv = device->getGUIEnvironment();

    oldNow = device->getTimer()->getRealTime();
    time = 0;

    array<ITexture*> img;

    img.push_back(driver->getTexture("beast1.jpg"));
    img.push_back(driver->getTexture("beast2.jpg"));
    img.push_back(driver->getTexture("beast3.jpg"));
    img.push_back(driver->getTexture("beast4.jpg"));
    img.push_back(driver->getTexture("beast5.jpg"));
    // you can add as many textures as you want

    IAnimatedMesh* mesh = smgr->getMesh("beast.b3d");
    IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh);
    node->setMaterialFlag(EMF_LIGHTING,false);
    node->setFrameLoop(1, 25);

    smgr->addCameraSceneNode(0, vector3df(100,100,-150), vector3df(0,5,0));

    node->setMaterialTexture( 0,img[0]);
    u32 i = 1; // set to 1 because we already used texture at index 0

    while(device->run()){
        now = device->getTimer()->getRealTime();
        elapsed = now - oldNow;
        if(elapsed > 1000){
          node->setMaterialTexture( 0,img[i++]);
          i = i % img.size();
          oldNow = now;
        }

        driver->beginScene(true, true, SColor(255,100,101,140));

        smgr->drawAll();
        guienv->drawAll();
        driver->endScene();

    }
    device->drop();
    return 0;

}
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Surely you can already do this with the TextureAnimator.....
Image Image Image
Virion
Competition winner
Posts: 2148
Joined: Mon Dec 18, 2006 5:04 am

Post by Virion »

JP wrote:Surely you can already do this with the TextureAnimator.....
omg i didnt know that :oops: :oops: :oops:
henkten
Posts: 6
Joined: Fri Sep 26, 2008 9:20 pm

Thank you!

Post by henkten »

Thank you very much for that Virion, it's very helpful to me. It's just straight forward and gives you animated textures, not run around with NO instructions or directions for beginners like what many other people post. That was very generous of you.

I see JP said that there's a texture animator, but I've been searching and searching and I'm Finding NOTHING. I'm just fed up with that with Irrlicht, yeah I'm a newbie, but it's discouraging how hard it is to find info and how to implement certain mainstream stuff. I searched for animated textures in Ogre and found several straight forward directions to get it right away. Seriously, Irrlicht is harder than Orge. Thanks for this straight forward approach Virion. Irrlicht has much much less support than Ogre- and it's trumpeted as the simpler and more straight forward of the 2, gets me really annoyed at how lacking the support is!!! Could you more experienced guys help out the newbies in a little more straight forward way please. Post some links, leave some more hints so we could search for ourselves, not just dry half line answers that we can get nothing from, and only make sense to the experienced users. Thank you Virion.
Cloudef
Posts: 123
Joined: Wed Dec 03, 2008 9:02 pm
Location: Finland

Post by Cloudef »

The support is all about community, Irrlich community is well.. a bit quiet, but still i hope it grows itself as the Irrlicht Engine itself has been great finding to me.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

The texture animator is part of the Irrlicht SDK, its use is shown in the Demo, and the API docs contain all necessary stuff to learn about other use. Please learn to use the exsiting documentation and complain only about lack of it if there's really a lack!
Post Reply