sekelsenmat
21-06-2007, 11:19 AM
Hello,
I am trying to create a surface to draw overlays with DirectX, but it always fails on the CreateSurface function with the error $88760091, that according to my google search means Invalid Pixel Format.
But I tested lot's of different pixel formats and I can't find one that works. Any ideas? here is my code, thanks
function InitOverlays(vPluginData: TPluginData; var DebugInfo: Cardinal): Cardinal;
var
ddsd, ddsdOverlay: DDSURFACEDESC2;
ddrval: HRESULT;
capsDrv: TDDCaps;
pixelFormat: DDPIXELFORMAT;
begin
Result := VMG_DXFUNCTIONFAILED;
DebugInfo := 0;
{ Init DirectDraw }
ddrval := DirectDrawCreateEx(nil, g_lpdd, IID_IDirectDraw7, nil);
if ddrval <> DD_OK then
begin
DebugInfo := $1;
Exit;
end;
{ For NORMAL cooperative level we no longer need to provide an HWND }
ddrval := g_lpdd.SetCooperativeLevel(0, DDSCL_NORMAL);
if ddrval <> DD_OK then
begin
DebugInfo := $2;
Exit;
end;
if g_lpdd = nil then
begin
DebugInfo := $3;
Exit;
end;
{ Create the primary surface }
FillChar(ddsd, sizeof(ddsd), #0);
ddsd.dwSize := sizeof(ddsd);
ddsd.dwFlags := DDSD_CAPS;
ddsd.ddsCaps.dwCaps := DDSCAPS_PRIMARYSURFACE;
ddrval := g_lpdd.CreateSurface(ddsd, g_lpddsPrimary, nil);
if ddrval <> DD_OK then
begin
DebugInfo := $4;
Exit;
end;
{ Get driver capabilities to determine Overlay support }
FillChar(capsDrv, sizeof(capsDrv), #0);
capsDrv.dwSize := sizeof(capsDrv);
ddrval := g_lpdd.GetCaps(@capsDrv, nil);
if ddrval <> DD_OK then
begin
DebugInfo := $5;
Exit;
end;
{ Does the driver support overlays in the current mode?
(Currently the DirectDraw emulation layer does not support overlays.
Overlay related APIs will fail without hardware support) }
Result := VMG_NOSUPPORTFOROVERLAYS;
if (capsDrv.dwCaps and DDCAPS_OVERLAY) = 0 then
begin
DebugInfo := $B;
Exit;
end;
{ Setup the overlay surface }
FillChar(ddsdOverlay, sizeof(ddsdOverlay), #0);
ddsdOverlay.dwSize := sizeof(ddsdOverlay);
ddsdOverlay.dwFlags := DDSD_CAPS or DDSD_HEIGHT or DDSD_WIDTH or DDSD_PIXELFORMAT;
ddsdOverlay.dwBackBufferCount := 0;
ddsdOverlay.dwWidth := vPluginData.DesktopWidth;
ddsdOverlay.dwHeight := vPluginData.DesktopHeight;
ddsdOverlay.ddsCaps.dwCaps := DDSCAPS_OVERLAY or DDSCAPS_VIDEOMEMORY;
pixelFormat.dwSize := SizeOf(pixelFormat);
pixelFormat.dwFlags := DDPF_RGB;
pixelFormat.dwFourCC := 0;
pixelFormat.dwRGBBitCount := 32;
pixelFormat.dwRBitMask := $00FF0000;
pixelFormat.dwGBitMask := $0000FF00;
pixelFormat.dwBBitMask := $000000FF;
pixelFormat.dwRGBAlphaBitMask := $00000000;
// TODO: should match the screen output color depth
//DDPIXELFORMAT pixelFormat =
// {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0};
ddsdOverlay.ddpfPixelFormat := pixelFormat;
ddrval := g_lpdd.CreateSurface(ddsdOverlay, g_lpddsOverlay, nil);
if ddrval <> DD_OK then //// Will enter this block, so here is the failure
begin
DebugInfo := ddrval;
Exit;
end;
if (g_lpddsOverlay = nil) then
begin
DebugInfo := $D;
Exit;
end;
// mPrimaryMonitorRect := System::getPrimaryMonitorRect();
Result := VMG_NOERROR;
end;
I am trying to create a surface to draw overlays with DirectX, but it always fails on the CreateSurface function with the error $88760091, that according to my google search means Invalid Pixel Format.
But I tested lot's of different pixel formats and I can't find one that works. Any ideas? here is my code, thanks
function InitOverlays(vPluginData: TPluginData; var DebugInfo: Cardinal): Cardinal;
var
ddsd, ddsdOverlay: DDSURFACEDESC2;
ddrval: HRESULT;
capsDrv: TDDCaps;
pixelFormat: DDPIXELFORMAT;
begin
Result := VMG_DXFUNCTIONFAILED;
DebugInfo := 0;
{ Init DirectDraw }
ddrval := DirectDrawCreateEx(nil, g_lpdd, IID_IDirectDraw7, nil);
if ddrval <> DD_OK then
begin
DebugInfo := $1;
Exit;
end;
{ For NORMAL cooperative level we no longer need to provide an HWND }
ddrval := g_lpdd.SetCooperativeLevel(0, DDSCL_NORMAL);
if ddrval <> DD_OK then
begin
DebugInfo := $2;
Exit;
end;
if g_lpdd = nil then
begin
DebugInfo := $3;
Exit;
end;
{ Create the primary surface }
FillChar(ddsd, sizeof(ddsd), #0);
ddsd.dwSize := sizeof(ddsd);
ddsd.dwFlags := DDSD_CAPS;
ddsd.ddsCaps.dwCaps := DDSCAPS_PRIMARYSURFACE;
ddrval := g_lpdd.CreateSurface(ddsd, g_lpddsPrimary, nil);
if ddrval <> DD_OK then
begin
DebugInfo := $4;
Exit;
end;
{ Get driver capabilities to determine Overlay support }
FillChar(capsDrv, sizeof(capsDrv), #0);
capsDrv.dwSize := sizeof(capsDrv);
ddrval := g_lpdd.GetCaps(@capsDrv, nil);
if ddrval <> DD_OK then
begin
DebugInfo := $5;
Exit;
end;
{ Does the driver support overlays in the current mode?
(Currently the DirectDraw emulation layer does not support overlays.
Overlay related APIs will fail without hardware support) }
Result := VMG_NOSUPPORTFOROVERLAYS;
if (capsDrv.dwCaps and DDCAPS_OVERLAY) = 0 then
begin
DebugInfo := $B;
Exit;
end;
{ Setup the overlay surface }
FillChar(ddsdOverlay, sizeof(ddsdOverlay), #0);
ddsdOverlay.dwSize := sizeof(ddsdOverlay);
ddsdOverlay.dwFlags := DDSD_CAPS or DDSD_HEIGHT or DDSD_WIDTH or DDSD_PIXELFORMAT;
ddsdOverlay.dwBackBufferCount := 0;
ddsdOverlay.dwWidth := vPluginData.DesktopWidth;
ddsdOverlay.dwHeight := vPluginData.DesktopHeight;
ddsdOverlay.ddsCaps.dwCaps := DDSCAPS_OVERLAY or DDSCAPS_VIDEOMEMORY;
pixelFormat.dwSize := SizeOf(pixelFormat);
pixelFormat.dwFlags := DDPF_RGB;
pixelFormat.dwFourCC := 0;
pixelFormat.dwRGBBitCount := 32;
pixelFormat.dwRBitMask := $00FF0000;
pixelFormat.dwGBitMask := $0000FF00;
pixelFormat.dwBBitMask := $000000FF;
pixelFormat.dwRGBAlphaBitMask := $00000000;
// TODO: should match the screen output color depth
//DDPIXELFORMAT pixelFormat =
// {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0};
ddsdOverlay.ddpfPixelFormat := pixelFormat;
ddrval := g_lpdd.CreateSurface(ddsdOverlay, g_lpddsOverlay, nil);
if ddrval <> DD_OK then //// Will enter this block, so here is the failure
begin
DebugInfo := ddrval;
Exit;
end;
if (g_lpddsOverlay = nil) then
begin
DebugInfo := $D;
Exit;
end;
// mPrimaryMonitorRect := System::getPrimaryMonitorRect();
Result := VMG_NOERROR;
end;