Page 1 of 1

Render in Existing Window

Posted: Sun Dec 10, 2006 9:01 pm
by VertigoEclipse
Hey Guys,

Just started with IRRLICHT. I have an application that creates an OpenGL window and renders graphics using it's own 3D engine.

This application offers and SDK that allows me to do my own rendering on top of the existing 3D grpahics engine which is OpenGL based.

I want to render using IRRLICHT similar to how you would render inside of a Win32 window. I have a handle to the existing OpenGL window, is there some sample code on how to initialize IRRLICHT using an existing OpenGL window?

Cheers!

Posted: Sun Dec 10, 2006 10:27 pm
by Acki
I don't know if there could be a conflict between Irrlicht and OpenGL, but as long as you have a handle to a window you can use this handle/window to create a device that renders into this window...
This can be done with any window you got a handle from (all Windows objects like buttons etc. are derived from the class window and can be used for this as long as you got the handle of it)...
The win32-tutorial shows how to create a device inside a win32 window !!!
So you can use this tutorial and instead of the creation of the window you can use the handle directly...
Or look in the docu for createDeviceEx(...), this is used for this...

EDIT:
Yeah, here is a little demo that runs Irrlicht inside Notepad !!!
Run this program and open Notepad... :lol:

Code: Select all

#include <windows.h>
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

int main(){
  HWND wnd = 0;
  while(!wnd){
    wnd = FindWindow("Notepad", NULL);
    if(wnd) wnd = GetWindow(wnd, GW_CHILD);
    Sleep(10);
  }
  SIrrlichtCreationParameters ppp;
  ppp.AntiAlias = false;
  ppp.Bits = 16;
  ppp.DriverType = EDT_DIRECT3D9;
  ppp.EventReceiver = 0;
  ppp.Fullscreen = false;
  ppp.HighPrecisionFPU = false;
  ppp.Stencilbuffer = false;
  ppp.Vsync = false;
  ppp.WindowSize = dimension2d<s32>(800, 600);
  ppp.WindowId = (s32)wnd;

  IrrlichtDevice *device = createDeviceEx(ppp);
  IVideoDriver* driver = device->getVideoDriver();
  ISceneManager* smgr = device->getSceneManager();
  IGUIEnvironment* guienv = device->getGUIEnvironment();

  ISceneNode* node = smgr->addCubeSceneNode(10);
  node->setPosition(vector3df(0, -50, 50));
  ICameraSceneNode* cam = smgr->addCameraSceneNode();
  cam->setTarget(vector3df(0, -50, 50));

  while(device->run()){
    driver->beginScene(true, true, SColor(255,100,101,140));
    smgr->drawAll();
    guienv->drawAll();
    driver->endScene();
  }
  device->drop();
  return 0;
}

Posted: Mon Dec 11, 2006 12:18 am
by VertigoEclipse
Acki,


Really appreciate the help, I'll do some testing.

Best Regards,

C

Posted: Tue Mar 06, 2007 10:42 pm
by Abraxas
Hello,

I am very interested in this.
But how can I run this Programme, Acki posted?
(It is plain Text, not an *.exe - file)

Greetings

Abraxas

Posted: Wed Mar 07, 2007 12:08 am
by Acki
This plain text is called C/C++ source code !!! :lol:
Make an exe file out of it... ;)

Posted: Wed Mar 07, 2007 12:46 am
by Abraxas
Hi,

sorry, I didn't know it was c++ source code.
I will put it into a visual studio file (and hope it will work).

Thank you very much.

Posted: Wed Mar 07, 2007 1:03 am
by Acki
Well, the main problem would be to find the correct window you want to use...
Especially for a internet browser, because there are many different browsers out there...

For example to use it with Mozilla's Firefox you'll have to do it this way:

Code: Select all

  HWND wnd = 0;
  while(!wnd){
    wnd = FindWindow(NULL, "Mozilla Firefox");
    if(wnd){ // Firefox found
      Sleep(100);
      // find the main area
      wnd = GetWindow(wnd, GW_CHILD);
      wnd = GetWindow(wnd, GW_CHILD);
      wnd = GetWindow(wnd, GW_HWNDNEXT);
      wnd = GetWindow(wnd, GW_HWNDNEXT);
      wnd = GetWindow(wnd, GW_CHILD);
      wnd = GetWindow(wnd, GW_CHILD);
      wnd = GetWindow(wnd, GW_CHILD);
      wnd = GetWindow(wnd, GW_CHILD);
    }
  }
This will run Irrlicht inside the Firefox window (no webpage needed to load) !!! ;)
You see there are many child windows you have to enumerate until you get to the main screen of Firefox !!!
And if someone uses MSIE it's again a different number of child windows and maybe you'll have to add for example an empty Java applet to get the HWND off... :?

Posted: Wed Mar 07, 2007 2:08 pm
by Abraxas
Thank you Acki,

I will give this to a friend to test it, because it doesn't run on my computer.
It is maybe too old. I don't have the "windows.h" file, but this is neccessary to include it.

Maybe my friend could make a browser-plugin for irrlicht engine using this code, as long as it doesn't work with jirr. There are too many errors (like security errors "access denied" for the applet or "class not found").

I'll give it up now.
Maybe I have to wait until someone will write a browser-plugin.

Sorry, I didn't expect things would become this complicated.

Greetings

Abraxas