|
-
Nov 17th, 2002, 11:50 AM
#1
Thread Starter
Stuck in the 80s
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.
-
Nov 17th, 2002, 12:08 PM
#2
Addicted Member
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!'
-
Nov 17th, 2002, 12:10 PM
#3
Thread Starter
Stuck in the 80s
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.
-
Nov 17th, 2002, 12:15 PM
#4
Good Ol' Platypus
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)
-
Nov 17th, 2002, 12:15 PM
#5
Thread Starter
Stuck in the 80s
Code:
StretchBlt ToDC, x, y, iW, iH, picMiniBlt.hdc, 32, 0, 32, 32, SRCCOPY
That just leaves me with a white picturebox?
-
Nov 17th, 2002, 12:21 PM
#6
Thread Starter
Stuck in the 80s
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
-
Nov 17th, 2002, 12:23 PM
#7
Thread Starter
Stuck in the 80s
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?
-
Nov 17th, 2002, 12:38 PM
#8
Thread Starter
Stuck in the 80s
I converted some of the variables to double and it seemed to fix it.
Thanks for all your help.
-
Nov 17th, 2002, 04:13 PM
#9
Thread Starter
Stuck in the 80s
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.
-
Nov 17th, 2002, 04:19 PM
#10
Good Ol' Platypus
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)
-
Nov 17th, 2002, 04:20 PM
#11
Thread Starter
Stuck in the 80s
Originally posted by Sastraxi
SetStretchBltMode only has to be called once
It reverts back to the other way if I only call it once.
-
Nov 17th, 2002, 04:22 PM
#12
Good Ol' Platypus
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)
-
Nov 17th, 2002, 04:26 PM
#13
Good Ol' Platypus
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)
-
Nov 17th, 2002, 04:35 PM
#14
Thread Starter
Stuck in the 80s
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?
-
Nov 17th, 2002, 05:05 PM
#15
Good Ol' Platypus
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)
-
Nov 17th, 2002, 09:52 PM
#16
Thread Starter
Stuck in the 80s
Thanks, man. I just sent it via email.
Let me know if you can find anything.
-
Nov 17th, 2002, 11:01 PM
#17
Good Ol' Platypus
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)
-
Nov 17th, 2002, 11:17 PM
#18
Good Ol' Platypus
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: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)
-
Nov 17th, 2002, 11:21 PM
#19
Thread Starter
Stuck in the 80s
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: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.
-
Nov 17th, 2002, 11:24 PM
#20
Good Ol' Platypus
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)
-
Nov 17th, 2002, 11:26 PM
#21
Thread Starter
Stuck in the 80s
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.
-
Nov 17th, 2002, 11:44 PM
#22
Good Ol' Platypus
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)
-
Nov 18th, 2002, 09:03 AM
#23
Thread Starter
Stuck in the 80s
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?
-
Nov 18th, 2002, 03:53 PM
#24
Good Ol' Platypus
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)
-
Nov 18th, 2002, 04:11 PM
#25
Thread Starter
Stuck in the 80s
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.
-
Nov 18th, 2002, 06:50 PM
#26
Thread Starter
Stuck in the 80s
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!"
-
Nov 18th, 2002, 07:01 PM
#27
Thread Starter
Stuck in the 80s
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|