[DX9] DirectDraw Clipper problems

Irrinity

New member
Joined
Feb 16, 2003
Messages
2
Hi guys,

Im 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 doesnt seem to work and gets me an UnsupportedException from DirectDraw. The next example works fine:

Code:
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:

Code:
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:

[VB]
BackBuffer.Clipper = New Clipper()
BackBuffer.Clipper.Window = this;
BackBuffer.Clipper.ClipList = New Rectangle() {New Rectangle(10, 10, 100, 100)}
BackBuffer.Draw(New Rectangle(0, 0, 32, 32), SomeSurface, DrawFlags.DoNotWait)
[/VB]
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 didnt do the job :(. Remember, Im coding a FULLscreen app. I think the problem is that Im drawing SomeSurface outside of the BackBuffers 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:

Code:
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