View Websites in a Game

Posted By: Lutz_G

View Websites in a Game - 12/23/07 11:06

Hi

Just for fun...
Now it's possible to view websites in your game.
Use W A S D and the Mouse to move and rotate around and 1 2 3 4 5 to call websites.

Please try this application and tell me what you think.


Download ( 2,34 MB )

Have fun!!!




Posted By: JibbSmart

Re: View Websites in a Game - 12/23/07 12:02

man that's cool! even apart from the fact that i can see my name on the first screenshot ;P abouta give it a go...

julz

EDIT: lol, got a pop-up. my laptop struggles with it, but still cool.
Posted By: Slin

Re: View Websites in a Game - 12/23/07 12:15

Very cool, but why is it that slow?
Posted By: ambe

Re: View Websites in a Game - 12/23/07 12:26

Those pop ups needs to be taken care of ingame .. otherwise awesome
Posted By: FlorianP

Re: View Websites in a Game - 12/23/07 13:21

rly cool - thats what i was looking for a time ago.
Do you allow to use it for free?
Posted By: Martek

Re: View Websites in a Game - 12/23/07 13:52

Very nice and my Name is on the List too

Mfg, Pingulord
Posted By: frazzle

Re: View Websites in a Game - 12/23/07 19:55

Nice one

Cheers

Frazzle
Posted By: flits

Re: View Websites in a Game - 12/23/07 20:31

realy cool like to zee my desktop in 3d to
(especialy when its working to)

i hope u can make the buttons working

great job
Posted By: broozar

Re: View Websites in a Game - 12/23/07 20:47

looks like beryl or compiz (linux 3d desktop)
Posted By: Gandalf

Re: View Websites in a Game - 12/23/07 21:53

very nice work
Posted By: jemen

Re: View Websites in a Game - 12/23/07 22:38

COOL
C O O L
COLD as NORTPOLEICE
Posted By: Ready

Re: View Websites in a Game - 12/24/07 04:38

wow this is pretty cool
Only downside is that its pretty slow
Posted By: adoado

Re: View Websites in a Game - 12/24/07 05:08

Lutz, what is the method you are using to achieve this?

A while ago I achieved the same thing (web browser in 3dgs) but mine was slow also, mainly due to the fact that I had to "inefficiently" copy the web browser into a 3dgs BMAP..

Thanks,
Adoado
Posted By: Lutz_G

Re: View Websites in a Game - 12/24/07 07:51

Yes, it is slow. But i think a performance increase is not possible.
It was hard to get a Browser-Bitmap to a GS-Bitmap.

@adoado: Unfortunately i can not use the paintto-Method. Wicht did this with the 3dgs-Flash-Plugin. But with a TWebBrowser-Object it's not possible.
There are two main operations:
1. From TWebBrowser to TBitmap
2. From TBitmap to PBMAP.

The second step is very easy and very fast. (BitmapToTexture(PBMAP, TBitmap). The bottle neck is step one.

Here is the complete Code:

Code:

unit Unit_Main;

interface

uses ComObj, ActiveX, Windows,Graphics,Sysutils,A6DLLLib, A6DLL, DLL_DEBUG, Classes, messages, OleCtrls,SHDocVW,MSHTML_TLB,Controls,JPEG,Direct3D9,Dialogs,Clipbrd,ExtCtrls,Variants,StdCtrls,ComCtrls;

function dsg_WebCreate():VAR_; cdecl; exports dsg_WebCreate;
function dsg_WebNavigate(url:PString):VAR_; cdecl; exports dsg_WebNavigate;
function dsg_WebPaint(bmap:PBMAP):VAR_; cdecl; exports dsg_WebPaint;

function BitmapToTexture(tex: PBMAP; var B: TBitmap): Integer;

implementation

const Username_real:string = 'put your GS username here';

var WB:TWebBrowser;
H:THandle;
sourceBitmap: TBitmap;
targetBitmap: TBitmap;
B:TBitmap;
UserValid:boolean = false;


function dsg_WebCreate():VAR_;
var Username_p:PChar;
Username_s:String;
Begin
Username_p:=ev.User_name.char;
Username_s:=StrPas(Username_p);
if Username_s = Username_real then
UserValid:=true else
UserValid:=false;

if UserValid = true then
Begin
Coinitialize(nil);
H:=ev.hWndMain;
WB:=TWebBrowser.CreateParented(H);
WB.Left:=1400;
WB.Top:=0;
WB.Width:=1024;
WB.Height:=1024;
WB.Visible:=true;
WB.DoubleBuffered:=true;
End else
ShowMessage('Sorry... Wrong User');
End;



function dsg_WebNavigate(url:PString):VAR_;
var url_p:PChar;
url_s:string;
Begin
if UserValid = true then
Begin
url_p:=_CHR(url);
url_s:=StrPas(url_p);

WB.Navigate(url_s);
end;
End;

function generateBitmapfromBrowser(browser: iWebBrowser2;
srcHeight: Integer; srcWidth: Integer; tarHeight: Integer; tarWidth: Integer):TBitmap;
var
sourceDrawRect: TRect;
targetDrawRect: TRect;
viewObject: IViewObject;
begin
if sourceBitmap=nil then
sourceBitmap := TBitmap.Create;

if targetBitmap=nil then
Begin
targetBitmap := TBitmap.Create;
targetBitmap.PixelFormat:=pf16bit;
End;

try
try
sourceDrawRect := Rect(0, 0, srcWidth, srcHeight);
sourceBitmap.Width := srcWidth;
sourceBitmap.Height := srcHeight;

viewObject := browser as IViewObject;

if viewObject = nil then
Exit;

// this operation is the bottle neck !!!!!!!!!!!!!!
OleCheck(viewObject.Draw(DVASPECT_CONTENT, 1, nil, nil, H,
sourceBitmap.Canvas.Handle, @sourceDrawRect, nil, nil, 0));

// Resize the src bitmap to the target bitmap
targetDrawRect := Rect(0, 0, tarWidth, tarHeight);
targetBitmap.Height := tarHeight;
targetBitmap.Width := tarWidth;
targetBitmap.Canvas.StretchDraw(targetDrawRect, sourceBitmap);

result:=targetBitmap;

finally
end;
except
// Error Code
end;

end;

function dsg_WebPaint(bmap:PBMAP):VAR_;
var
IDoc1: IHTMLDocument2;
Web:IWebBrowser2;
viewObject: IViewObject;
dx9tex : IDIRECT3DTEXTURE9;
ddsd : TD3DSURFACE_DESC;
tex:PBMAP;
Begin
if UserValid = true then
Begin
CoInitialize(nil);
try

if B=nil then
Begin
B:=TBitmap.Create;
B.PixelFormat:=pf16bit;
end;

tex:=bmap;
with WB do
begin
Document.QueryInterface(IHTMLDocument2, iDoc1);
Web := WB.ControlInterface;

TControl(WB).Visible := Boolean(0);
Height:=1024;
Width:=1024;
B:=generateBitmapfromBrowser(Web,1024, 1024, 1024, 1024);
TControl(WB).Visible := Boolean(1);
end;

dx9tex := IDIRECT3DTEXTURE9(tex.d3dtex);


if (dx9tex <> nil) then
begin
if (not FAILED(dx9tex.GetLevelDesc(0,ddsd))) then
begin
B.Width := ddsd.Width;
B.Height := ddsd.Height;
end;
end;

BitmapToTexture(tex,B);
SourceBitmap.FreeImage;
TargetBitmap.FreeImage;
except
on E:Exception do
begin

if Assigned(B) then B.Free;
// if Verbose then a5dll_errormessage(PChar(E.Message));
//ShowMessage(PChar(E.Message));

end;


end;
end;
result:=_VAR(1);
End;

function BitmapToTexture(tex: PBMAP; var B: TBitmap): Integer;
type
TRGBQuadArray = ARRAY[WORD] OF INTEGER;
pRGBQuadArray = ^TRGBQuadArray;
PWORD = ^WORD;
var
// tex : PA4_TEX;
dx9tex : IDIRECT3DTEXTURE9;
ddsd : TD3DSURFACE_DESC;
d3dlr : TD3DLOCKED_RECT;
pixels : PByte;
row : pRGBQuadArray;
Row16 : pWordArray;
y : longword;
x : longword;
target : Plongword;
Error: Integer;
//OldT: Integer;
begin
Error := 0;
// oldt := gettickcount;
{ we can not be sure that the entity texture exists - it could be purged }
// tex := bmap^.tex;
if (tex <> NIL) then
begin
dx9tex := IDIRECT3DTEXTURE9(tex.d3dtex);
if (dx9tex <> nil) then
begin
// a5dll_errormessage(pchar('got to bitmap create'));
// B := TBitmap.Create;
{ check the texture format }
if (not FAILED(dx9tex.GetLevelDesc(0,ddsd))) then
begin
//B.Width := ddsd.Width;
//B.Height := ddsd.Height;
{ lock the texture and retrieve a pointer to the surface }
if (not FAILED(dx9tex.LockRect(0,d3dlr,nil,0))) then
begin
try
pixels := PByte(d3dlr.pBits);
// a5dll_errormessage(pchar('pixels assigned'));
{ do we have a 16 bit or 32 bit format? All 4 formats are possible: }
if (ddsd.Format = D3DFMT_A8R8G8B8) then
begin
// a5dll_errormessage(pchar('32bit'));
B.PixelFormat := pf32Bit;
y := 0;
while (y < ddsd.Height) do
begin
target := pointer(longword(pixels) + (y * d3dlr.Pitch));
row := B.Scanline[y];
x := 0;
while (x < ddsd.Width) do
begin
//target^ := $FFFF0000; { that's red in 8888 }
target^ := row[x];//x*y;
target := pointer(longword(target) + 4);
x := x + 1;
end;
y := y + 1;
end;
end
else if (ddsd.Format = D3DFMT_A4R4G4B4) then
begin
// a5dll_errormessage(pchar('16bit1'));
B.PixelFormat := pf16Bit;
y := 0;
while (y < ddsd.Height) do
begin
target := pointer(longword(pixels) + (y * d3dlr.Pitch));
row16 := B.Scanline[y];
x := 0;
while (x < ddsd.Width) do
begin
//PWord(target)^ := $FF00; { that's red in 4444 }
PWord(target)^ := row16[x];//x*y;
target := pointer(longword(target) + 2);
x := x + 1;
end;
y := y + 1;
end
end
else if (ddsd.Format = D3DFMT_A1R5G5B5) then
begin
// a5dll_errormessage(pchar('16bit2'));
B.PixelFormat := pf16Bit;
y := 0;
while (y < ddsd.Height) do
begin
target := pointer(longword(pixels) + (y * d3dlr.Pitch));
row16 := B.Scanline[y];
x := 0;
while (x < ddsd.Width) do
begin
//PWord(target)^ := $FC00; { that's red in 1555 }
PWord(target)^ := row16[x];//x*y;
target := pointer(longword(target) + 2);
x := x + 1;
end;
y := y + 1;
end;
end
else if (ddsd.Format = D3DFMT_R5G6B5) then
begin
// a5dll_errormessage(pchar('16bit3'));
B.PixelFormat := pf16Bit;
y := 0;
while (y < ddsd.Height) do
begin
target := pointer(longword(pixels) + (y * d3dlr.Pitch));
row16 := B.Scanline[y];
x := 0;
while (x < ddsd.Width) do
begin
PWord(target)^ := row16[x];//x*y;
//PWord(target)^ := $F800; { that's red in 565 }
target := pointer(longword(target) + 2);
x := x + 1;
end;
y := y + 1;
end;
end;
// a5dll_errormessage(pchar('got to save file'));
// fn := StrPas(filename^.chars);
// B.SaveToFile(fn);
// a5dll_errormessage(pchar('saved'));
{ Unlock the surface again }
except
Error := 1;
end;
dx9tex.UnlockRect(0);
end;
end;
// B.Free;
end;
end;
// oldt := gettickcount-oldt;
// a5dll_errormessage(pchar(inttostr(oldt)));
result := Error;
end;

end.


Posted By: adoado

Re: View Websites in a Game - 12/27/07 12:20

Wow, thanx for sharing the code

TWebbrowser? Wheres that class? Is that in Delphi natively? ^^

I used a Delphi component (I can't remember the name exactly) which did have a PaintTo method.

With step two, when I used the BitmapToTexture function my bitmaps were modified. They somehow gained alpha channels and their dimensions were stretched, etc. Did you experience this?

Unfortunately, I think you are right. Using this method, a performance boost may not be possible

Thanks,
Adoado
Posted By: raymich

Re: View Websites in a Game - 12/27/07 15:11

very interesting work there!
Posted By: Lutz_G

Re: View Websites in a Game - 12/28/07 16:13

@adoado:
I have Delphi Turbo Explorer. There you have a TWebbrowser.
Otherwise you can install a ActiveX.

Go to "Install ActiveX" (or something like this) and choose "Microsoft Internet Components".

Now you can use the Browser-Object in Delphi. And in GS.
Posted By: zolyn213

Re: View Websites in a Game - 12/29/07 02:15

Hallo ich bin äusserst begeistert von dieser Funktion und war genau danach auf der Suche. Sehr gerne würde ich diese Funktion mit in mein Level einfügen. Jedoch benötige ich noch eine Klickfunktion. Es muss möglich sein wie im normalen Browser zu surfen. Derzeit besitze ich nur die Trial-Edition von 3DGS, jedoch würde ich mir sehr gerne das Paket bestellen, sofern ich eine Möglichkeit finde die Internetseiten INgame anzuzeigen.

Es wäre sehr schön wenn es dieses wunderbare Script für alle Frei zugänglich wäre und man es ohne gesonderte Software editieren könnte.
Ich wäre auch bereit ggf. etwas dafür zu Zahlen.

@Lutz G, Please write me an PN or post here.
Posted By: adoado

Re: View Websites in a Game - 12/29/07 06:07

Ah, you are using an ActiveX control, ok then ^^

I think I will relook into my old version, see if I can improve it, although I doubt there will be a big speed increase..

Thanks,
Adoado
Posted By: alleen

Re: View Websites in a Game - 01/04/08 19:30

excellent job

it runs extremely slow though, with like 1 or 2 fps?
Posted By: Lutz_G

Re: View Websites in a Game - 01/04/08 21:04

Yes, i know. It is slow. But... it was just for fun.
I posted the source code because adoado is also working on a similar plugin.

Currently i have other preferences. I'am working with Wicht on a Ingame-LevelEditor with a Cutscene-Editor, Particle-Editor, own Scenemanagement and a own Levelformat/Load- & Savesystem.
Posted By: LazyDog

Re: View Websites in a Game - 01/05/08 23:09

Quote:

Currently i have other preferences. I'am working with Wicht on a Ingame-LevelEditor with a Cutscene-Editor, Particle-Editor, own Scenemanagement and a own Levelformat/Load- & Savesystem.




sounds cool, would this by chance be getting developed in Delphi?
Posted By: Lutz_G

Re: View Websites in a Game - 01/06/08 10:09

Only Delphi!!! What else?
Posted By: adoado

Re: View Websites in a Game - 01/06/08 10:30

Wow that sounds awesome Lutz_G!! You gotta keep us all informed of this

And yeah, no other programming language would be up for the job

Thanks,
Adoado
Posted By: frazzle

Re: View Websites in a Game - 01/06/08 10:58

Quote:


And yeah, no other programming language would be up for the job





Typical adoado

Cheers

Frazzle
Posted By: DoC

Re: View Websites in a Game - 01/07/08 08:13

This is one of the best idea I ever see. The only problem is the framerate...
but good one!
© 2024 lite-C Forums