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:
////////////////////////////////////////////////////////////
// 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):
#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