Results 1 to 13 of 13

Thread: BitBlt-ing and then what?!?!

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636

    Exclamation BitBlt-ing and then what?!?!

    Hi,

    In my game, my drawing are done by BitBlt and SetPixel on a picturebox. When my window is on the back of other windows when I come back it's all gone, the drawing are erased!!!
    I tried to draw it again in the Got_Focus event but no use!

    What do BitBlted games do to avoid this?

    Thank you,
    Arie.

  2. #2
    Zaei
    Guest
    Set AutoRedraw to true.

    Z.

  3. #3
    Addicted Member Janus's Avatar
    Join Date
    Aug 2001
    Location
    California
    Posts
    221
    Also, call the .Refresh method after you're done drawing, to update the screen.
    "1 4m 4 1337 #4xz0r!'
    Janus

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636
    Ok, done.

    but now I have missed something:

    In my game I use this code to get a lower light to the picture, and when I had AutoRedrew = False I was able to see the light changing but now I don't see anything:
    VB Code:
    1. Public Type LongPixel
    2.    Value As Long
    3. End Type
    4. Public Type RGBAPixel
    5.    Red As Byte
    6.    Green As Byte
    7.    Blue As Byte
    8.    Alpha As Byte
    9. End Type
    10. Public Declare Function SetPixelV Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
    11.  
    12.     Dim LPixel As LongPixel, BPixel As RGBAPixel
    13.     Dim I As Integer, J As Integer
    14.    
    15.     For I = 0 To 320
    16.         For J = 0 To 320
    17.             LPixel.Value = GetPixel(Form1.picMain.hdc, J, I)
    18.             LSet BPixel = LPixel
    19.             BPixel.Red = BPixel.Red \ iLight
    20.             BPixel.Green = BPixel.Green \ iLight
    21.             BPixel.Blue = BPixel.Blue \ iLight
    22.             LSet LPixel = BPixel
    23.             SetPixelV Form1.picMain.hdc, J, I, LPixel.Value
    24.         Next
    25.     Next

    and if I add the Refresh command it is done very slowly!!!

    help!

    Thank you,
    Arie.

  5. #5
    Fanatic Member riis's Avatar
    Join Date
    Nov 2001
    Posts
    551
    Here's a small tip to enhance the performance of your code.
    You really should store the hdc of your picturebox in a variable, before you start the loops. This way you only have to determine it once, instead of 206082 times (321 * 321 * 2). The device context of the picturebox doesn't change throughout the program (as far as I know).

    Janus meant to refresh the picturebox after ALL drawing, after the loops. It has no need to refresh it after every pixel, which indeed will make your code very slow.

  6. #6
    Fanatic Member riis's Avatar
    Join Date
    Nov 2001
    Posts
    551
    Oops, I forgot to mention that the type of the hdc variable should be long.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636
    How do I do that?

    I have the big loop, all the drawing I make in the new hdc, and in the end of the loop I BitBlt it to the picturebox?
    That's what you mean?

    If it's that, so how do I see the picturebox turning into a lower bright in-motion? in the code I posted?

    Thank you,
    Arie.

  8. #8
    Fanatic Member riis's Avatar
    Join Date
    Nov 2001
    Posts
    551
    Adjusted code:
    VB Code:
    1. Public Type LongPixel
    2.    Value As Long
    3. End Type
    4. Public Type RGBAPixel
    5.    Red As Byte
    6.    Green As Byte
    7.    Blue As Byte
    8.    Alpha As Byte
    9. End Type
    10. Public Declare Function SetPixelV Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
    11.  
    12.     Dim LPixel As LongPixel, BPixel As RGBAPixel
    13.     Dim I As Integer, J As Integer
    14.     Dim hDC as Long
    15.    
    16.     hDC = Form1.picMain.hdc   'Retrieve the DC handle
    17.     For I = 0 To 320
    18.         For J = 0 To 320
    19.             LPixel.Value = GetPixel(hDC, J, I)   'You can use the variable hDC here
    20.             LSet BPixel = LPixel
    21.             BPixel.Red = BPixel.Red \ iLight
    22.             BPixel.Green = BPixel.Green \ iLight
    23.             BPixel.Blue = BPixel.Blue \ iLight
    24.             LSet LPixel = BPixel
    25.             SetPixelV hDC, J, I, LPixel.Value   'You can use the variable hDC here
    26.         Next
    27.     Next
    28.     Form1.picMain.Refresh   'Refresh the picturebox, to see the changes

  9. #9
    Addicted Member Janus's Avatar
    Join Date
    Aug 2001
    Location
    California
    Posts
    221
    Hmm...
    That looks suspiciously like a certain example I wrote
    "1 4m 4 1337 #4xz0r!'
    Janus

  10. #10
    Fanatic Member riis's Avatar
    Join Date
    Nov 2001
    Posts
    551
    That looks suspiciously like a certain example I wrote
    Janus, you mean this?
    VB Code:
    1. LPixel.Value = GetPixel(hDC, J, I)   'You can use the variable hDC here
    2.             LSet BPixel = LPixel
    3.             BPixel.Red = BPixel.Red \ iLight
    4.             BPixel.Green = BPixel.Green \ iLight
    5.             BPixel.Blue = BPixel.Blue \ iLight
    6.             LSet LPixel = BPixel

    I just modified Arie's code, and Arie probably used it, since you promoted it as an improvement which it probably is. (I haven't used it myself yet, but I surely will.)

  11. #11
    Addicted Member Janus's Avatar
    Join Date
    Aug 2001
    Location
    California
    Posts
    221
    Hehe, I was kidding! :P Glad to see it works for ya
    "1 4m 4 1337 #4xz0r!'
    Janus

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636

    Talking Thanx!!!

    oh....
    OK, I got it. Solved the problem!!
    Thank you very much!!!

    Arie.

  13. #13
    Fanatic Member riis's Avatar
    Join Date
    Nov 2001
    Posts
    551
    Hehe, I was kidding! :P
    I know, but I couldn't resist to post a remark

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