Results 1 to 27 of 27

Thread: BitBlt vs PaintPicture

  1. #1

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    BitBlt vs PaintPicture

    I was using PaintPicture to draw a 'Mini Map' for my game, but I wanted to make it show all the characters positions. When I added that, it was slow as hell.

    So I decided to switch everything over to BitBlt in the game, but the Mini Map part of it just ends up looking like ass.

    I attached an example so you can see the differences. Can anyone figure out what I'm doing wrong?

    Edit: Attachment removed until I find out whether or not Jupitermedia will own it if I post it.
    Last edited by The Hobo; Nov 21st, 2002 at 07:56 PM.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  2. #2
    Addicted Member
    Join Date
    Oct 2002
    Location
    Somewhere out in space
    Posts
    151
    this is because you try to resize your source bmp when blitting. Paintpicture can do it, but not bitblt. I've changed the bitblt calls for stretchblt calls and it worked great.

    - Valkan
    'You keep creatures in cages and release them to fight? That's sick!'

  3. #3

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by Valkan
    this is because you try to resize your source bmp when blitting. Paintpicture can do it, but not bitblt. I've changed the bitblt calls for stretchblt calls and it worked great.

    - Valkan
    Thanks, Valkan, I don't know why I didn't think to try that. I'll give it a whirl and let you know how it turned out.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  4. #4
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Also, use the SetStretchBltMode API to set it to COLOR_ON_COLOR; then it looks GREAT
    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
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Code:
    StretchBlt ToDC, x, y, iW, iH, picMiniBlt.hdc, 32, 0, 32, 32, SRCCOPY
    That just leaves me with a white picturebox?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  6. #6

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by The Hobo
    Code:
    StretchBlt ToDC, x, y, iW, iH, picMiniBlt.hdc, 32, 0, 32, 32, SRCCOPY
    That just leaves me with a white picturebox?
    Nevermind! Found my mistake
    My evil laugh has a squeak in it.

    kristopherwilson.com

  7. #7

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Valkan, that works great! Sastraxi, thanks for adding that. It makes it look much better.

    But one more question. The Stretch Blitted map seems to be off a little. The Width and Height seem to be more than the box itself.

    Any ideas on that?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  8. #8

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I converted some of the variables to double and it seemed to fix it.

    Thanks for all your help.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  9. #9

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Problem, again: when I use SetStretchBltMode, it really, slows down the game.

    The MiniMap is being refreshed everytime the user moves his character, or whenever the "bad guy" moves around, so SetStretchBltMode is being called very frequently. And this really slows it down.

    And of course, without it, the map looks like ass.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  10. #10
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    SetStretchBltMode only has to be called once
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  11. #11

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by Sastraxi
    SetStretchBltMode only has to be called once
    It reverts back to the other way if I only call it once.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  12. #12
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Really? That's the first I've heard of this behaviour. Let me go check...
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  13. #13
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Okay, if you use a different destination DC for it, you'll have to call it each time. But if not, you only have to call it once. Are you just bltting it to a Picturebox's .hDC property? If so, try using .AutoRedraw = True, and calling .Refresh after the call.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  14. #14

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Damn. Now I'm not sure if it's SetStretchBltMode or StretchBlt causing the lag.

    If I attach my whole project (isn't large), could you give it a look and see what you can find out?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  15. #15
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Yeah, I could! If you don't want to post it publicly, you can email it to me:

    [email protected]
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  16. #16

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Thanks, man. I just sent it via email.

    Let me know if you can find anything.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  17. #17
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Sorry I wasn't on; I was watching Patriot Games (great movie eh?). So I'll take a look..
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  18. #18
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    I looked over your code, and I see a lot of redundancies (or maybe it's just that I don't understand how you're thinking in this case). Anyway, look at the code:
    VB Code:
    1. DrawGuy Index
    Index doesn't matter. In no place in the DrawGuy routine do you ever draw the index that you are given, you just loop through and draw both guys. When this is in the KeyUp event (which, for the sake of responsiveness, should be in KeyDown), it is done BEFORE the map and minimap are drawn. In the timer, both are drawn after the map. This shows me where the delay is, it's that your character will only be drawn during the timer. I'll tweak it a bit, add some comments where I changed code, and send it back to you.

    If you have any questions after that, just ask!
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  19. #19

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by Sastraxi
    I looked over your code, and I see a lot of redundancies (or maybe it's just that I don't understand how you're thinking in this case). Anyway, look at the code:
    VB Code:
    1. DrawGuy Index
    Index doesn't matter. In no place in the DrawGuy routine do you ever draw the index that you are given, you just loop through and draw both guys.
    Yeah, I know about that one. I'm just too lazy to fix it. At one point, the index did matter, but I changed the code and eventually it wasn't use and it's just still chilling there.

    Originally posted by Sastraxi
    When this is in the KeyUp event (which, for the sake of responsiveness, should be in KeyDown), it is done BEFORE the map and minimap are drawn. In the timer, both are drawn after the map. This shows me where the delay is, it's that your character will only be drawn during the timer. I'll tweak it a bit, add some comments where I changed code, and send it back to you.

    If you have any questions after that, just ask!
    Not sure I follow all that, but I'll look through the code and it'll probably make sense.

    Thanks for giving it a look.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  20. #20
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Hold tight - the code should be coming in about 20 minutes or so Probably a bit less.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  21. #21

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by Sastraxi
    Hold tight - the code should be coming in about 20 minutes or so Probably a bit less.
    Alright I'm gonna have to hit the sack in a few minutes, though. I need to get up and write me an English paper before school tomorrow. So I probably wont catch it until tomorrow after my classes.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  22. #22
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Uh, I was just writing the code when it hit me - you're using TransparentBlt. Never mind whatever else I was saying - it's tired and ought to goto sleep... man what did I just say? IT'S TIRED? Oh well...

    But TransparentBleck has a memoy leakm and thus shouldnt be used. It's a really, really badly behaved function.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  23. #23

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by Sastraxi
    Uh, I was just writing the code when it hit me - you're using TransparentBlt. Never mind whatever else I was saying - it's tired and ought to goto sleep... man what did I just say? IT'S TIRED? Oh well...

    But TransparentBleck has a memoy leakm and thus shouldnt be used. It's a really, really badly behaved function.
    Damn. I've never had a problem with it before?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  24. #24
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Well, it does. Play your game for a while, then try to move the form...

    But hey, I may be mistaken, and it was only on Win98 first edition (do you have Win98SE?) It might have been fixed in later OS'. Once again I'm not too sure. Also, the timer thing still applies.

    Here's what I think you should do. When YOUR person moves, update the whole map and draw the person and badguy in new position. When the badguy moves, only redraw the block the badguy was on, and blit him to where he moves to. Pretty simple, yet pretty darn effective.

    Tell me how you do with that method, any other suggestions I might've had would've required massive rewrites.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  25. #25

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by Sastraxi
    Well, it does. Play your game for a while, then try to move the form...

    But hey, I may be mistaken, and it was only on Win98 first edition (do you have Win98SE?) It might have been fixed in later OS'. Once again I'm not too sure. Also, the timer thing still applies.

    Here's what I think you should do. When YOUR person moves, update the whole map and draw the person and badguy in new position. When the badguy moves, only redraw the block the badguy was on, and blit him to where he moves to. Pretty simple, yet pretty darn effective.

    Tell me how you do with that method, any other suggestions I might've had would've required massive rewrites.
    Yeah, I did some searching and found out about the TransparentBlt. I'm running ME on this machine, resources are: System: 46%, User: 46%, GDI: 54%.

    When I leave it running for a few minutes, resources are: System: 44%, User: 44%, GDI: 58%.

    That's some good advice about blitting only the moving guy. Although when my guy moves, I'll also have to redo the whole map, because the X, and Y of the map changes as the user moves.

    But I'm pretty sure it could be fixed nicely.

    Also, I know how to transparently use BitBlt with masks, but my searching of how to do with with colors other than black and white have come up with nothing. Do you know how to do that?

    Just because it's fixed in ME, it's still a problem in 98 and still doesn't exist for 95.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  26. #26

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Alright. I just got rid of TransparentBlt. Now I'm going to try to optimize the way it updates the map, like you suggested.

    But I'm stuck. I screwed something up, and now everytime I try to use my COORD UDT, it gives me mismatch errors.

    "Argh!" says The Hobo, "argh!"
    My evil laugh has a squeak in it.

    kristopherwilson.com

  27. #27

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Hey Sastraxi. When I comment out all the DrawMini code so the MiniMap is never drawn, it runs as fast as it used to. So it's something with drawing that map that kills it.

    I'm going to try to optimize that first so it just draws over the old spot and draws the new spot for the characters.
    My evil laugh has a squeak in it.

    kristopherwilson.com

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