(no bug) Prob. when IRRlicht is used with wxWidget
-
- Posts: 1638
- Joined: Mon Apr 30, 2007 3:24 am
- Location: Montreal, CANADA
- Contact:
(no bug) Prob. when IRRlicht is used with wxWidget
Hi, I think thoses problems could affect Irrlicht response and perhaps could NOT be bugs, I'm just asking because I've had weird behaviors coming from the IRRlicht window. This as all been experimented with Irrlicht 1.7.2 and MSVC on Windows Vista.
I was able to use IRRlicht inside a WxWidget application. wxWidget recommend that we use their "event loop" and refresh our application.
I tried to use their recommendation when I started implementing wxWidget for the IRR Rpg Builder project:
http://irrrpgbuilder.sourceforge.net/fo ... p=291#p291
-- When wxWidget drive the main loop:
Using their recommendation, the main loop is done inside WxWidget and I'm intercepting events and forwarding them to IRRlicht (mouse and keyboard events), Irrlicht is refreshed by a timer event.
But I had this problems: (my biggest problem so far)
- animated meshes don't animate, they only move to their first frame. (they still move on the screen but their animation is not playing)
- The Irrlicht scroller GUI is working but the slider GUI element is not receiving the mouse events and is not working, but the button arrows are still functionnal.
Theses problems are related to how IRRlicht received the events from wxWidget and "might" not be bugs. (If someone have an idea how to set the events to be received properly by IRRlicht it would be great)
- I had weird issues with the way the keyboard event were received by IRRlicht, all the letters are received as capital letters. (perhaps I need to process them further before sending them to IRRlicht?)
- Mouse events seem to work, but a combined mouse+keyboard event is not received properly (keyboard event is not received)
--When IRRlicht is using it's own game loop and "refresh" wxWidget:
I found out by some tests that IRRlicht seem to work properly, if instead I run the application in a game loop (inside IRRlicht). It look like IRRlicht magically is getting the proper events, the animations plays, the GUI slider is working also. I checked further by disabling the forwarding of events from wxWidget and IRRlicht was still receiving mouse and keyboard events...
Look like IRRlicht for some reasons is connecting directly to the OS? I don't know, but it work better, and I've set up the application this way. To have wxWidget receive events for it's own GUI, I've added the wxYield() inside my Irrlicht game loop. The only problem is that is considered "bad" by wxWidget.
-- Other problems caused when IRRlicht is used in a window:
There is also one problem when IRRlicht is used inside wxWidget (could also be inside a window application or other types I suppose)
- The returned device screen size is wrong. It should return the window size IRRlicht is placed.
And caused thoses problems:
- IRRlicht GUI positions based on the screen are placed incorrectly
- IRRlicht GUI that are trying to use "absolute" clipping rectangle position are returning wrong values. (I found out that using the "clientrect" seem to return a more coherent value.
- IRRlicht cameras don't have the proper aspect ratio (I think its because of the wrong information about the display size)
I was able to use IRRlicht inside a WxWidget application. wxWidget recommend that we use their "event loop" and refresh our application.
I tried to use their recommendation when I started implementing wxWidget for the IRR Rpg Builder project:
http://irrrpgbuilder.sourceforge.net/fo ... p=291#p291
-- When wxWidget drive the main loop:
Using their recommendation, the main loop is done inside WxWidget and I'm intercepting events and forwarding them to IRRlicht (mouse and keyboard events), Irrlicht is refreshed by a timer event.
But I had this problems: (my biggest problem so far)
- animated meshes don't animate, they only move to their first frame. (they still move on the screen but their animation is not playing)
- The Irrlicht scroller GUI is working but the slider GUI element is not receiving the mouse events and is not working, but the button arrows are still functionnal.
Theses problems are related to how IRRlicht received the events from wxWidget and "might" not be bugs. (If someone have an idea how to set the events to be received properly by IRRlicht it would be great)
- I had weird issues with the way the keyboard event were received by IRRlicht, all the letters are received as capital letters. (perhaps I need to process them further before sending them to IRRlicht?)
- Mouse events seem to work, but a combined mouse+keyboard event is not received properly (keyboard event is not received)
--When IRRlicht is using it's own game loop and "refresh" wxWidget:
I found out by some tests that IRRlicht seem to work properly, if instead I run the application in a game loop (inside IRRlicht). It look like IRRlicht magically is getting the proper events, the animations plays, the GUI slider is working also. I checked further by disabling the forwarding of events from wxWidget and IRRlicht was still receiving mouse and keyboard events...
Look like IRRlicht for some reasons is connecting directly to the OS? I don't know, but it work better, and I've set up the application this way. To have wxWidget receive events for it's own GUI, I've added the wxYield() inside my Irrlicht game loop. The only problem is that is considered "bad" by wxWidget.
-- Other problems caused when IRRlicht is used in a window:
There is also one problem when IRRlicht is used inside wxWidget (could also be inside a window application or other types I suppose)
- The returned device screen size is wrong. It should return the window size IRRlicht is placed.
And caused thoses problems:
- IRRlicht GUI positions based on the screen are placed incorrectly
- IRRlicht GUI that are trying to use "absolute" clipping rectangle position are returning wrong values. (I found out that using the "clientrect" seem to return a more coherent value.
- IRRlicht cameras don't have the proper aspect ratio (I think its because of the wrong information about the display size)
Last edited by christianclavet on Thu Mar 31, 2011 5:14 pm, edited 1 time in total.
You must add a tick call, just before beginScene:- animated meshes don't animate, they only move to their first frame.
Code: Select all
GetIrrDevice()->getTimer()->tick();
Add this:- IRRlicht cameras don't have the proper aspect ratio (I think its because of the wrong information about the display size)
Code: Select all
void CIrrWindow::OnSize(wxSizeEvent &event)
{
float w=GetClientSize().GetWidth();
float h=GetClientSize().GetHeight();
fRatio = (float)w/(float)h;
if ( irrWrapperDevice )
{
irr::video::IVideoDriver *driver=irrWrapperDevice->GetVideoDriver();
if ( driver )
{
const core::dimension2d<irr::u32> dim(w, h);
driver->OnResize( dim );
if ( irrCameraCurrent )
irrCameraCurrent->setAspectRatio( fRatio );
if ( !m_Timer.IsRunning() )
Update();
}
}
event.Skip();
}
I hope this helps.
-
- Posts: 1638
- Joined: Mon Apr 30, 2007 3:24 am
- Location: Montreal, CANADA
- Contact:
Thanks TCM! I did not know about the "tick"! Great! I will keep what I've done for the "main" window of the application, but for other tools using 3D windows, this will be very helpful! Do you think that could solve the event problem?
Cool! For the camera, my solution is almost the same in code as yours!
For the display size, I checked more why the display was distorted and the device size at initialisation (When I define all the "ingame" IRRlicht guis) is 20x20. I fixed it by defining my "own" size at initialisation.
Once initialised the display size report ok. (I think wxWidget init IRRlicht in 20,20 then stretche it to match the window after being initialised)
serengeor, I'm developping the windows version for IRR RPG Builder, but Andres (the originator of the project) will port the windows version to Linux when he have the time. Check the forum when he does.
Meanwhile, have you tried to use a wxWidget demo project and added Irrlicht to it for testing? There is a lot of libraries to add to the project to start a wxProject. The place I had the most trouble was to give IRRlicht the proper window handle.
I've found a code that initialize Irrlicht inside Linux, but I've not tested it (Im using windows only) Perhaps you could check and try it (Check the LINUX define condition in this code):
If someone have the time and skills on Linux, having defines like that in the Example14 (Win32Window), that could open a window on Linux would be really nice...
Cool! For the camera, my solution is almost the same in code as yours!
For the display size, I checked more why the display was distorted and the device size at initialisation (When I define all the "ingame" IRRlicht guis) is 20x20. I fixed it by defining my "own" size at initialisation.
Once initialised the display size report ok. (I think wxWidget init IRRlicht in 20,20 then stretche it to match the window after being initialised)
serengeor, I'm developping the windows version for IRR RPG Builder, but Andres (the originator of the project) will port the windows version to Linux when he have the time. Check the forum when he does.
Meanwhile, have you tried to use a wxWidget demo project and added Irrlicht to it for testing? There is a lot of libraries to add to the project to start a wxProject. The place I had the most trouble was to give IRRlicht the proper window handle.
I've found a code that initialize Irrlicht inside Linux, but I've not tested it (Im using windows only) Perhaps you could check and try it (Check the LINUX define condition in this code):
If someone have the time and skills on Linux, having defines like that in the Example14 (Win32Window), that could open a window on Linux would be really nice...
Code: Select all
void wxIrrlicht::InitIrr(irr::SIrrlichtCreationParameters* init_params) {
SIrrlichtCreationParameters params;
params.DriverType = EDT_OPENGL;
SIrrlichtCreationParameters* actual_params = init_params ? init_params : ¶ms;
dimension2d<s32> irrSize(GetClientSize().GetX(), GetClientSize().GetY());
actual_params->WindowSize = irrSize;
#ifdef LINUX
wxStaticText* pnl = new wxStaticText(this, -1, wxEmptyString);
pnl->SetBackgroundStyle(wxBG_STYLE_CUSTOM);
GtkWidget* handle = pnl->GetHandle();
if (!handle)
return;
XID xHandle = GDK_WINDOW_XWINDOW(handle->window);
Display* mDisp = GDK_WINDOW_XDISPLAY(handle->window);
stringc dName = (long)mDisp;
dName += ':';
dName += (int)xHandle;
actual_params->WindowId = (long)dName.c_str();
#else
actual_params->WindowId = reinterpret_cast<void *>(pnl->GetHandle());
#endif
m_pDevice = createDeviceEx(*actual_params);
if (!m_pDevice) {
throw "Can't create Irrlicht device!";
}//if
m_pDriver = m_pDevice->getVideoDriver();
m_pSceneManager = m_pDevice->getSceneManager();
m_pGuiEnvironment = m_pDevice->getGUIEnvironment();
OnCreateScene();
m_pDriver->OnResize(irrSize);
}//InitIrr()
Yeah, this should be made for all major OS's, not just M$.If someone have the time and skills on Linux, having defines like that in the Example14 (Win32Window), that could open a window on Linux would be really nice...
Working on game: Marrbles (Currently stopped).
I am not sure what wxWidget is your irrLicht window. Is it a wxControl or a wxWindow? You must make sure that the control or window in which you have the irrlicht 3d window is having the focus. Otherwise it simply does not receive the messages, since it does not have the focus. You can give it the focus this way:
where this is the control (or window) handle.
Also, you can also handle the messages in the main wxWindows class.
I also had problems with the main irrlicht handle . To create the wxWindow you need the irrlicht handle, and to create the irrlicht window, you need the handle to the window. I tried several ways, i still get a memory leak. Do you experience something similar, or you managed to get it working fine?
Code: Select all
this->SetFocus();
Also, you can also handle the messages in the main wxWindows class.
I also had problems with the main irrlicht handle . To create the wxWindow you need the irrlicht handle, and to create the irrlicht window, you need the handle to the window. I tried several ways, i still get a memory leak. Do you experience something similar, or you managed to get it working fine?
-
- Posts: 1638
- Joined: Mon Apr 30, 2007 3:24 am
- Location: Montreal, CANADA
- Contact:
HI, TCM.
I confirm the memory leak, Each time I close the application I get MSVC complaining about a memory leak. I build the editor with defines (wxWidget) or plain IRRlicht. There is no report of any leak for the plain Irrlicht version. So I assume it's related on how wxWidget close the application. (As you mentionned it seem that it doesnt want to let go Irrlicht ressources).
If someone find a solution for this let us know..
I confirm the memory leak, Each time I close the application I get MSVC complaining about a memory leak. I build the editor with defines (wxWidget) or plain IRRlicht. There is no report of any leak for the plain Irrlicht version. So I assume it's related on how wxWidget close the application. (As you mentionned it seem that it doesnt want to let go Irrlicht ressources).
If someone find a solution for this let us know..
Re: (no bug) Prob. when IRRlicht is used with wxWidget
What is the size of the wxwidgets related libraries once included ?
-
- Posts: 1638
- Joined: Mon Apr 30, 2007 3:24 am
- Location: Montreal, CANADA
- Contact:
Re: (no bug) Prob. when IRRlicht is used with wxWidget
Hi, It depend on the libraries your need to use with wxWidget as it separated in several libraries. For what I needed on IRB the .lib files goes over 30 megabytes...
The final compiled application is about 3 megabytes (wxWidget libs are build as static libraries on my project). I should have updated the thread, I fixed the leak but was done so long ago that I don't remember what I've done! The thing I understand now is that Irrlicht must be go into the wxWidget loop. Doing the game loop inside Irrlicht will cut of most of the events.
The final compiled application is about 3 megabytes (wxWidget libs are build as static libraries on my project). I should have updated the thread, I fixed the leak but was done so long ago that I don't remember what I've done! The thing I understand now is that Irrlicht must be go into the wxWidget loop. Doing the game loop inside Irrlicht will cut of most of the events.
Re: (no bug) Prob. when IRRlicht is used with wxWidget
Hi,
I asked wxWidgets libs size to compare with Qt libs once included in project.
For me including Qt (similar to wx for some aspects) is the same : 34 Mb.
Same with Qt , irrlicht loop inside Qt loop ..
I asked wxWidgets libs size to compare with Qt libs once included in project.
For me including Qt (similar to wx for some aspects) is the same : 34 Mb.
Same with Qt , irrlicht loop inside Qt loop ..