Irrinity Posted February 16, 2003 Posted February 16, 2003 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: 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: 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. Quote
jen Posted February 24, 2003 Posted February 24, 2003 Try this! Hi, I had the same problem and the solution was to set the Window property of the clipper! Try this: 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 Quote
btoth Posted February 25, 2003 Posted February 25, 2003 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) Quote
Irrinity Posted February 25, 2003 Author Posted February 25, 2003 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: 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 ;) . Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.