[Linux] Firefox embedding

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Linaxys
Posts: 47
Joined: Tue Feb 24, 2009 10:46 pm

[Linux] Firefox embedding

Post by Linaxys »

Hey all,
I've been doing some good stuff with the engine, but now I'd like to embed it inside Firefox, under Linux.

I got my plugin ready to be compiled, if I use the traditional createDevice function, it creates a new window and renders fine.

But if I use createDeviceEx with the params I specified, it doesn't render anything, it does something like this :

http://img25.imageshack.us/my.php?image=arghhh.jpg

This is where the X stuff create's it's own window to render inside the canvas of the firefox plugin :

Code: Select all

NPError nsPluginInstance::SetWindow(NPWindow* aWindow)
{
  if(aWindow == NULL)
    return FALSE;

  mX = aWindow->x;
  mY = aWindow->y;
  mWidth = aWindow->width;
  mHeight = aWindow->height;
  if (mWindow == (Window) aWindow->window) {
    // The page with the plugin is being resized.
    // Save any UI information because the next time
    // around expect a SetWindow with a new window id.
  } else {
    mWindow = (Window) aWindow->window;
    NPSetWindowCallbackStruct *ws_info = (NPSetWindowCallbackStruct *)aWindow->ws_info;
    mDisplay = ws_info->display;
    mVisual = ws_info->visual;
    mDepth = ws_info->depth;
    mColormap = ws_info->colormap;

    if (!mFontInfo) {
      if (!(mFontInfo = XLoadQueryFont(mDisplay, "9x15")))
        printf("Cannot open 9X15 font\n");
    }
    // add xt event handler
    Widget xtwidget = XtWindowToWidget(mDisplay, mWindow);
    if (xtwidget && mXtwidget != xtwidget) {
      mXtwidget = xtwidget;
      long event_mask = ExposureMask;
      XSelectInput(mDisplay, mWindow, event_mask);
      XtAddEventHandler(xtwidget, event_mask, False, (XtEventHandler)xt_event_handler, this);

      /*
      *
      * Beginning of IRRLICHT Init Code!
      *
      */

      SIrrlichtCreationParameters param;
      param.WindowId = reinterpret_cast<void*>(mWindow);
      param.DriverType = EDT_SOFTWARE;
      param.WindowSize = dimension2d<s32>(mWidth,mHeight);
      device = createDeviceEx(param);
      //device = createDevice( video::EDT_OPENGL, dimension2d<s32>(mWidth, mHeight), 32, false, false, false, 0);
      driver = device->getVideoDriver();

      smgr = device->getSceneManager();

      guienv = device->getGUIEnvironment();


      guienv->addStaticText(L"Hello World!", rect<s32>(10,10,260,22), true);
      smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));

      /*
      *
      * End of IRRLICHT Init Code!
      *
      */
    }
  }
  draw();
  return TRUE;
}
The Draw function, called everytime, main loop :

Code: Select all

