i am trying to create more devices. ViewPorts are not enough for me, i need to project more different scenes. Is it possible?
I am using createDeviceEx for open device in win32 window (or more precisely wxWidgets::wxFrame). It seems, that only last created device/window is functional, and the others dont respond to my calls. Every irr-call is protected by mutex. Do i something wrong?
Here is my code based on wxIrrlicht (http://wxforum.shadonet.com/viewtopic.php?t=17090)
--- Display.h ---
Code: Select all
class Display: public wxControl {
DECLARE_EVENT_TABLE();
protected:
void OnPaint(wxPaintEvent& event);
void OnSize(wxSizeEvent& event);
void OnEraseBackground(wxEraseEvent& event) {}
void OnTimer(wxTimerEvent& event);
void OnMouse(wxMouseEvent& event);
void OnKey(wxKeyEvent& event);
IrrlichtDevice* device;
video::IVideoDriver* driver;
scene::ISceneManager* smgr;
scene::ICameraSceneNode* camera;
scene::ILightSceneNode* light;
wxTimer timerRender;
bool renderingActive;
static wxMutex mutexIrr;
public:
Display(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxTAB_TRAVERSAL, const wxString& name = wxPanelNameStr);
virtual ~Display();
void InitIrr();
void StartRendering();
void StopRendering();
void Render();
IrrlichtDevice* GetDevice() const { return device; }
video::IVideoDriver* GetVideoDriver() const { return driver; }
scene::ISceneManager* GetSceneManager() const { return smgr; }
};
Code: Select all
wxMutex Display::mutexIrr;
BEGIN_EVENT_TABLE(Display, wxControl)
EVT_TIMER(TIMER_RENDER_ID, Display::OnTimer)
EVT_SIZE(Display::OnSize)
EVT_PAINT(Display::OnPaint)
EVT_ERASE_BACKGROUND(Display::OnEraseBackground)
EVT_MOUSE_EVENTS(Display::OnMouse)
EVT_KEY_DOWN(Display::OnKey)
EVT_KEY_UP(Display::OnKey)
END_EVENT_TABLE()
Display::Display(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name)
: wxControl(parent, id, pos, size, style, wxDefaultValidator, name),
device(0),
driver(0),
smgr(0),
camera(0),
timerRender(this, TIMER_RENDER_ID) {
InitIrr();
SetBackgroundStyle(wxBG_STYLE_CUSTOM);
StartRendering();
}
Display::~Display() {
mutexIrr.Lock();
device->drop();
mutexIrr.Unlock();
}
void Display::InitIrr() {
mutexIrr.Lock();
core::dimension2d<s32> irrSize(GetClientSize().GetX(), GetClientSize().GetY());
SIrrlichtCreationParameters params;
params.DriverType = video::EDT_OPENGL;
params.WindowSize = irrSize;
params.WindowId = this->GetHandle();
device = createDeviceEx(params);
if (device == NULL)
throw BasicException("Display::InitIrr - Cannot create irrlicht device.");
driver = device->getVideoDriver();
smgr = device->getSceneManager();
driver->OnResize(irrSize);
mutexIrr.Unlock();
}
void Display::StartRendering() {
renderingActive = true;
timerRender.Start(TIMER_RENDER_PERIOD, true);
}
void Display::StopRendering(){
renderingActive = false;
timerRender.Stop();
}
void Display::Render() {
mutexIrr.Lock();
if(!device->run()) {
mutexIrr.Unlock();
return;
}
driver->beginScene(true, true, video::SColor(0,0,0,0));
smgr->drawAll();
driver->endScene();
mutexIrr.Unlock();
}
void Display::OnPaint(wxPaintEvent& event){
wxPaintDC paint_dc(this);
Render();
}
void Display::OnSize(wxSizeEvent& event) {
mutexIrr.Lock();
s32 w;
s32 h;
GetClientSize(&w, &h);
core::dimension2d<s32> size(w, h);
driver->OnResize(size);
if (camera) {
camera->setAspectRatio((float)w / (float)h);
}
mutexIrr.Unlock();
Render();
}
void Display::OnTimer(wxTimerEvent& event) {
Render();
if(renderingActive)
timerRender.Start(TIMER_RENDER_PERIOD, true);
}
// ... OnMouse and OnKey are not interesting ...
Thanks for your responses...