Of course what you have is going to take two passes before it goes onto the screen. It's the way you've *BADLY* wrote your workflow once again. Let me break it down for you:
Read the comments above for what you're doing all wrong here. Then, after you've tossed your shoe at the screen and gotten past cussing poor innocent Steve, take a moment and study the code below for a much simpler and easier workflow:
Now, what is your original code doing?
Loading an image FOUR TIMES. (twice in the inner loop, repeated twice in that outer loop)
Using it...
Freeing it...
WHY?? This is... less than 10k bytes of memory. If that's taxing your PC's memory, tell your wife that you have my permission to go out and upgrade from the TRS-80 that you're still trying to somehow run QB64 on. /sigh
Just load it once. Make it hardware. Use it as needed and don't worry about it.
And throw away the Overlay. You don't need that at all. The hardware layer is separate from the software layer. Just put what you need on the hardware layer and _DISPLAY it. It really is *THAT* simple.
(Note that you'll need to change the path to files. I'm storing your images on my ram drive for now, so I won't have to worry about temp junk filling up my folders. That's where the Z:\ comes from.
)
Code: (Select All)
Type fields_and_buttons
a As String
fld As Integer
nof As Integer
nob As Integer
style As Integer
End Type
Dim fb As fields_and_buttons
ReDim button$(10), x(10), y(10)
x(9) = 5: y(9) = 10
x(10) = 25: y(10) = 10
fb.a = "z:\Activate"
button$(9) = _Trim$(fb.a)
button$(10) = _Trim$(fb.a)
overlay = _NewImage(_Width * _FontWidth, _Height * _FontHeight, 32)
'Create a blank overlay with the above
For p = 1 To 2 ' p is not part of the original code. It's just here to demo the problem.
'make a copy of the existing overlay
'when p is 1, we're going to make a copy of a blank image
Overlay_Hardware = _CopyImage(overlay, 33)
'Now, let's draw on that overlay! Here we make it the _DEST
_Dest overlay
'And here, we put the copy of the existing overlay onto the screen...
'Remember, for the first pass, this is still BLANK at this point!!
_PutImage (0, 0), Overlay_Hardware
For k = 9 To 10
'and here we're just dumb. We want to load the same damn tiny file over and over
'and free it so that we run up CPU usage inside a loop and..
'save what? 10k of memory?
'I did the maths -- It's an 87 x 28 image, in 32-bit colors so raw, uncompressed
'mem usuage is 87 * 28 * 4 = 9,744 bytes of memory.
'WOOOOOOO!!! Why the FLUCK is this just not loaded once and then fogotten about?!!
img& = _LoadImage(button$(k) + "-static.png", 32)
'And here, we put the image to... the current _DEST...
'which is, of course, _DEST overlay
_PutImage ((x(k) - 1) * 8 + 4, (y(k) - 1) * 16), img&
'Kindly recall that overlay WAS blank up until this point
'So we're putting it to the overlay for the first time
'But... This does NOTHING to change the fact that we've already
'put the BLANK Hardware image to the screen, before this...
_FreeImage img& 'WHY OH WHY?!!
Next
_FreeImage Overlay_Hardware 'Get rid of that copy we made
_Dest 0 'Restore our _DEST
_Display 'Laugh at Pete quite soundly at this point
Beep: Sleep
Next p 'NOW, when we run this a second time, the Overlay has the image on it
'so when we make a copy of the overlay, we end up with it being visible on the screen
'when we putimage that copy to the display
Read the comments above for what you're doing all wrong here. Then, after you've tossed your shoe at the screen and gotten past cussing poor innocent Steve, take a moment and study the code below for a much simpler and easier workflow:
Code: (Select All)
Type fields_and_buttons
a As String
fld As Integer
nof As Integer
nob As Integer
style As Integer
End Type
Dim fb As fields_and_buttons
img& = _LoadImage("Z:\activate-static.png", 32)
img_hw& = _CopyImage(img&, 33) 'copy the hardware image
_FreeImage img& 'free that image since we made a hardware version of it
ReDim button$(10), x(10), y(10)
x(9) = 5: y(9) = 10
x(10) = 25: y(10) = 10
fb.a = "Activate"
button$(9) = _Trim$(fb.a)
button$(10) = _Trim$(fb.a)
'overlay = _NewImage(_Width * _FontWidth, _Height * _FontHeight, 32)
'No need for an overlay. The hardware screen itself is the overlay!!
'For p = 1 To 2 ' p is not part of the original code. It's just here to demo the problem.
' Overlay_Hardware = _CopyImage(overlay, 33)
' _Dest overlay
' _PutImage (0, 0), Overlay_Hardware
'NOPE. No need for these either!
For k = 9 To 10
_PutImage ((x(k) - 1) * 8 + 4, (y(k) - 1) * 16), img_hw&
'_FreeImage img&
'NOPE!! Not needed. Just leave the image in memory!
Next
'_FreeImage Overlay_Hardware
'_Dest 0
'NOPE. Didn't make it. Don't need to change it. No need to alter _DEST
'Toss all this crapola out
_Display
Beep: Sleep
'Next p
'No need to pee anywhere. We have now sorted out the code so that it works properly
'without having to make that second pass to display
Now, what is your original code doing?
Loading an image FOUR TIMES. (twice in the inner loop, repeated twice in that outer loop)
Using it...
Freeing it...
WHY?? This is... less than 10k bytes of memory. If that's taxing your PC's memory, tell your wife that you have my permission to go out and upgrade from the TRS-80 that you're still trying to somehow run QB64 on. /sigh
Just load it once. Make it hardware. Use it as needed and don't worry about it.
And throw away the Overlay. You don't need that at all. The hardware layer is separate from the software layer. Just put what you need on the hardware layer and _DISPLAY it. It really is *THAT* simple.
(Note that you'll need to change the path to files. I'm storing your images on my ram drive for now, so I won't have to worry about temp junk filling up my folders. That's where the Z:\ comes from.
