MFC&IrrLicht

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
zcorvid
Posts: 10
Joined: Fri Aug 07, 2015 10:59 am

MFC&IrrLicht

Post by zcorvid »

I need to create an MFC application using IrrLicht. There is method to send rendering into the window using its HWND handle. I tried to use this method with MFC, but some problems have arisen.

1)

Compilation of MFC application with included irrlicht.h returns an error:

Code: Select all

error C2059: Syntax error: (    ...\irrlicht\include\irrallocator.h 47  1   
The code containing the error is the following:

Code: Select all

 
    //! Construct an element
    void construct(T* ptr, const T&e)
    {
        new ((void*)ptr) T(e); // Error is here
    }
 
I can't fix the problem.

2)

I created an MFC application based on dialog windows and I created a picture box. Then I tried to render 3D scene into the picture box, but I failed, because the function CreateDevice returns NULL. On the other hand, this function works corectly for the main window of the application. But I need to place the 3D rendering into a limited region, like a picture box!

I don't know, how make MFC to work with IrrLicht :( .
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: MFC&IrrLicht

Post by CuteAlien »

Not really sure about either of those. But Irrlicht usually compiles so my best guess at your first error is that it's called by something you do before including the irrlicht header. Try including that as first line - do you still get the error then?

For the second error try using createDeviceEx instead of createDevice. That allows you to pass a hwnd as one of it's parameters (WindowId). Check example 14.Win32Window which does do that.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
zcorvid
Posts: 10
Joined: Fri Aug 07, 2015 10:59 am

Re: MFC&IrrLicht

Post by zcorvid »

CuteAlien wrote:Not really sure about either of those. But Irrlicht usually compiles so my best guess at your first error is that it's called by something you do before including the irrlicht header. Try including that as first line - do you still get the error then?
I moved including of irrlicht.h at first line, but compiler returned 1 error (text of error was hidden amog warnings). After commenting all blocks of the following species:

Code: Select all

 
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
 
code was compiled without errors (but with warnings). First problem fixed. Thanks
CuteAlien wrote:For the second error try using createDeviceEx instead of createDevice. That allows you to pass a hwnd as one of it's parameters (WindowId). Check example 14.Win32Window which does do that.
In my code for creating of device the following block is used:

Code: Select all

 
HWND hWind = (HWND)GetDlgItem(ID_Picture_Box);
irr::SIrrlichtCreationParameters param;
param.DriverType = driverType;
param.WindowId = reinterpret_cast<void*>(hWind);
irr::IrrlichtDevice* device = irr::createDeviceEx(param);
 
ID_Picture_Box is ID of Picture Control, which was created using forms constructor of MFC. In this block device gets value NULL.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: MFC&IrrLicht

Post by CuteAlien »

Are there any errors on the console?
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
zcorvid
Posts: 10
Joined: Fri Aug 07, 2015 10:59 am

Re: MFC&IrrLicht

Post by zcorvid »

There is no console, because project has no type "console project", its type is "MFC project". But I can create console and resend output into it... Now I will try this.
zcorvid
Posts: 10
Joined: Fri Aug 07, 2015 10:59 am

Re: MFC&IrrLicht

Post by zcorvid »

I failed in creating of console window, in MFC project there is many errors (63) if I use the following code:

Code: Select all

 
AllocConsole();
HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE);
int hCrt = _open_osfhandle((long)handle_out, _O_TEXT);
FILE* hf_out = _fdopen(hCrt, "w");
setvbuf(hf_out, NULL, _IONBF, 1);
*stdout = *hf_out;
HANDLE handle_in = GetStdHandle(STD_INPUT_HANDLE);
hCrt = _open_osfhandle((long)handle_in, _O_TEXT);
FILE* hf_in = _fdopen(hCrt, "r");
setvbuf(hf_in, NULL, _IONBF, 128);
*stdin = *hf_in;
 
I will think, how fix that, but it requires some time.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: MFC&IrrLicht

Post by CuteAlien »

You can get the console output by starting your .exe from a console. You can use DosBox if you have no good one installed. I personally prefer using the shells from MinGW or Cygwin (both provide unix-shells which run on Windows).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
zcorvid
Posts: 10
Joined: Fri Aug 07, 2015 10:59 am

Re: MFC&IrrLicht

Post by zcorvid »

CuteAlien wrote:You can get the console output by starting your .exe from a console. You can use DosBox if you have no good one installed. I personally prefer using the shells from MinGW or Cygwin (both provide unix-shells which run on Windows).
I tried start application from the console. Application run, but there is no any log information in console (like information, which is shown in console, when application runs as console application).
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: MFC&IrrLicht

Post by CuteAlien »

Hm, strange. Well, without an example to reproduce the problem I can't help much. You have to debug into the engine to see where it fails.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: MFC&IrrLicht

Post by REDDemon »

zcorvid, you should run your application from console and redirect output to log files, sometimes that works where other solutions fails and is pretty simple, if you are on windows the batch script for that is:

Code: Select all

 
C:\yourDirectory>yourApplication.exe 1> cerr.txt 2> cout.txt
 
If that don't work chances are
1) loggin disabled (you compiled irrlicht without logging)
2) some code in your application redirected cerr & cout somewhere else
3) the application is sandboxed inside another application that steal cerr& cout without re-transmitting them outside.

It seems you are in case 2) XD. by creating a "console" using code, you accidentally messed up application output. JUST ERASE THAT CONSOLE CODE, AND RUN APPLICATION FROM CONSOLE.
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
zcorvid
Posts: 10
Joined: Fri Aug 07, 2015 10:59 am

Re: MFC&IrrLicht

Post by zcorvid »

Problems, which we met, was very hard and we decided not use MFC. Now the development will use Windows Forms Application (this is special module for Visual Studio). Our project correctly ported in this project type. There was problem with event receiver (IrrLicht receiver didn't see events while device runs), but we found the answer for this problem. Now the project is in progress and I hope, it will not meet any other problems :)
Post Reply