How to integrate Irrlicht in a wxWidgets application

Posted on:August 08 2006

Especially since Irrlicht 1.1 and irrEdit 0.3 are released, I'm getting tons of mails asking how to integrate Irrlicht in an application written using wxWidgets, just like I did it with irrEdit. Here is a short howto:

There are two possibilities to display Irrlicht in wxWidgets.

A) Take a look at the 14th tutorial, I am showing how to use Irrlicht in a Win32 window there. This is done by creating the IrrlichtDevice with a parameter set to the HWND handle of the Win32 window. If you are using wxWidgets in Windows, you can get that HWND and simply set it. The method in wxWidgets for this is named GetHandle().

B) There is a second way which is a bit more difficult, and I am using it in irrEdit. It only works in Windows and only with the Software and Direct3D devices, and not with OpenGL, currently. The advantage of this method is that you can render into multiple windows with variable sizes, but only need one IrrlichtDevice. The method IVideoDriver::endScene() takes a windowId as parameter. Just set this to the window your want Irrlicht to render everything into (use GetHandle() again), and that's it.

Hope this helped a bit.





Comments:


Nice niko!
bicunisa
Quote
2006-08-08 19:54:00


The Complexity of it all proves that Niko is all-powerful... not really, but I am just to lazy to try.. ;-)
RustyNail
Quote
2006-08-08 20:51:00


Here is an expansion of the first method, which I am using that works in OpenGL :)

One problem with wxWidgets is it is a bit tricky to integrate. In Win32 the default window proc is not called in the message loop, so if you decide to update the display continuously you'll need a way to send messages to Irrlicht.

Unfortunately not all messages can be sent to irrlicht via the proc postEventFromUser, for example the resize event. One way to get around that is to manually add some methods to force resize in Irrlicht itself.

In order to use wxWidgets, you'll need to override the default message loop like this:

//overload this
int EditorApp::OnRun()
{
SetExitOnFrameDelete(true);

wxMainEventLoop eventLoop(this);
wxEventLoop::SetActive(&eventLoop);

m_mainLoop = &eventLoop;

for ( ; ; ) {

while (!Pending() && ProcessIdle());

while (Pending())
{
if (!Dispatch())
{
mShouldLeave = true;
break;
}
}

if (mShouldLeave)
{
while (Pending())
Dispatch();

m_mainLoop = NULL;
return 0;
}


if (mFrame)
mFrame->RenderFrame();

wxMilliSleep(10); // dont take up 100% of cpu as usual
}

m_mainLoop = NULL;
return 0;
}

Definition of new class:

namespace
{
class wxMainEventLoop : public wxEventLoop
{
public:

wxMainEventLoop(EditorApp *editorApp);
virtual void OnExit();

private:
EditorApp *mEditorApp;
};
}

add this:

namespace
{
wxMainEventLoop::wxMainEventLoop(EditorApp *editorApp) : wxEventLoop()
{
mEditorApp = editorApp;
}

void wxMainEventLoop::OnExit()
{
mEditorApp->SetShouldLeave(true);
}
};

good luck!
Matthew
Quote
2006-08-09 00:46:00


hehe,

und ich wundere Mich, warum nix ordentlcihes in Irrlicht gecodet wird.
Wenn die Leute es ncihtmal schaffen, ein Handle zu übergeben.
Vielleicht sind das alles Kinder.

cu
Jan_
Quote
2006-08-09 08:07:00


Hello Niko!

I have one quastion.Maybe is a noob quastion,but i don't know how i can load terrain in IrrEdit...

Here is the topic on forum:http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?t=14741

thank you for irrlicht.
Ros
Quote
2006-08-09 10:00:00


Hey Niko,

some time time ago i figured out that you render to multiple windows by passing the handle via endScene (as seen in your first alpha of 1.1 via SVN)...In principle in OpenGL this is possible too, and i implemented this already myself in 1.1. But, and thats the reason why i am posting here, in OGL one has to at least bind the GL render context to the corresponding device handle (HDC). And that has to be done *before* any drawing (e.g. via glxMakeCurrent under win32). I am just saying that this endScene thingy will never work for OGL when you want to render to some secondary output windows...As i understand this, glxMakeCurrent always flushs the render context (HRC).

I understand that your solution is the most compatible way in terms of a stable Irrlicht API. But i suspect a generic solution will need an API change by introducing an extra Method to pass the window handle. Would be still compatible in a way if this method is not used...*

Just to let you know...*
mrcdrc
Quote
2006-08-09 12:56:00


Hey Niko,

Great work on the lightmapper! I'm amazed at how awesome it looks. No more need for Dele D for me :)

I am here to make a feature request: May you please add simple terrain display functionality into irrEdit as soon as possible? This would greatly help out any project using irrlicht that requires outdoor rendering of any type. .

I have started a thread and there seems to be a collective need for terrain in order for projects such as mine to be able to use irrEdit efficiently.
http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?t=15273

Please consider my request (and that of many others).

Thankyou very much,
Krama
Krama
Quote
2006-08-31 08:16:00


Add comment:


Posted by:


Enter the missing letter in: "Internation?l"


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons