How to reuse the DirectSurface Object?(DX7)

kenl
05-31-2002, 11:54 PM
Hi!
I want to reuse the same DirectDraw surface again, but how to
clear the buffer and reload it?
I reload another image, and i can get the image width, height..
,but CAN NOT blt ??? (blt nothing)
Help, Thanks!

e.g

public DD as DirectDraw7
public DDS1 as DirectDrawSurface7

Sub Main()
...
Set DDS1 = DD.CreateSurfaceFromFile(PathName, DDSDesc)
....
Do
....
Call P1
....
Loop
End Sub

Sub P1()
....
DDS1.restore
set DDS1 = nothing

'// CAN LOAD THE IMAGE, BUT BLT NOTHING ?!
Set DDS1 = DD.CreateSurfaceFromFile(PathName2, DDSDesc2)
....
End Sub

kenl
06-01-2002, 08:35 AM
Hi:
How to reuse the same var of DXDrawSurface(DX7)?
I create a surface from the file and can blt, set it to nothing and
load it from other file again. This time can NOT bit?? But I can get
the correct surface information(height, weight)! Why?
Why bit nothing? Help please! Thanks!!


e.g
Public DD as DirectDraw7
Public DDS1 as DirectDrawSurface7
Public Primary as DirectDrawSurface7

Sub Main
....
Set DDS1 = DD.CreateSurfaceFromFile(PathName1, DDSDecs1)
....
'//IT IS OK CAN SEE SOMETHING!
Primary.blt R1, DDS1, R2, DDBLT_WAIT
....
Call P1
....
//BLT NOTHING, WHY?(But i can get surface information)
Primary.blt R1, DDS1, R2, DDBLT_WAIT
End Sub



Sub P1
DDS1.restore
Set DDS1 = Nothing '//SOMETHING WRONG?!

Set DDS1 = DD.CreateSurfaceFromFile(PathName2, DDSDecs2)
End Sub

AndreRyan
06-02-2002, 12:26 AM
Is DDSDESC1 public? Try posting the entire section of the project.

I don't see what's wrong but you could try this


Sub P1()
Dim TempDesc As DDSURFACEDESC2, TempSurf As DirectDrawSurface7
With TempDesc
.lFlags = DDSD_CAPS
.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
End With

Set TempSurf = DirectDraw.CreateSurfaceFromFile(File2, TempDesc)

Dim R1 As RECT, R2 as RECT
R1.Left = 0
R1.Top = 0
R1.Right = TempDesc.lWidth
R1.Bottom = TempDesc.lHeight

R2.Top = 0
R2.Left = 0
R2.Bottom = DDSDESC2.lHeight
R2.Right = DDSDESC2.lWidth

DDS1.Blt R1, TempSurf, R2, DDBLT_WAIT
End Sub

kenl
06-02-2002, 01:36 PM
Thanks AndreRyan

My code is same as yours. so the same results

But finally I can blt the picture, because i have try to Set ColorKey.

I don't know why must set the ColorKey?!(May be the display mode

is window mode?!)

Anywhere, Thanks AndreRyan ! :D

Squirm
06-02-2002, 03:47 PM
Can you post the code where the flags for DDSDecs1 and DDSDecs2 are set? I have never experienced a problem with reloading a surface.

AndreRyan
06-03-2002, 01:58 AM
I don't know why that helped. The Color Key is used to set transparency(to make it so you can see through a certain range of colors)

kenl
06-04-2002, 07:21 AM
Squirm:
This is the code.



Public Sub DXw_Init(frmhWnd As Long, PicBoxhWnd)
Dim r1 As RECT

On Error GoTo ErrHandler:
KDXw_InitOK = False
Set DD = DX.DirectDrawCreate("")
Call DD.SetCooperativeLevel(frmhWnd, DDSCL_NORMAL)

PR_DDSD.lFlags = DDSD_CAPS
PR_DDSD.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE
Set Primary = DD.CreateSurface(PR_DDSD)

Primary.GetSurfaceDesc PR_DDSD
OS_DDSD.lFlags = DDSD_HEIGHT Or DDSD_WIDTH
OS_DDSD.lWidth = PR_DDSD.lWidth
OS_DDSD.lHeight = PR_DDSD.lHeight
Set OffScreen = DD.CreateSurface(OS_DDSD)
SetTPColor OffScreen, RGB(0, 255, 0), RGB(0, 255, 0)

r1.Left = 0
r1.Top = 0
r1.Right = OS_DDSD.lWidth
r1.Bottom = OS_DDSD.lHeight
OffScreen.BltColorFill r1, vbBlack

Set ddClipper = DD.CreateClipper(0)
ddClipper.SetHWnd PicBoxhWnd
Primary.SetClipper ddClipper

KDXw_InitOK = True
Exit Sub

ErrHandler:
MsgBox "Unable to initialize DirectDraw - Closing program(" & Error & ")", vbInformation, "error"
End

End Sub


Public Function SetOffScreenPlan(ByVal PathName As String) As DirectDrawSurface7
On Error GoTo ERRORHANDLER

Dim Tmp As DDSURFACEDESC2
With Tmp
.lFlags = DDSD_CAPS
.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
End With
Set SetOffScreenPlan = DD.CreateSurfaceFromFile(PathName, Tmp)
Exit Function

ERRORHANDLER:
MsgBox "Create DirectDrawSurface fail! (" & pathname & ")"
End Function

Public Sub SetTPColor(Surface As DirectDrawSurface7, ByVal HighColor As Long, ByVal LowColor As Long)
Dim TPColorKey As DDCOLORKEY
With TPColorKey
.high = HighColor
.low = LowColor
End With
Surface.SetColorKey DDCKEY_SRCBLT, TPColorKey
End Sub

Sub Main
...
Set PicSurface = SetOffScreenPlan(PicFilename1)
SetTPColor PicSurface, RGB(0, 255, 0), RGB(0, 255, 0)
...

PicSurface.Restore '//Restore surface without lack mem
Set PicSurface = Nothing '//Clear Surface

'//Reload it with other Picture file
Set PicSurface = SetOffScreenPlan(PicFilename2)
SetTPColor PicSurface, RGB(0, 255, 0), RGB(0, 255, 0)
...
End Sub

Squirm
06-04-2002, 08:36 AM
Your code works fine.
Maybe you could zip up the project and attach it.

Things to point out:
Public Sub DXw_Init(frmhWnd As Long, PicBoxhWnd As Long)
Otherwise it will be a variant.

RGB(0, 255, 0) can be substituted for vbMagenta

kenl
06-04-2002, 09:15 PM
Thanks!

But if do not set the color key, the picture can not be Blt!(I have test it)

I don't know why? So just set the color key and blt it!

JimCamel
07-04-2002, 08:06 AM
Originally posted by Squirm
RGB(0, 255, 0) can be substituted for vbMagenta

Actually RGB(0,255,0) is the same as vbGreen
vbMagenta is RGB(255,0,255)
Jim

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum