SFML community forums

Help => Graphics => Topic started by: theodor on March 22, 2013, 12:29:52 pm

Title: SFML Window + Irrlicht rendering animation problems
Post by: theodor on March 22, 2013, 12:29:52 pm
Hey,

Here I am, once again in my journey to combine 2D and 3D api's.

The following is the minimal code I use to draw an animated model in the SFML window:
Code: [Select]
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <irrlicht.h>

//#include <GL/glu.h>
#include <iostream>
#include <math.h>
#define M_PI           3.14159265358979323846

////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////

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

int main()
{
    // Create the main rendering window
    sf::ContextSettings settings;
    settings.depthBits = 16;
    settings.stencilBits = 8;
    settings.antialiasingLevel = 8;
    settings.majorVersion = 3;
    settings.minorVersion = 0;

    sf::RenderWindow App(sf::VideoMode(800, 600), "OpenGL", sf::Style::Default, settings);

    IrrlichtDevice* device;
    SIrrlichtCreationParameters Parameters;
    Parameters.DriverType = video::EDT_OPENGL;
    Parameters.Bits = 16;
    Parameters.Fullscreen = false;
    Parameters.Stencilbuffer = true;
    Parameters.Vsync = true;
    Parameters.AntiAlias = true;
    Parameters.HighPrecisionFPU = false;
    Parameters.WindowId = App.getSystemHandle();
    device = createDeviceEx(Parameters);

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

IAnimatedMesh* mesh = smgr->getMesh("sydney.md2");
if (!mesh)
{
device->drop();
return 1;
}
IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );

if (node)
{
node->setMaterialFlag(EMF_LIGHTING, false);
node->setMD2Animation(scene::EMAT_STAND);
node->setMaterialTexture( 0, driver->getTexture("sydney.bmp") );
}

    smgr->addCameraSceneNode(0, vector3df(0,30,-60), vector3df(0,5,0));
    //App.setVerticalSyncEnabled(true);

    bool running = true;
    while (running == true)
    {
        // Process events
        sf::Event Event;

        while (App.pollEvent(Event))
        {
            // Close window : exit
            if (Event.type == sf::Event::Closed)
            {
                running = false;
            }
            else if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::Escape))
            {
                running = false;
            }
            else if (Event.type == sf::Event::Resized)
            {
                // adjust the viewport when the window is resized
                //glViewport(0, 0, Event.size.width, Event.size.height);
            }

        }

          driver->beginScene(true, true, SColor(255,0,0,255));
          //App.display();
       smgr->drawAll();
      guienv->drawAll();
    driver->endScene();
    }
    device->drop();
    return EXIT_SUCCESS;
}

The result is just a non-moving model.
This irrlicht example (hello world), works fine(removed comments to save space):

Code: [Select]
#include <irrlicht.h>

using namespace irr;

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

#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif


/*
This is the main method. We can now use main() on every platform.
*/
int main()
{
IrrlichtDevice *device =
createDevice( video::EDT_OPENGL, dimension2d<u32>(640, 480), 16,
false, false, false, 0);

if (!device)
return 1;

device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");

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

guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!",
rect<s32>(10,10,260,22), true);

IAnimatedMesh* mesh = smgr->getMesh("../../media/sydney.md2");
if (!mesh)
{
device->drop();
return 1;
}
IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );

if (node)
{
node->setMaterialFlag(EMF_LIGHTING, false);
node->setMD2Animation(scene::EMAT_STAND);
node->setMaterialTexture( 0, driver->getTexture("../../media/sydney.bmp") );
}

smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));

while(device->run())
{

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

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

driver->endScene();
}

device->drop();

return 0;
}

So the problem is that the model doesn't animate.

If I use raw opengl and draw a rotating cube in the SFML and Irrlicht combination, the cube shows, but completely black and missing one side (square) [yes it, rotates fine]

My program with the raw opengl rotating cube in the background and sfml animated sprites worked fine without irrlicht. Just using irrlicht with sfml window(without 3D rendering on it's part) resulted in sprites not showing and the cube missing one side and being black.

That is just extra information and is subject to a further topic though.

I simplified everything and right now I would like feedback on why the mesh isn't animating in the sfml window. What am I missing? (Probably some fundamental knowledge)

Cheers,
Theo

Title: Re: SFML Window + Irrlicht rendering animation problems
Post by: theodor on March 28, 2013, 09:58:28 am
bump
Title: Re: SFML Window + Irrlicht rendering animation problems
Post by: Laurent on March 28, 2013, 10:40:09 am
Why the hell do people always try to combine SFML with 3D engines? What does SFML provide that Irrlicht doesn't have?
Title: Re: SFML Window + Irrlicht rendering animation problems
Post by: binary1248 on March 28, 2013, 09:28:30 pm
Why the hell do people always try to combine SFML with 3D engines? What does SFML provide that Irrlicht doesn't have?
You should rather ask what Irrlicht has that SFML doesn't.

3D.

And to answer your first question: Because from my experience, most 3D engines are horrible to work with and people think they can get the best of both worlds by throwing 3D engine X and SFML in a blender and getting a 3D engine that is as easy to use as SFML :)

Be happy nobody tried to use DirectX with SFML yet ;)
Title: Re: SFML Window + Irrlicht rendering animation problems
Post by: Nexus on March 29, 2013, 01:06:26 pm
What does SFML provide that Irrlicht doesn't have?
A simple and powerful 2D API.

2D graphics are very limited in Irrlicht. There is only a bunch of functions for immediate drawing (see tutorial (http://irrlicht.sourceforge.net/docu/example006.html)). A lot of basic features like image rotation are not available.

It would also be interesting to combine SFML with Irrlicht in order to use extensions like SFGUI. From my first impressions, SFGUI is much better designed than other GUI toolkits like CEGUI (standalone new calls :o).
Title: Re: SFML Window + Irrlicht rendering animation problems
Post by: theodor on March 30, 2013, 11:13:43 am
Looks like I don't even have to explain myself. People know why :)

Will I get an explanation why my code doesn't work as intended, or should I just scrap everything I wrote with sfml and try to rewrite everything using irrlicht?

I really like sfml so I do not want to abandon it.
Title: Re: SFML Window + Irrlicht rendering animation problems
Post by: theodor on April 08, 2013, 10:49:13 am
bump
Title: Re: SFML Window + Irrlicht rendering animation problems
Post by: zsbzsb on April 08, 2013, 03:43:24 pm
I will say most people here do not use 3d engines with SFML and that is why no one is trying to help so please do not get mad at us ;)

I personally have never done anything like this so its a guess in the dark, maybe try surrounding your 3d engine drawing code with a glPush and glPop states.
Title: Re: SFML Window + Irrlicht rendering animation problems
Post by: theodor on April 09, 2013, 02:28:41 pm
No worries, mate.

If I can't get help, I suppose I'll have to do some more searching and experimenting. I will perhaps have to see what SDL has to offer even though I dislike it.

Thank you.

Cheers,
Theo
Title: Re: SFML Window + Irrlicht rendering animation problems
Post by: Laurent on April 09, 2013, 02:40:10 pm
I still don't get it, because if you're able to do 3D with an API, you can for sure do 2D with the same API: use an orthgraphic projection matrix and draw textured quads. It's almost as easy as working with the sf::Sprite class (look at its source code: it's a ridiculously thin wrapper around OpenGL code).
Title: Re: SFML Window + Irrlicht rendering animation problems
Post by: theodor on April 10, 2013, 12:41:23 pm
I'll look at the source code, hopefully I am knowledgeable enough to somehow integrate it with Irrlicht without changing the sfml code I already have.

The reason why I am so stubborn is because I like those wrappers(thin or not), which hide the hideous code from me and in turn simplify everything. So for me, it would be ideal to be able to use SFML for 2D and Irrlicht for 3D.

Theo
Title: Re: SFML Window + Irrlicht rendering animation problems
Post by: Laurent on April 10, 2013, 01:35:02 pm
I just checked, and Irrlicht has functions for drawing 2D sprites, text and shapes. It seems as easy as with SFML. So... ???