How to embed graphics engine (eg., Irrlicht) into wx?
How to embed graphics engine (eg., Irrlicht) into wx?
I'm using Irrlicht. And I want to create a map editor. But I don't know how to embed Irrlicht into wxWidgets. Any clues?
Thanks.
Thanks.
Hi!
Although I didn't try it or even havin ever worked with Irrlicht, I found this
irr::SIrrlichtCreationParameters::WindowId
in the docs.
Use createDeviceEx() to create Irrlicht.
Although I didn't try it or even havin ever worked with Irrlicht, I found this
irr::SIrrlichtCreationParameters::WindowId
in the docs.
So I suppose it might work if you create the GUI and wxApp as usual and tell Irrlicht to use one of your wxWindows (like a wxPanel). I'm not really sure what Itllicht would expect on other platforms, but you can get the HWND of a wxWindow with wxWindow::GetHandle().If this is set to a value other than 0, the Irrlicht Engine will be created in an already existing window. For windows, set this to the HWND of the window you want
Use createDeviceEx() to create Irrlicht.
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4
"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4
"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda
BTW: This seems to be more or less this way of doing it ->
http://irrlicht.sourceforge.net/tut014.html
http://irrlicht.sourceforge.net/tut014.html
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4
"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4
"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda
A small update: I just tried it and it works charming. The problem to solve was where to call IrrlichtDevice::run(). I therefor created a derived wxPanel that would be use as the window for Irrlicht and implemented a OnIdle event handler and called it from there. After doing all needed drawing I simply call wxIdleEvent::RequestMore() to keep it "running".
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4
"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4
"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda
Here's the code for my wxPanel.
IrrlichScene.h
IrrlichtScene.cpp
This shows the same animantion as the sample in the tutorial I mentioned. Note that I never worked with Irrlicht before and thus there may be errors in my code. Still, it works charming for me and even changing the renderer works.
There is one thing though: I had to pass the wxPanel size so that the window size is set before the scene is created. If the window resizes you'll have to tell Irrlicht about that. Simply put: I didn't know how to do this
IrrlichScene.h
Code: Select all
#include <wx/wx.h>
#include <irrlicht.h>
using namespace irr;
class IrrlichtScene :
public wxPanel
{
irr::IrrlichtDevice* device;
irr::scene::ISceneManager* smgr;
video::IVideoDriver* driver;
public:
IrrlichtScene(wxWindow* parent,wxSize s);
~IrrlichtScene(void);
void OnIdle(wxIdleEvent& e);
DECLARE_EVENT_TABLE()
};
Code: Select all
#include "IrrlichtScene.h"
BEGIN_EVENT_TABLE(IrrlichtScene, wxPanel)
EVT_IDLE(IrrlichtScene::OnIdle)
END_EVENT_TABLE()
IrrlichtScene::IrrlichtScene(wxWindow* parent,wxSize s)
:wxPanel(parent,-1,wxDefaultPosition,s)
{
irr::SIrrlichtCreationParameters param;
param.WindowId = (irr::s32)(HWND)this->GetHandle();
param.DriverType = video::EDT_DIRECT3D9 ;
device = irr::createDeviceEx(param);
smgr = device->getSceneManager();
driver = device->getVideoDriver();
scene::ICameraSceneNode* cam = smgr->addCameraSceneNode();
cam->setTarget(core::vector3df(0,0,0));
scene::ISceneNodeAnimator* anim =
smgr->createFlyCircleAnimator(core::vector3df(0,10,0), 30.0f);
cam->addAnimator(anim);
anim->drop();
scene::ISceneNode* cube = smgr->addCubeSceneNode(25);
cube->setMaterialFlag(video::EMF_LIGHTING, false);
cube->setMaterialTexture(0, driver->getTexture("media/rockwall.bmp"));
smgr->addSkyBoxSceneNode(
driver->getTexture("media/irrlicht2_up.jpg"),
driver->getTexture("media/irrlicht2_dn.jpg"),
driver->getTexture("media/irrlicht2_lf.jpg"),
driver->getTexture("media/irrlicht2_rt.jpg"),
driver->getTexture("media/irrlicht2_ft.jpg"),
driver->getTexture("media/irrlicht2_bk.jpg"));
}
void IrrlichtScene::OnIdle(wxIdleEvent& e)
{
device->run();
driver->beginScene(true, true, 0);
smgr->drawAll();
driver->endScene();
e.RequestMore();
}
There is one thing though: I had to pass the wxPanel size so that the window size is set before the scene is created. If the window resizes you'll have to tell Irrlicht about that. Simply put: I didn't know how to do this

OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4
"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4
"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda