Game Development Community

In-game web browser

by Iain Craig · in Torque Game Engine · 09/29/2005 (12:23 pm) · 8 replies

(In reference to this thread - didn't want to resurrect)

Having an ActiveX Internet Explorer control embedded in Torque would rock my world. I'm playing with persistent world stuff with MySQL backend, and I'd love to be able to do certain in-game gui tasks in PHP, connecting to the same backend.

This is very similar to There.

I don't mind being Windows-only.

So, my question is, where would I start to get an IE ActiveX control embedded into the engine?

Many thanks for any help anyone can offer.

#1
10/01/2005 (1:48 am)
Well, TorqueDemo doesn't look like it was originally an MFC project, but in visual C++, there are steps to add ActiveX support after the fact (I've read it in one of my books before, try looking it up on google). Once you have ActiveX support in a project, adding a working MSIE control takes like 2 seconds to add to an MFC dialog box. However, it may take a little more work to add it to a non MFC-based window or widget.

The mozilla browser has really improved since the discussion in the old forum thread. Mozilla has an embedding interface, I have used it before to embed a browser engine in a Linux port of one of my programs that used MSIE. The widget I used was called gtkmozembed, which unfortunately would require your project to be a GTK+/Gnome project.

Assuming someone would want to make this reuseable:

Since Torque uses neither MFC or GTK+ toolkits, keeping cross-platform in mind, the best bet would be to make a new browser widget based on their own GUI system. This may actually be possible with Mozilla, if you think about it. The gtkmozembed was basically a GTK+ binding to the Mozilla engine, which would have accessed Mozilla through an exposed C++ interface. I'm sure it's very possible to make a "torquemozembed" widget, since Mozilla is open source and such an interface can be created in/for the Torque engine code. Whether or not changes need to be made to the Mozilla engine is another story. If this is the case (and I have the feeling it is), you'd have to ship modified versions of Mozilla's engine with your game. And from there we go back to the licensing subject...

With embedding either Mozilla or MSIE as a widget, you'll need to look at the GUI part of the Torque engine code, since I imagine that's where all the widgets are implemented (or if necessary on the OpenGL level). You'd probably need to create a widget class and an interface/container class that can pass a handle of the browser engine instance to the widget. I read something the other night about getting videos to play in TGE 1.4RC2 (I think), perhaps they embedded the movie control the same way you would an ActiveX MSIE control.

Whatever the case may be I would imagine it wouldn't be extremely hard to code and get working, compared to developing a Torque engine video game that integrates with such online backend features.
#2
10/02/2005 (10:23 pm)
If anyone has a working mozilla implementation in Torque, I'd be very interested in getting ahold of it. Give me a shout.

One way to do this, incidentally, is to use Cairo or related tech to get mozilla to draw to a texture which you can then put on-screen.
#3
10/03/2005 (12:21 am)
If anyone feels up to it, here is the documentation:

www.mozilla.org/projects/embedding

Also check out the "Roll your own browser" section for examples:

www.mozilla.org/projects/embedding/howto/index.html


I have looked at Torque\SDK\engine\gui\guiAviBitmapCtrl.cc, where it looks like one may get some hints on how to do this. I've also noticed the #include statement, which means it uses win32 (the GUI API) at some point. This tells me you can access handles to win32 objects from within Torque's own GUI code. And from reading the some of the sample mozilla embedding code from the above documentation, you can grab an HWND handle to the browser engine:

lxr.mozilla.org/seamonkey/source/embedding/tests/winEmbed/winEmbed.cpp#329

How to slap an HWND handle into a Torque GUI element is not something I have much knowledge on, but I'm sure someone at GG that has worked on the GUI part of the engine code does. The problem with my above example is that winEmbed (which is win32), has been obsoleted by mfcEmbed which doesn't use HWND handles. I'm sure the MFC version is better anyways, but I'm not even sure if the Torque engine is even built with MFC bindings (why would it if it uses its own GUI system through openGL?).
#4
10/03/2005 (12:39 am)
I have not read the Mozilla license. Are there issues with distributing embedded Mozilla with Torque?

I could take a peek at embedding IE on Windows. I'm new to Torque but I used to develop for Microsoft on the IE team so I'm fairly familiar with it from that end.

-Tricky
#5
10/03/2005 (1:16 am)
You don't want to embed mozilla/IE via the usual "render using the GDI and an HWND or ActiveX control." That's typically a very OS specific way to do it, and it won't behave well with programs like Torque that take over the standard input and rendering paths. You need to put it into a box - get it to render to a texture so you can put it wherever you need, and give it the exact input events you want. The alternative is an eternal headache of focus issues, rendering issues, context switching haedaches, porting problems, driver misbehavior, and other fun things.

The GuiAviBitmapCtrl is an atrocious model for nearly any development. It has been superceded by GuiTheoraCtrl, which demonstrates a much more appropriate way to implement that sort of functionality.
#6
10/03/2005 (1:22 am)
Chris:

What are the license terms for embedding Gecko? (the Mozilla engine is called Gecko)
The same as for the rest of Mozilla. See the MPL page for more information.

http://www.mozilla.org/MPL

It is open source, but embedding is not considered modifying from what I understand, so the source code for your embedding application can be kept closed. It's really a matter of distributing Mozilla/Gecko Rendering Engine with your product.

http://www.mozilla.org/projects/embedding/GRE.html#mozTocId334331


Ben:

Embedding any browser to applications on any OS is going to have OS specific ways, no matter what. You have a very good point about Torque taking over user input and rendering paths. I now see the perils in such a project.
#7
10/03/2005 (2:48 am)
ActiveX is dangerous.

Ari
"Got root?"
#8
10/03/2005 (8:14 am)
Thanks guys, very good overview there.

Note I'm Windows-only but Ben, point taken that the usual Win way of doing this would fight with Torque.

I've got a solution in mind that would actually allow me to embed any mouse-driven application and pass it mouse events, but it's not pretty.

Due to some work I did on a 3D shell for Windows (hmm... must be time for a Torque port...) I've got a fairly elegant way to capture any application window as a memory bitmap. Essentially a create-HBITMAP-given-HWND method.

I could add code to Torque to do this capture, and write a gui control that spawns whatever external app is required, keeps it hidden, renders the captured texture and passes mouse events through to the hidden app.

Not elegant, definately Windows-only, but may meet my needs. I'm going to play. The question is the performance I can get.

I realise this is a hack... but it's my hack, dammit :)

Although I guess if I'm going to do that I could just spawn a menuless/toolbarless browser over the top of the game! Actually, anyone got any tips to let me spawn an app and focus it (while the game's in fullscreen mode) while preventing the mode change back to desktop resolution?