|
-
Mar 1st, 2002, 09:25 AM
#1
Thread Starter
Fanatic Member
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.
-
Mar 1st, 2002, 10:20 AM
#2
Set AutoRedraw to true.
Z.
-
Mar 1st, 2002, 02:51 PM
#3
Addicted Member
Also, call the .Refresh method after you're done drawing, to update the screen.
"1 4m 4 1337 #4xz0r!'
Janus
-
Mar 2nd, 2002, 04:57 AM
#4
Thread Starter
Fanatic Member
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:
Public Type LongPixel
Value As Long
End Type
Public Type RGBAPixel
Red As Byte
Green As Byte
Blue As Byte
Alpha As Byte
End Type
Public Declare Function SetPixelV Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
Dim LPixel As LongPixel, BPixel As RGBAPixel
Dim I As Integer, J As Integer
For I = 0 To 320
For J = 0 To 320
LPixel.Value = GetPixel(Form1.picMain.hdc, J, I)
LSet BPixel = LPixel
BPixel.Red = BPixel.Red \ iLight
BPixel.Green = BPixel.Green \ iLight
BPixel.Blue = BPixel.Blue \ iLight
LSet LPixel = BPixel
SetPixelV Form1.picMain.hdc, J, I, LPixel.Value
Next
Next
and if I add the Refresh command it is done very slowly!!!
help!
Thank you,
Arie.
-
Mar 2nd, 2002, 01:32 PM
#5
Fanatic Member
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.
-
Mar 2nd, 2002, 01:34 PM
#6
Fanatic Member
Oops, I forgot to mention that the type of the hdc variable should be long.
-
Mar 2nd, 2002, 03:22 PM
#7
Thread Starter
Fanatic Member
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.
-
Mar 3rd, 2002, 05:06 AM
#8
Fanatic Member
Adjusted code:
VB Code:
Public Type LongPixel
Value As Long
End Type
Public Type RGBAPixel
Red As Byte
Green As Byte
Blue As Byte
Alpha As Byte
End Type
Public Declare Function SetPixelV Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
Dim LPixel As LongPixel, BPixel As RGBAPixel
Dim I As Integer, J As Integer
Dim hDC as Long
hDC = Form1.picMain.hdc 'Retrieve the DC handle
For I = 0 To 320
For J = 0 To 320
LPixel.Value = GetPixel(hDC, J, I) 'You can use the variable hDC here
LSet BPixel = LPixel
BPixel.Red = BPixel.Red \ iLight
BPixel.Green = BPixel.Green \ iLight
BPixel.Blue = BPixel.Blue \ iLight
LSet LPixel = BPixel
SetPixelV hDC, J, I, LPixel.Value 'You can use the variable hDC here
Next
Next
Form1.picMain.Refresh 'Refresh the picturebox, to see the changes
-
Mar 4th, 2002, 02:00 PM
#9
Addicted Member
Hmm...
That looks suspiciously like a certain example I wrote
"1 4m 4 1337 #4xz0r!'
Janus
-
Mar 4th, 2002, 02:53 PM
#10
Fanatic Member
That looks suspiciously like a certain example I wrote
Janus, you mean this?
VB Code:
LPixel.Value = GetPixel(hDC, J, I) 'You can use the variable hDC here
LSet BPixel = LPixel
BPixel.Red = BPixel.Red \ iLight
BPixel.Green = BPixel.Green \ iLight
BPixel.Blue = BPixel.Blue \ iLight
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.)
-
Mar 5th, 2002, 04:18 AM
#11
Addicted Member
Hehe, I was kidding! :P Glad to see it works for ya
"1 4m 4 1337 #4xz0r!'
Janus
-
Mar 5th, 2002, 01:56 PM
#12
Thread Starter
Fanatic Member
Thanx!!!
oh....
OK, I got it. Solved the problem!!
Thank you very much!!!
Arie.
-
Mar 5th, 2002, 02:37 PM
#13
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|