How to embed graphics engine (eg., Irrlicht) into wx?

Are you writing your own components and need help with how to set them up or have questions about the components you are deriving from ? Ask them here.
Post Reply
kornerr
Experienced Solver
Experienced Solver
Posts: 66
Joined: Wed Oct 12, 2005 2:43 pm
Location: Russia
Contact:

How to embed graphics engine (eg., Irrlicht) into wx?

Post by kornerr » Wed Aug 30, 2006 12:47 pm

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.
Open Source all the way, baby ;)
OpenGameStudio
Image

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE » Wed Aug 30, 2006 1:04 pm

Hi!
Although I didn't try it or even havin ever worked with Irrlicht, I found this
irr::SIrrlichtCreationParameters::WindowId
in the docs.
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
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().
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

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE » Wed Aug 30, 2006 1:08 pm

BTW: This seems to be more or less this way of doing it ->
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

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE » Wed Aug 30, 2006 1:49 pm

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

kornerr
Experienced Solver
Experienced Solver
Posts: 66
Joined: Wed Oct 12, 2005 2:43 pm
Location: Russia
Contact:

Post by kornerr » Wed Aug 30, 2006 2:09 pm

Can you, please, show me the code? :P
Open Source all the way, baby ;)
OpenGameStudio
Image

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE » Wed Aug 30, 2006 2:14 pm

Here's the code for my wxPanel.

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()
};
IrrlichtScene.cpp

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();
}
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 :)
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

kornerr
Experienced Solver
Experienced Solver
Posts: 66
Joined: Wed Oct 12, 2005 2:43 pm
Location: Russia
Contact:

Post by kornerr » Sun Sep 24, 2006 5:07 am

Unfortunately, it doesn't work under Linux.
Anyone tried that under Linux (and is able to show full workable code)?
Thanks.
Open Source all the way, baby ;)
OpenGameStudio
Image

kornerr
Experienced Solver
Experienced Solver
Posts: 66
Joined: Wed Oct 12, 2005 2:43 pm
Location: Russia
Contact:

Post by kornerr » Sun Sep 24, 2006 5:37 am

Well, may be anyone can tell me HOW is embedding work in wx(GTK)? I mean, what should be accomplished in order to make smth external work inside wx(GTK)?
Thanks.
Open Source all the way, baby ;)
OpenGameStudio
Image

mispunt
Experienced Solver
Experienced Solver
Posts: 59
Joined: Tue Oct 19, 2004 3:23 pm
Location: Ede, Holland

Post by mispunt » Sun Sep 24, 2006 9:39 am

Did you change the driver type? The code of upCASE is using video::EDT_DIRECT3D9, but you should use the OPENGL thing (look in the documentation of Irrlicht...)
OS: win XP pro
Compiler: MingW
wxWidgets version: 2.6.2

kornerr
Experienced Solver
Experienced Solver
Posts: 66
Joined: Wed Oct 12, 2005 2:43 pm
Location: Russia
Contact:

Post by kornerr » Sun Sep 24, 2006 11:10 am

Of course =)
Irrlicht's doc don't say anything about wxGTK :(
Open Source all the way, baby ;)
OpenGameStudio
Image

yablebab
Earned a small fee
Earned a small fee
Posts: 12
Joined: Thu Sep 21, 2006 6:48 pm

the answer to all your problems

Post by yablebab » Tue Sep 26, 2006 9:28 pm

check it out:

http://irrlicht.sourceforge.net/phpBB2/ ... =wxwidgets

this works beautifully

=)

kornerr
Experienced Solver
Experienced Solver
Posts: 66
Joined: Wed Oct 12, 2005 2:43 pm
Location: Russia
Contact:

Post by kornerr » Wed Sep 27, 2006 4:31 am

I saw it already. It doesn't work for me.
Can you provide a workable demo which will work with wxGTK (under Linux, I mean).
Thanks.
Open Source all the way, baby ;)
OpenGameStudio
Image

Post Reply