void nsPluginInstance::draw()
{

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

  /*
  *
  * Blah blah blah, go away X...
  */

  /*unsigned int h = mHeight/2;
  unsigned int w = 3 * mWidth/4;
  int x = (mWidth - w)/2; // center
  int y = h/2;
  if (x >= 0 && y >= 0) {
    GC gc = XCreateGC(mDisplay, mWindow, 0, NULL);
    if (!gc) 
      return;
    XDrawRectangle(mDisplay, mWindow, gc, x, y, w, h);
  const char *string = getVersion();
  if (string && *string) {
    int l = strlen(string);
    int fmba = mFontInfo->max_bounds.ascent;
    int fmbd = mFontInfo->max_bounds.descent;
    int fh = fmba + fmbd;
    y += fh;
    x += 32;
      XDrawString(mDisplay, mWindow, gc, x, y, string, l); 
    }
    XFreeGC(mDisplay, gc);
  }*/

}
I already tried replacing mWindow by mDisplay, mXtwidget,... it shows :
Irrlicht Engine version 1.5
Linux 2.6.27-11-generic #1 SMP Thu Jan 29 19:24:39 UTC 2009 i686
Creating X window...
Visual chosen: : 33
X Error: BadWindow (invalid Window parameter)
From call : X_CreateWindow
X Error: BadWindow (invalid Window parameter)
From call : X_ChangeProperty
X Error: BadWindow (invalid Window parameter)
From call : X_ConfigureWindow
X Error: BadWindow (invalid Window parameter)
From call : X_MapWindow
X Error: BadDrawable (invalid Pixmap or Window parameter)
From call : X_GetGeometry
X Error: BadWindow (invalid Window parameter)
From call : X_GetProperty
X Error: BadDrawable (invalid Pixmap or Window parameter)
From call : X_CreatePixmap
X Error: BadDrawable (invalid Pixmap or Window parameter)
From call : X_CreatePixmap
X Error: BadDrawable (invalid Pixmap or Window parameter)
From call : X_CreateGC
X Error: BadDrawable (invalid Pixmap or Window parameter)
From call : X_PolyFillRectangle
X Error: BadDrawable (invalid Pixmap or Window parameter)
From call : X_PolyFillRectangle
X Error: BadPixmap (invalid Pixmap parameter)
From call : X_CreateCursor
X Error: BadGC (invalid GC parameter)
From call : X_FreeGC
X Error: BadPixmap (invalid Pixmap parameter)
From call : X_FreePixmap
X Error: BadPixmap (invalid Pixmap parameter)
From call : X_FreePixmap
X Error: BadDrawable (invalid Pixmap or Window parameter)
From call : X_PutImage
X Error: BadDrawable (invalid Pixmap or Window parameter)
From call : X_PutImage
X Error: BadDrawable (invalid Pixmap or Window parameter)
From call : X_PutImage
X Error: BadDrawable (invalid Pixmap or Window parameter)
From call : X_PutImage
X Error: BadDrawable (invalid Pixmap or Window parameter)
From call : X_PutImage
X Error: BadDrawable (invalid Pixmap or Window parameter)
From call : X_PutImage
X Error: BadDrawable (invalid Pixmap or Window parameter)
From call : X_PutImage
X Error: BadDrawable (invalid Pixmap or Window parameter)
From call : X_PutImage
X Error: BadDrawable (invalid Pixmap or Window parameter)
From call : X_PutImage
X Error: BadDrawable (invalid Pixmap or Window parameter)
From call : X_PutImage
X Error: BadDrawable (invalid Pixmap or Window parameter)
From call : X_PutImage
X Error: BadDrawable (invalid Pixmap or Window parameter)
From call : X_PutImage
X Error: BadDrawable (invalid Pixmap or Window parameter)
From call : X_PutImage
X Error: BadDrawable (invalid Pixmap or Window parameter)
From call : X_PutImage
X Error: BadDrawable (invalid Pixmap or Window parameter)
From call : X_PutImage
X Error: BadDrawable (invalid Pixmap or Window parameter)
From call : X_PutImage
X Error: BadDrawable (invalid Pixmap or Window parameter)
From call : X_PutImage
X Error: BadDrawable (invalid Pixmap or Window parameter)
From call : X_PutImage
I've heard about creating a parent window inside the mWindow for Win32, but I don't know how to do that with X... Weird...

Thanks a lot for your help, I will seriously need it.
Frank Dodd
Posts: 208
Joined: Sun Apr 02, 2006 9:20 pm

Post by Frank Dodd »

I'm afraid I am not experienced with plug-ins for Firefox but I'd just like to give my moral support for the project, I've always thought that a 3D engine plug in for a browser has a massive market for high quality in browser casual gaming.

Good luck with the project and I hope you get some help.
wITTus
Posts: 167
Joined: Tue Jun 24, 2008 7:41 pm
Location: Germany

Post by wITTus »

I'm trying to understand how this could be possibly useful. Could I create a script page then (like HTML), which contains interpreted calls to Irrlicht functions? Image
Linaxys
Posts: 47
Joined: Tue Feb 24, 2009 10:46 pm

Post by Linaxys »

OK Guys, it works like a charm under Firefox with Windows, haven't tried with MacOSX yet...

There's maybe something wrong with the EDT_OPENGL device when I try to render to a XtWindow on firefox, I'll see that later once I get the time.

I don't know anything about mac, can someone please tell me how it's windows system work ? Is it like linux ? Or completely different ?

Thanks.
Abraxas
Posts: 57
Joined: Mon Nov 07, 2005 3:56 pm

Post by Abraxas »

Hello,

I am looking for a plugin for firefox just to be able to have a showroom for some artwork I've done with the amazing irrlicht engine.

Unfortunately I am not familiar with creating plugin and how to use this,
but I still hope someone has already made this.

I would be so great if someone could help me.
The best would be a plugin installer like others work, and then the possibility just to embed this in the web page with some parameter like to load the scene content from the server and render it in the canvas onto the site.

Please help me, if you can.
Thank you

Oliver
Image
Post Reply