DirectDraw Overlay don't work
Posted: Fri Jan 20, 2006 6:35 am
Hi community,
i have a problem, i have started programming a overlay. I have get an c++ code and stat translating it to pb. Everything looks good but my translatet Code don't work. I get the last error on "m_overlay_surface\UpdateOverlay(0, m_primary_surface, dest_rect, m_overlay_flags, m_overlay_fx)". The return value isn't #DD_OK. And I can't solve the problem myself. Here my code:
The C++ code you can get here: http://nexe.gamedev.net/files/Overlay-2005-11-21.zip
I hope somebody can help me to fix the problem.
Thanks
Lukaso
i have a problem, i have started programming a overlay. I have get an c++ code and stat translating it to pb. Everything looks good but my translatet Code don't work. I get the last error on "m_overlay_surface\UpdateOverlay(0, m_primary_surface, dest_rect, m_overlay_flags, m_overlay_fx)". The return value isn't #DD_OK. And I can't solve the problem myself. Here my code:
Code: Select all
DataSection
IID_IDirectDraw7:
Data.l $15E65EC0
Data.w $3B9C, $11D2
Data.b $B9, $2F, $00, $60, $97, $97, $EA, $5B
EndDataSection
#DD_ROP_SPACE = 256/32
Structure DDCOLORKEY
dwColorSpaceLowValue.l
dwColorSpaceHighValue.l
EndStructure
Structure DDPIXELFORMAT
dwSize.l
dwFlags.l
dwFourCC.l
dwRGBBitCount.l
dwRBitMask.l
dwGBitMask.l
dwBBitMask.l
dwRGBAlphaBitMask.l
EndStructure
Structure DDSCAPS
dwCaps.l
EndStructure
Structure DDSCAPS2
dwCaps.l
dwCaps2.l
dwCaps3.l
dwCaps4.l
EndStructure
Structure DDSURFACEDESC2
dwSize.l
dwFlags.l
dwHeight.l
dwWidth.l
lPitch.l
dwBackBufferCount.l
dwRefreshRate.l
dwAlphaBitDepth.l
dwReserved.l
lpSurface.l
ddckCKDestOverlay.DDCOLORKEY
ddckCKDestBlt.DDCOLORKEY
ddckCKSrcOverlay.DDCOLORKEY
ddckCKSrcBlt.DDCOLORKEY
ddpfPixelFormat.DDPIXELFORMAT
ddsCaps.DDSCAPS2
dwTextureStage.l
EndStructure
Structure DDOVERLAYFX
dwSize.l
dwAlphaEdgeBlendBitDepth.l
dwAlphaEdgeBlend.l
dwReserved.l
dwAlphaDestConstBitDepth.l
StructureUnion
dwAlphaDestConst.l
lpDDSAlphaDest.IDirectDrawSurface7
EndStructureUnion
StructureUnion
dwAlphaSrcConstBitDepth.l
lpDDSAlphaSrc.IDirectDrawSurface7
EndStructureUnion
dckDestColorkey.DDCOLORKEY
dckSrcColorkey.DDCOLORKEY
dwDDFX.l
dwFlags.l
EndStructure
Structure DDCAPS
dwSize.l
dwCaps.l
dwCaps2.l
dwCKeyCaps.l
dwFXCaps.l
dwFXAlphaCaps.l
dwPalCaps.l
dwSVCaps.l
dwAlphaBltConstBitDepths.l
dwAlphaBltPixelBitDepths.l
dwAlphaBltSurfaceBitDepths.l
dwAlphaOverlayConstBitDepths.l
dwAlphaOverlayPixelBitDepths.l
dwAlphaOverlaySurfaceBitDepths.l
dwZBufferBitDepths.l
dwVidMemTotal.l
dwVidMemFree.l
dwMaxVisibleOverlays.l
dwCurrVisibleOverlays.l
dwNumFourCCCodes.l
dwAlignBoundarySrc.l
dwAlignSizeSrc.l
dwAlignBoundaryDest.l
dwAlignSizeDest.l
dwAlignStrideAlign.l
dwRops.l[#DD_ROP_SPACE]
ddsOldCaps.DDSCAPS
dwMinOverlayStretch.l
dwMaxOverlayStretch.l
dwMinLiveVideoStretch.l
dwMaxLiveVideoStretch.l
dwMinHwCodecStretch.l
dwMaxHwCodecStretch.l
dwReserved1.l
dwReserved2.l
dwReserved3.l
dwSVBCaps.l
dwSVBCKeyCaps.l
dwSVBFXCaps.l
dwSVBRops.l[#DD_ROP_SPACE]
dwVSBCaps.l
dwVSBCKeyCaps.l
dwVSBFXCaps.l
dwVSBRops.l[#DD_ROP_SPACE]
dwSSBCaps.l
dwSSBCKeyCaps.l
dwSSBFXCaps.l
dwSSBRops.l[#DD_ROP_SPACE]
dwMaxVideoPorts.l
dwCurrVideoPorts.l
dwSVBCaps2.l
dwNLVBCaps.l
dwNLVBCaps2.l
dwNLVBCKeyCaps.l
dwNLVBFXCaps.l
dwNLVBRops.l[#DD_ROP_SPACE]
ddsCaps.DDSCAPS2
EndStructure
#DD_OK = $00000000
#DDSCL_NORMAL = $00000008
#DDPF_RGB = $00000040
#DDOVER_SHOW = $00000002
#DDFLIP_WAIT = $00000001
#DDSD_CAPS = $00000001
#DDSD_HEIGHT = $00000002
#DDSD_WIDTH = $00000004
#DDSD_BACKBUFFERCOUNT = $00000020
#DDSD_PIXELFORMAT = $00001000
#DDCAPS_OVERLAY = $00000800
#DDSCAPS_BACKBUFFER = $00000004
#DDSCAPS_COMPLEX = $00000008
#DDSCAPS_FLIP = $00000010
#DDSCAPS_OVERLAY = $00000080
#DDSCAPS_PRIMARYSURFACE = $00000200
#DDSCAPS_VIDEOMEMORY = $00004000
#DDERR_EXCLUSIVEMODEALREADYSET = 2289435205
#DDERR_WRONGMODE = 2289435211
#DDCKEYCAPS_SRCOVERLAY = $00002000
#DDOVER_KEYSRCOVERRIDE = $00002000
#DDOVER_DDFX = $00080000
Declare initialize_surfaces()
Declare cleanup()
Declare initialize()
Global m_direct_draw.IDirectDraw7
Global m_caps.DDCAPS
Global m_primary_surface.IDirectDrawSurface7
Global m_overlay_surface.IDirectDrawSurface7
Global m_surfaces_lost.b
Global m_overlay_flags.l
Global m_overlay_back_surface.IDirectDrawSurface7
Global m_overlay_fx.DDOVERLAYFX
Global ddsd.DDSURFACEDESC2
Global OVERLAY_WIDTH, OVERLAY_HEIGHT
OVERLAY_WIDTH = 256
OVERLAY_HEIGHT = 64
Procedure overlay_renderer_t()
If OpenLibrary(0, "ddraw.dll")
If CallFunction(0, "DirectDrawCreateEx", 0, @m_direct_draw, ?IID_IDirectDraw7, 0) = #DD_OK
m_caps\dwSize = SizeOf(DDCAPS)
m_direct_draw\GetCaps(@m_caps, 0)
ProcedureReturn #True
EndIf
EndIf
EndProcedure
Procedure support_available()
num_visible_overlays.l = 0
If m_overlay_surface
num_visible_overlays = m_caps\dwCurrVisibleOverlays - 1
EndIf
If m_caps\dwMaxVisibleOverlays > num_visible_overlays And m_caps\dwCaps & #DDCAPS_OVERLAY
ProcedureReturn #True
Else
ProcedureReturn #False
EndIf
EndProcedure
Procedure initialize()
m_direct_draw\SetCooperativeLevel(0, #DDSCL_NORMAL)
ddsd.DDSURFACEDESC2
ddsd\dwSize = SizeOf(DDSURFACEDESC2)
ddsd\dwFlags = #DDSD_CAPS
ddsd\ddsCaps\dwCaps = #DDSCAPS_PRIMARYSURFACE
m_direct_draw\CreateSurface(ddsd, @m_primary_surface, 0)
initialize_surfaces()
EndProcedure
Procedure update()
hr.l = m_direct_draw\TestCooperativeLevel()
If hr <> #DD_OK
Select hr
Case #DDERR_EXCLUSIVEMODEALREADYSET
m_surfaces_lost = #True
Delay(1000)
ProcedureReturn #False
Case #DDERR_WRONGMODE
cleanup()
initialize()
EndSelect
EndIf
If m_surfaces_lost
m_direct_draw\RestoreAllSurfaces()
m_surfaces_lost = #False
EndIf
dc.l = 0
str.s = "This is overlayed text"
m_overlay_back_surface\GetDC(@dc)
SetTextColor_(dc, RGB(255, 255, 255))
SetBkColor_(dc, RGB(0, 0, 0))
TextOut_(dc, 5, 5, @str, Len(str))
m_overlay_back_surface\ReleaseDC(dc)
m_overlay_surface\Flip(0, #DDFLIP_WAIT)
dest_rect.RECT
dest_rect\left = 0
dest_rect\top = 0
dest_rect\right = OVERLAY_WIDTH
dest_rect\bottom = OVERLAY_HEIGHT
m_overlay_flags = #DDOVER_SHOW
If m_caps\dwCKeyCaps & #DDCKEYCAPS_SRCOVERLAY
m_overlay_fx\dckDestColorkey\dwColorSpaceLowValue = 0
m_overlay_fx\dckDestColorkey\dwColorSpaceHighValue = 0
m_overlay_flags = m_overlay_flags | #DDOVER_DDFX | #DDOVER_KEYSRCOVERRIDE
EndIf
m_overlay_surface\UpdateOverlay(0, m_primary_surface, dest_rect, m_overlay_flags, m_overlay_fx)
EndProcedure
Procedure initialize_surfaces()
ddsd.DDSURFACEDESC2
ddsd\dwSize = SizeOf(DDSURFACEDESC2)
ddsd\dwFlags = #DDSD_CAPS | #DDSD_HEIGHT | #DDSD_WIDTH | #DDSD_BACKBUFFERCOUNT | #DDSD_PIXELFORMAT
ddsd\ddsCaps\dwCaps = #DDSCAPS_OVERLAY | #DDSCAPS_FLIP | #DDSCAPS_COMPLEX | #DDSCAPS_VIDEOMEMORY
ddsd\dwBackBufferCount = #True
ddsd\dwWidth = OVERLAY_WIDTH
ddsd\dwHeight = OVERLAY_HEIGHT
ddsd\ddpfPixelFormat\dwSize = SizeOf(DDPIXELFORMAT)
ddsd\ddpfPixelFormat\dwFlags = #DDPF_RGB
ddsd\ddpfPixelFormat\dwRGBBitCount = 32
ddsd\ddpfPixelFormat\dwRBitMask = $00FF0000
ddsd\ddpfPixelFormat\dwGBitMask = $0000FF00
ddsd\ddpfPixelFormat\dwBBitMask = $000000FF
ddscaps.DDSCAPS2
m_direct_draw\CreateSurface(ddsd, @m_overlay_surface, 0)
ddscaps\dwCaps = #DDSCAPS_BACKBUFFER
m_overlay_surface\GetAttachedSurface(ddscaps, @m_overlay_back_surface)
m_overlay_fx\dwSize = SizeOf(DDOVERLAYFX)
EndProcedure
Procedure cleanup()
m_overlay_surface = 0
m_primary_surface = 0
m_surfaces_lost = #False
EndProcedure
If overlay_renderer_t()
If support_available()
initialize()
Repeat
update()
Delay(0)
ForEver
EndIf
CloseLibrary(0)
EndIf
I hope somebody can help me to fix the problem.
Thanks

Lukaso