Results 1 to 12 of 12

Thread: DirectDraw clippers in fullscreen?*CONTINUED*

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Great White North, ey?
    Posts
    202

    Exclamation DirectDraw clippers in fullscreen?*CONTINUED*

    I searched everywhere, even planet source code doesn't have anything on the subject. Is it even possible? I know there is a sample on dx4vb but I can't use that cause my engine is very different. Anybody know how clippers can be used in fullscreen mode so that the sprites don't just disappear off screen when they get to the edge, but leave gradualy?

    Thanks.
    Last edited by Dude1; Jan 20th, 2003 at 10:20 AM.

  2. #2
    Addicted Member
    Join Date
    Aug 2002
    Location
    Baltimore, MD
    Posts
    230
    Normally, most people do their own clipping in full-screen games. The DirectDrawClipper usually slows down a game more than implementing your own clipping.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Great White North, ey?
    Posts
    202

    Unhappy

    Sorry from bringing this thread back, but how would you go about making your own clipping? Would you need to detect when the sprite is about to leave the screen area and then somehow gradually chop it off so that the edge of the sprite never touches the edge of the screen? How would you do that? Just subtract from the right and left properties of the sprite?

    Thanks.

  4. #4
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    I've got an EXTREMELY efficient piece of clipping code for VB. It's as efficient as I can get it, anyway...
    VB Code:
    1. Dim ObjRect As RECT
    2. Dim ScreenRect As RECT
    3. Dim visix As Boolean, visiy As Boolean, visix2 As Boolean, visiy2 As Boolean, visi As Boolean
    4.  
    5.  
    6. With ScreenRect
    7.     .Right = ScreenWidth - 1
    8.     .Bottom = ScreenHeight - 1
    9. End With
    10.  
    11. With RECT_OF_OBJECT
    12.     'add in your data    
    13.     visix = ((Abs(.Left) - .Left) = 0)
    14.     visiy = ((Abs(.Top) - .Top) = 0)    
    15.     visix2 = Not (.Right >= nWidth)
    16.     visiy2 = Not (.bottom >= nHeight)
    17.     visi = visix And visix2 And visiy And visiy2
    18. End With
    19.  
    20. If visi Then Render(OBJECT)
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Great White North, ey?
    Posts
    202
    Thanks, but I don't understand what I should replace the (OBJECT) with in the last line

    I've replaced ScreenWidth and ScreenHeight with 800 and 600 cause thats the resolution my game uses. Then I replaced nWidth and nHeight with the width and height of my object I'm trying to clip. I've changed "With RECT_OF_OBJECT" to With "rBlock1"

    But what do you mean by Render (OBJECT) if I replace it with "Block1" which I defined as Dim Block1 As DirectDrawSurface7
    it gives me an error, if I replace it with "rBlock1" which is the rect, I also get an error. What should I put in there?

    Thanks

  6. #6
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Yes, can you try to expplain the logic behind that code Sastraxi...

  7. #7
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Originally posted by Sastraxi
    I've got an EXTREMELY efficient piece of clipping code for VB. It's as efficient as I can get it, anyway...
    VB Code:
    1. Dim ObjRect As RECT
    2. Dim ScreenRect As RECT
    3. Dim visix As Boolean, visiy As Boolean, visix2 As Boolean, visiy2 As Boolean, visi As Boolean
    4.  
    5.  
    6. With ScreenRect
    7.     .Right = ScreenWidth - 1
    8.     .Bottom = ScreenHeight - 1
    9. End With
    10.  
    11. With RECT_OF_OBJECT
    12.     'add in your data    
    13.     visix = ((Abs(.Left) - .Left) = 0)
    14.     visiy = ((Abs(.Top) - .Top) = 0)    
    15.     visix2 = Not (.Right >= ScreenRect.Right)
    16.     visiy2 = Not (.bottom >= ScreenRect.Bottom)
    17.     visi = visix And visix2 And visiy And visiy2
    18. End With
    19.  
    20. If visi Then You_Can_Render_This_Object_So_Do_So!
    I've changed a few things (nWidth = ScreenRect.Right, nHeight = ScreenRect.Bottom), and I think I've now made it perfectly clear what I mean by Render(OBJECT)
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  8. #8
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Just remembered something. If you want this to be a clipper, you need to change all RECT_OF_OBJECT.Right with .Left, .Bottom with .Top (but only for that RECT). I copied this code from one where this was used to check collision with the wall.

    And here's the logic:

    visix: If the absolute (above zero) version of the number is different than the original version, it's under 0 (non-absolute), and thus shouldn't be drawn.

    visiy: same as visix, on the y axis

    visix2: If the number is over or equal to the screen's width, it will return true. However, since this is a visibility check we'll inverse this to make the check FALSE.

    Here's some further optimised, and fixed, code:
    VB Code:
    1. Dim ObjRect As RECT
    2. Dim ScreenRect As RECT
    3. Dim visix As Boolean, visiy As Boolean, visix2 As Boolean, visiy2 As Boolean, visi As Boolean
    4.  
    5. With ScreenRect
    6.     .Right = ScreenWidth
    7.     .Bottom = ScreenHeight
    8. End With
    9.  
    10. With RECT_OF_OBJECT
    11.     'add in your data    
    12.     visix = ((Abs(.Right + 1) - .Right + 1) = 0)
    13.     visiy = ((Abs(.Bottom + 1) - .Bottom + 1) = 0)
    14.     visix2 = (.Left < ScreenRect.Right)
    15.     visiy2 = (.Top < ScreenRect.Bottom)
    16.     visi = visix And visix2 And visiy And visiy2
    17. End With
    18.  
    19. If visi Then You_Can_Render_This_Object_So_Do_So!
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  9. #9
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    LOL, just saw what you were trying to do, sorry... all this does is check if a sprite is off the screen. However, you can use BLTFast that doesn't stretch the sprite to do this. Simply change the rect!
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Great White North, ey?
    Posts
    202

    Question

    Thats some pretty advanced code just to check if sprite is off screen. My code would look something like- If sprite.x => 800 and sprite.y => 600 then Sprite_IS_Of_Screen LOL

    This is how I blit all my objects: backbuffer.BltFast SpriteX + sx1, SpriteY + sy1, SpriteSurf, rSpriteSurf, DDBLTFAST_SRCCOLORKEY Or DDBLTFAST_WAIT

    the sx1 and sy1 are for the sliding background so that the sprites don't leave a trail.

    I'm afraid I don't understand what you mean by changing the rect. Do you mean subtaract from it when sprite gets close to the edge of the screen? like rSpriteSurf.Left = rSpriteSurf.Left - 1 ?

    Thanks again.

  11. #11
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Wait, you will have to useBLT instead of BLTFAST. When it gets close to the left, take away 1 from the width of the rect, and add 1 to the offset of the RECT that takes data from the source image. Do this for each edge and you'll be done.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Great White North, ey?
    Posts
    202

    Unhappy

    Well, here is my little program. It is suppose to be a sliding world where the red circle is the main character. I did a clipping check on the big red block which is blitted to the background, but it still disappears when it touches any edge of the screen. Can someone please take a look and see what I'm doing wrong. You'll find all the clipping code under "CheckClip" sub.

    Thanks a lot.
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width