I translated the DDraw.h from WM6 but I always fail on create surface,
even example from WM SDK still fail while creating surface.(I deploy the example in VS)
But the example from here can use directdraw on both emulator and my HTC Touch.
http://www.codeproject.com/KB/mobile/Caleidoscope.aspx
my direct draw code:
Code:
var
Form1 : TForm1;
m_pdd : IDirectDraw;
m_ddsd : TDDSURFACEDESC ;
m_psurf : IDirectDrawSurface ;
m_psurf2 : IDirectDrawSurface ;
m_cbpp : DWORD;
m_xpitch : longint;
m_ypitch : longint;
m_framebufwidth : DWORD;
m_framebufheight : DWORD;
aimage : TPicture;
...
procedure TForm1.FormCreate(Sender: TObject);
Var mResult : HResult;
begin
mResult := DirectDrawCreate(nil,m_pdd ,nil);
if mResult <> DD_OK then exit;
mResult := m_pdd.SetCooperativeLevel(Handle,DDSCL_FULLSCREEN);
if mResult <> DD_OK then
begin
m_pdd._Release;
m_pdd := nil;
exit;
end;
m_psurf := nil;
end;
...
procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
try
m_psurf._Release;
m_psurf := nil;
m_pdd._Release;
m_pdd := nil;
except
end;
end;
...
procedure TForm1.Timer1Timer(Sender: TObject);
var DF: TDDBltFX;
mResult : HResult;
pbuf : pwidechar;
buf : array [0 .. 255] of widechar;
mhdc : HDC;
begin
if m_psurf = nil then
begin
ZeroMemory(@m_ddsd, sizeof(m_ddsd));
m_ddsd.dwSize:= sizeof(m_ddsd);
m_ddsd.dwFlags:=DDSD_CAPS or DDSD_PIXELFORMAT;
m_ddsd.ddsCaps.dwCaps:= DDSCAPS_PRIMARYSURFACE ;
m_ddsd.ddpfPixelFormat.dwSize:= sizeof(DDPIXELFORMAT);
m_ddsd.ddpfPixelFormat.dwFlags:=DDPF_RGB;
mResult := m_pdd.CreateSurface(m_ddsd, m_psurf2,nil); //<----Always Fail Here
if mResult <> DD_OK then
begin
timer1.Enabled:=false;
m_pdd._Release;
m_pdd := nil;
exit;
end;
//load image from file
pbuf := pwidechar(buf);
GetModuleFileName(null,pbuf,255);
aimage.LoadFromFile(buf1+'tmp.jpg');
ZeroMemory(@m_ddsd, sizeof(m_ddsd));
m_ddsd.dwSize:= sizeof(m_ddsd);
mResult := m_psurf.Lock(nil,m_ddsd,DDLOCK_WAITNOTBUSY, 0);
if mResult <> DD_OK then
begin
m_psurf._Release;
m_psurf := nil;
m_pdd._Release;
m_pdd := nil;
exit;
end;
m_cbpp :=m_ddsd.ddpfPixelFormat.dwRGBBitCount;
m_xpitch :=m_ddsd.lXPitch;
m_ypitch :=m_ddsd.lPitch;
m_framebufwidth :=m_ddsd.dwWidth;
m_framebufheight :=m_ddsd.dwHeight;
m_psurf.GetDC(mHDC);
BitBlt(mHDC,0,0,320,240,aimage.Bitmap.Canvas.Handle,0, 0, SRCCOPY);
m_psurf.ReleaseDC(mHDC);
m_psurf.Unlock(nil);
end;
m_ddsd.dwSize := sizeof(m_ddsd);
mResult := m_psurf.Lock(nil,m_ddsd,DDLOCK_WAITNOTBUSY, 0);
if mResult <> DD_OK then
begin
m_psurf._Release;
m_psurf := nil;
m_pdd._Release;
m_pdd := nil;
exit;
end;
//fill 0! clear scr
//DF.dwsize := SizeOf(DF);
//DF.dwFillColor := 0;
//m_psurf.Blt(srcrect,nil,destrect,DDBLT_COLORFILL or DDBLT_WAITNOTBUSY, DF);
//DF.dwROP:= SRCCOPY;
//m_psurf.Blt(srcrect,m_psurf2,destrect,DDBLT_ROP,DF);
m_psurf.Unlock(nil);
end;
Bookmarks