Page 1 of 1

can i using irrlicht in MFC?

Posted: Wed Sep 07, 2005 2:59 am
by yjlchina
well...
i was supposed to develop an MFC application with a 3D scene window in it. i wonder if i could using irrlicht to render the subwindow in my application. Since there is already a tutorial about how to integrate win32 application with irrlicht, i think it is possible to do the same thing in MFC.
but i really don't kown where to put the "device->run()" function.
if anybody did it, please tell me.

Posted: Wed Sep 07, 2005 7:37 am
by Bersi
I didn't try this but I think you have to put the "device->run" function into the function OnTimer. Start your own timer with a specific id and duration and then run the function when the timer is triggered. I don't know if this works but I think it does. :)

With the timer you can also change the frame rate yourself.


Here is some peace of example code:

Code: Select all

void CMyApp::OnTimer(UINT nIDEvent) 
{
    if(nIDEvent == 1)
        device->run();

    CDialog::OnTimer(nIDEvent);
}

void CMyApp::StopDrawing()
{
    KillTimer(1);
}

BOOL CMyApp::OnInitDialog()
{
    ...

    SetTimer(1, 50); // 20 fps

    return TRUE;
}

As I said before I have never tested this. But let's have a try. ;)

Posted: Wed Sep 07, 2005 7:40 am
by Guest
But I thinks it's better when you create a second thread which draws the 3d scene. So you can work like you do with other irrlicht projects and use two threads. The base thread for the whole MFC stuff and the other for the irrlicht stuff. ;)

Posted: Wed Sep 07, 2005 4:06 pm
by dhenton9000
I've heard rumors (I could be wrong) that Irrlicht might snarf keyboard/mouse events or otherwise mess up event handling by MFC. I would love to get Irrlicht to work under MFC, what a great way to make gaming tools.

Posted: Thu Sep 08, 2005 3:37 am
by yjlchina
i put some code in "OnTimer()" and it really works.
but there comes another problem, the scene does't show at all.

here is some of my code.


C***View::OnCreate(){
...
HWND hWnd;
hWnd = GetSafeHwnd();

SIrrlichtCreationParameters p;
p.DriverType = EDT_OPENGL;
p.AntiAlias = true;
p.WindowId = (s32)hWnd;
device = createDeviceEx(p);

driver = device->getVideoDriver();
smgr = device->getSceneManager();

device->getFileSystem()->addZipFileArchive("map-20kdm2.pk3");
mesh = smgr->getMesh("20kdm2.bsp");
node = 0;
if (mesh)
node = smgr->addOctTreeSceneNode(mesh->getMesh(0));
if (node)
node->setPosition(core::vector3df(-1300,-144,-1249));
smgr->addCameraSceneNodeFPS();

SetTimer(1, 100, NULL);
...
}

C***View::OnTimer(){
...
driver->beginScene(true, true, SColor(0,rand()%200,rand()%200,rand()%200));
smgr->drawAll();
guienv->drawAll();
driver->endScene();
...
}

i make the backcolor change everytime OnTimer() is called, and it works. but i can't see the expected quake map at all.

Posted: Thu Sep 08, 2005 12:12 pm
by cpprules
I hate MFC, is there any reason you must use it?

Posted: Fri Sep 09, 2005 7:19 am
by yjlchina
MFC is a powerful tool on windows platform. if you want to make some complex and standard window applications, MFC will be a good choice. if i want to make a level editor, what else can i use?