[DX9] DirectDraw Clipper problems

Irrinity

Newcomer
Joined
Feb 16, 2003
Messages
2
Hi guys,

I'm coding this fullscreen managed DirectDraw app. I use the standard flipping principle with a front and a back buffer. Now I want to draw some surfaces onto the back buffer, but clip them off the edges of the back buffer. This doesn't seem to work and gets me an UnsupportedException from DirectDraw. The next example works fine:

Visual Basic:
BackBuffer.Clipper = New Clipper()
BackBuffer.Clipper.ClipList = New Rectangle() {New Rectangle(10, 10, 100, 100)}
BackBuffer.Draw(New Rectangle(1, 1, 32, 32), SomeSurface, DrawFlags.DoNotWait)

In the above example SomeSurface gets clipped the way its supposed to be. Here comes the problem code:

Visual Basic:
BackBuffer.Clipper = New Clipper()
BackBuffer.Clipper.ClipList = New Rectangle() {New Rectangle(10, 10, 100, 100)}
BackBuffer.Draw(New Rectangle(0, 0, 32, 32), SomeSurface, DrawFlags.DoNotWait)

This gets me the UnsupportedException from DirectDraw. The only difference to both pieces of code is in the X and Y values of the drawn Surface. I just dont get it :confused: . Im sure you guys can help me out :). Thanks in advance.
 
Try this!

Hi,

I had the same problem and the solution was to set the Window property of the clipper!

Try this:

Visual Basic:
BackBuffer.Clipper = New Clipper()
[B]BackBuffer.Clipper.Window = this;[/B]
BackBuffer.Clipper.ClipList = New Rectangle() {New Rectangle(10, 10, 100, 100)}
BackBuffer.Draw(New Rectangle(0, 0, 32, 32), SomeSurface, DrawFlags.DoNotWait)
Hope this helps! :D

/John Eriksson
 
Dim clip As Clipper

'..... misc DirectDraw setup code ......

clip = New Clipper(draw)
clip.Window = Me
back.Clipper = clip

' have to draw the sprite using Draw, not DrawFast

back.Draw(destRect, mySprite, spriteRect, DrawFlags.DoNotWait Or DrawFlags.KeySource)
 
jen, btoth:

Thanks for your reply. Sadly enough your solution didn't do the job :(. Remember, I'm coding a FULLscreen app. I think the problem is that I'm drawing SomeSurface outside of the BackBuffer's surface bounds.

I did find a solution myself and works by clipping the source rectangle and the destination rectangle to the edges of the BackBuffer surface:

Visual Basic:
Dim Dst as New Rectangle(0, 0, 32, 32)
Dim Src as Rectangle
Dim C as New Rectangle(10, 10, 100, 100) 'Clip rectangle

If Dst.X < C.X Then Src.X += C.X - Dst.X
If Dst.Y < C.Y Then Src.Y += C.Y - Dst.Y
Dst.Intersect(C)
Src.Width = Dst.Width
Src.Height = Dst.Height

'Only draw if SomeSurface is visable
If Dst.Width > 0 AndAlso Dst.Height > 0 Then
    BackBuffer.Draw(Dst, SomeSurface, Src, DrawFlags.DoNotWait)
End If

This works really well :D . By clipping like this, I still have the option to use DrawFast ;) .
 
Back
Top