Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,014 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 3 1 2 3
Re: View Websites in a Game [Re: Gandalf] #174508
12/23/07 22:38
12/23/07 22:38
Joined: Feb 2005
Posts: 29
jemen Offline
Newbie
jemen  Offline
Newbie

Joined: Feb 2005
Posts: 29
COOL
C O O L
COLD as NORTPOLEICE


Jemen - Out:.... www.theJemReport.com
Re: View Websites in a Game [Re: jemen] #174509
12/24/07 04:38
12/24/07 04:38
Joined: Dec 2003
Posts: 129
Osnabrück, Germany
Ready Offline
Member
Ready  Offline
Member

Joined: Dec 2003
Posts: 129
Osnabrück, Germany
wow this is pretty cool
Only downside is that its pretty slow


Do not underestimate people because they have a low post count... :0
Re: View Websites in a Game [Re: Ready] #174510
12/24/07 05:08
12/24/07 05:08
Joined: Jul 2006
Posts: 503
Australia
A
adoado Offline

User
adoado  Offline

User
A

Joined: Jul 2006
Posts: 503
Australia
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


Visit our development blog: http://yellloh.com
Re: View Websites in a Game [Re: adoado] #174511
12/24/07 07:51
12/24/07 07:51
Joined: Jul 2007
Posts: 103
L
Lutz_G Offline OP
Member
Lutz_G  Offline OP
Member
L

Joined: Jul 2007
Posts: 103
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.



Re: View Websites in a Game [Re: Lutz_G] #174512
12/27/07 12:20
12/27/07 12:20
Joined: Jul 2006
Posts: 503
Australia
A
adoado Offline

User
adoado  Offline

User
A

Joined: Jul 2006
Posts: 503
Australia
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


Visit our development blog: http://yellloh.com
Re: View Websites in a Game [Re: Gandalf] #174513
12/27/07 15:11
12/27/07 15:11
Joined: May 2005
Posts: 107
Latvia
raymich Offline
Member
raymich  Offline
Member

Joined: May 2005
Posts: 107
Latvia
very interesting work there!

Re: View Websites in a Game [Re: raymich] #174514
12/28/07 16:13
12/28/07 16:13
Joined: Jul 2007
Posts: 103
L
Lutz_G Offline OP
Member
Lutz_G  Offline OP
Member
L

Joined: Jul 2007
Posts: 103
@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.

Re: View Websites in a Game [Re: Lutz_G] #174515
12/29/07 02:15
12/29/07 02:15
Joined: Dec 2007
Posts: 11
Z
zolyn213 Offline
Newbie
zolyn213  Offline
Newbie
Z

Joined: Dec 2007
Posts: 11
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.

Re: View Websites in a Game [Re: zolyn213] #174516
12/29/07 06:07
12/29/07 06:07
Joined: Jul 2006
Posts: 503
Australia
A
adoado Offline

User
adoado  Offline

User
A

Joined: Jul 2006
Posts: 503
Australia
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


Visit our development blog: http://yellloh.com
Re: View Websites in a Game [Re: Gandalf] #174517
01/04/08 19:30
01/04/08 19:30
Joined: Dec 2007
Posts: 54
regensburg
alleen Offline
Junior Member
alleen  Offline
Junior Member

Joined: Dec 2007
Posts: 54
regensburg
excellent job

it runs extremely slow though, with like 1 or 2 fps?

Page 2 of 3 1 2 3

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1