Results 1 to 9 of 9

Thread: Irrlicht in qt

  1. #1
    Join Date
    Jul 2012
    Posts
    5
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Irrlicht in qt

    does anyone know if you can port irrlicht engine to qt so it would be cross platfrom

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Irrlicht in qt

    Irrlicht is already cross-platform C++.

  3. #3
    Join Date
    Jul 2012
    Posts
    5
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Irrlicht in qt

    So how do you get it working with qt

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Irrlicht in qt

    Compile Irrlicht and link it to your application. This is only related to Qt if you use qmake to build your project (See Declaring Other Libraries), otherwise it is between you and your C++ compiler.

  5. #5
    Join Date
    Jul 2012
    Posts
    5
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Irrlicht in qt

    Does it need to be compile into lib to be cross platform

  6. #6
    Join Date
    Oct 2016
    Location
    Duckburg, Calisota
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Irrlicht in qt

    This class creates a Qt widget with Irrlicht:

    Qt Code:
    1. #include <QWidget>
    2. #include <QTimer>
    3. #include <QKeyEvent>
    4. #include <irrlicht.h>
    5.  
    6. class IrrlichtWidget : public QWidget{
    7. Q_OBJECT
    8.  
    9. public:
    10. IrrlichtWidget(irr::u32 width = 600, irr::u32 height = 400){
    11. setFixedSize(width, height);
    12.  
    13. irr::SIrrlichtCreationParameters params;
    14. params.DriverType = irr::video::EDT_OPENGL;
    15. params.WindowId = (void*)winId();
    16. params.WindowSize.Width = width;
    17. params.WindowSize.Height = height;
    18. m_device = irr::createDeviceEx(params);
    19.  
    20. setAttribute(Qt::WA_OpaquePaintEvent);
    21.  
    22. m_timer = new QTimer;
    23. m_timer->setInterval(0);
    24. QObject::connect(m_timer, &QTimer::timeout, [this](){
    25. emit inIrrlichtMainLoop();
    26. m_device->run();
    27. });
    28. m_timer->start();
    29. }
    30.  
    31. irr::IrrlichtDevice *getIrrlichtDevice() const{
    32. return m_device;
    33. }
    34.  
    35. signals:
    36. void inIrrlichtMainLoop();
    37.  
    38. protected:
    39. void keyPressEvent(QKeyEvent *event){
    40. irr::SEvent irrEvent;
    41. irrEvent.EventType = irr::EET_KEY_INPUT_EVENT;
    42. IrrlichtKey irrKey;
    43. irrKey.code = (irr::EKEY_CODE)(0);
    44. irrKey.ch = (wchar_t)(0);
    45. if((event->key() >= Qt::Key_A && event->key() <= Qt::Key_Z) || (event->key() >= Qt::Key_0 && event->key() <= Qt::Key_9)){
    46. irrKey.code = (irr::EKEY_CODE)event->key();
    47. irrKey.ch = (wchar_t)event->key();
    48. }
    49. else{
    50. switch(event->key()){
    51. case Qt::Key_Up:
    52. irrKey.code = irr::KEY_UP;
    53. break;
    54.  
    55. case Qt::Key_Down:
    56. irrKey.code = irr::KEY_DOWN;
    57. break;
    58.  
    59. case Qt::Key_Left:
    60. irrKey.code = irr::KEY_LEFT;
    61. break;
    62.  
    63. case Qt::Key_Right:
    64. irrKey.code = irr::KEY_RIGHT;
    65. break;
    66. }
    67. }
    68. if(irrKey.code != 0){
    69. irrEvent.KeyInput.Key = irrKey.code;
    70. irrEvent.KeyInput.Control = ((event->modifiers() & Qt::ControlModifier) != 0);
    71. irrEvent.KeyInput.Shift = ((event->modifiers() & Qt::ShiftModifier) != 0);
    72. irrEvent.KeyInput.Char = irrKey.ch;
    73. irrEvent.KeyInput.PressedDown = true;
    74.  
    75. m_device->postEventFromUser(irrEvent);
    76. }
    77. event->ignore();
    78. }
    79.  
    80. void keyReleaseEvent(QKeyEvent *event){
    81. irr::SEvent irrEvent;
    82. irrEvent.EventType = irr::EET_KEY_INPUT_EVENT;
    83. IrrlichtKey irrKey;
    84. irrKey.code = (irr::EKEY_CODE)(0);
    85. irrKey.ch = (wchar_t)(0);
    86. if((event->key() >= Qt::Key_A && event->key() <= Qt::Key_Z) || (event->key() >= Qt::Key_0 && event->key() <= Qt::Key_9)){
    87. irrKey.code = (irr::EKEY_CODE)event->key();
    88. irrKey.ch = (wchar_t)event->key();
    89. }
    90. else{
    91. switch(event->key()){
    92. case Qt::Key_Up:
    93. irrKey.code = irr::KEY_UP;
    94. break;
    95.  
    96. case Qt::Key_Down:
    97. irrKey.code = irr::KEY_DOWN;
    98. break;
    99.  
    100. case Qt::Key_Left:
    101. irrKey.code = irr::KEY_LEFT;
    102. break;
    103.  
    104. case Qt::Key_Right:
    105. irrKey.code = irr::KEY_RIGHT;
    106. break;
    107. }
    108. }
    109. if(irrKey.code != 0){
    110. irrEvent.KeyInput.Key = irrKey.code;
    111. irrEvent.KeyInput.Control = ((event->modifiers() & Qt::ControlModifier) != 0);
    112. irrEvent.KeyInput.Shift = ((event->modifiers() & Qt::ShiftModifier) != 0);
    113. irrEvent.KeyInput.Char = irrKey.ch;
    114. irrEvent.KeyInput.PressedDown = false;
    115.  
    116. m_device->postEventFromUser(irrEvent);
    117. }
    118. event->ignore();
    119. }
    120.  
    121. void mousePressEvent(QMouseEvent *event){
    122. irr::SEvent irrEvent;
    123.  
    124. irrEvent.EventType = irr::EET_MOUSE_INPUT_EVENT;
    125.  
    126. switch(event->button()){
    127. case Qt::LeftButton:
    128. irrEvent.MouseInput.Event = irr::EMIE_LMOUSE_PRESSED_DOWN;
    129. break;
    130.  
    131. case Qt::MidButton:
    132. irrEvent.MouseInput.Event = irr::EMIE_MMOUSE_PRESSED_DOWN;
    133. break;
    134.  
    135. case Qt::RightButton:
    136. irrEvent.MouseInput.Event = irr::EMIE_RMOUSE_PRESSED_DOWN;
    137. break;
    138.  
    139. default:
    140. return;
    141. }
    142.  
    143. irrEvent.MouseInput.X = event->x();
    144. irrEvent.MouseInput.Y = event->y();
    145. irrEvent.MouseInput.Wheel = 0.0f;
    146.  
    147. m_device->postEventFromUser(irrEvent);
    148. event->ignore();
    149. }
    150.  
    151. void mouseReleaseEvent(QMouseEvent* event){
    152. irr::SEvent irrEvent;
    153.  
    154. irrEvent.EventType = irr::EET_MOUSE_INPUT_EVENT;
    155.  
    156. switch(event->button()){
    157. case Qt::LeftButton:
    158. irrEvent.MouseInput.Event = irr::EMIE_LMOUSE_LEFT_UP;
    159. break;
    160.  
    161. case Qt::MidButton:
    162. irrEvent.MouseInput.Event = irr::EMIE_MMOUSE_LEFT_UP;
    163. break;
    164.  
    165. case Qt::RightButton:
    166. irrEvent.MouseInput.Event = irr::EMIE_RMOUSE_LEFT_UP;
    167. break;
    168.  
    169. default:
    170. return;
    171. }
    172.  
    173. irrEvent.MouseInput.X = event->x();
    174. irrEvent.MouseInput.Y = event->y();
    175. irrEvent.MouseInput.Wheel = 0.0f;
    176.  
    177. m_device->postEventFromUser(irrEvent);
    178. event->ignore();
    179. }
    180.  
    181. void wheelEvent(QWheelEvent* event){
    182. if(event->orientation() == Qt::Vertical){
    183. irr::SEvent irrEvent;
    184.  
    185. irrEvent.EventType = irr::EET_MOUSE_INPUT_EVENT;
    186.  
    187. irrEvent.MouseInput.Event = irr::EMIE_MOUSE_WHEEL;
    188. irrEvent.MouseInput.X = 0;
    189. irrEvent.MouseInput.Y = 0;
    190. irrEvent.MouseInput.Wheel = event->delta() / 120.0f;
    191.  
    192. m_device->postEventFromUser(irrEvent);
    193. }
    194. event->ignore();
    195. }
    196.  
    197.  
    198. private:
    199. struct IrrlichtKey{
    200. irr::EKEY_CODE code;
    201. wchar_t ch;
    202. };
    203.  
    204. irr::IrrlichtDevice *m_device;
    205. QTimer *m_timer;
    206. };
    To copy to clipboard, switch view to plain text mode 

    To use this, instead of declaring the Irrlicht device using its constructor, use IrrlichtWidget's getIrrlichtDevice() method. For Irrlicht's main loop, don't create a while loop but use IrrlichtWidget's inIrrlichtMainLoop signal, which is emitted every time it's in the Irrlicht main loop. Here is an example:

    Qt Code:
    1. IrrlichtWidget *myWidget = new IrrlichtWidget;
    2. QObject::connect(myWidget, &IrrlichtWidget::inIrrlichtMainLoop, [myWidget](){
    3. myWidget->getIrrlichtDevice()->getVideoDriver()->beginScene(true, true, irr::video::SColor(255, 255, 255, 255));
    4. myWidget->getIrrlichtDevice()->getSceneManager()->drawAll();
    5. myWidget->getIrrlichtDevice()->getVideoDriver()->endScene();
    6. });
    To copy to clipboard, switch view to plain text mode 

    You don't need to call the device's run() method since it's called automatically.

    To use Irrlicht in Qt Creator, you will have to add these two lines to the .pro file:

    Qt Code:
    1. INCLUDEPATH += "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Libraries\\irrlicht-1.8.4\\include"
    2. LIBS += -L"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Libraries\\irrlicht-1.8.4\\lib\\Win32-visualstudio" -lIrrlicht
    To copy to clipboard, switch view to plain text mode 

    Replace C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Libraries\\irrlicht-1.8.4 with the path in which you installed Irrlicht.

  7. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,243
    Thanks
    303
    Thanked 866 Times in 853 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Irrlicht in qt

    shawk has been waiting 4 1/2 years for this answer. Now he can finally get on with his project...
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  8. #8
    Join Date
    Mar 2016
    Posts
    14
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Irrlicht in qt

    Hi,
    thank you a lot Donald Duck, that works very well, it is a good start point for my project.
    However I don't understand the lines :
    Qt Code:
    1. QObject::connect(myWidget, &IrrlichtWidget::inIrrlichtMainLoop, [myWidget](){
    2. myWidget->getIrrlichtDevice()->getVideoDriver()->beginScene(true, true, irr::video::SColor(255, 255, 255, 255));
    3. myWidget->getIrrlichtDevice()->getSceneManager()->drawAll();
    4. myWidget->getIrrlichtDevice()->getVideoDriver()->endScene();
    5. });
    To copy to clipboard, switch view to plain text mode 
    I have never seen the "[]" bracket around a member, and I don't see the SLOT() like in "send, SIGNAL(), receiver, SLOT()" typical connection.

    Anyone could explain me the " [myWidget](){...}"?
    Last edited by xcxl; 10th June 2018 at 18:01.

  9. #9
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,243
    Thanks
    303
    Thanked 866 Times in 853 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Irrlicht in qt

    Go look up "C++ lambda expression" in your C++ book or online. And read the Qt 5 documentation for QObject::connect().
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.