Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Hardware Acceleration and Uses
#11
And here's an example of how to do this, and only update/change the screen as necessary:

Code: (Select All)
Dim buttons(1) 'just two simple buttons for the demo
button(0) = MakeButton("Hello World")
button(1) = MakeButton("STEVE!")

x = 100 'just for moveable button
Cls , 4 'a red screen for a background
screenChange = _TRUE 'we start by drawing the screen once
Do
k = _KeyHit
Select Case k 'left/right arrow to move that button
Case 19200
x = x - 3
If x < 0 Then x = 0
screenChange = _TRUE
Case 19712
x = x + 3
If x > _Width * _FontWidth - 100 Then x = _Width * _FontWidth - 100
screenChange = _TRUE
Case Is > 0: System 'any other key to end
End Select
If screenChange Then 'only update the screen when it changes
_PutImage (x, 100), button(0)
_PutImage (200, 200), button(1)
_Display
screenChange = _FALSE
End If
_Limit 30
Loop

Function MakeButton (caption$)
d = _Dest
temp = _NewImage(_FontWidth * Len(caption$) + 4, _FontHeight + 4, 32)
_Dest temp
Color &HFFFFFFFF&&, 0 ' bright white text with no background
Cls , &HFF0000FF&& 'dark blue background for this button
Line (0, 0)-(_Width - 1, _Height - 1), &HFFFFFFFF, B 'white trim around the edges
Line (1, 1)-(_Width - 2, _Height - 2), &HFFFFFFFF, B '2 pixel trim
_PrintString (3, 3), caption$ 'print the caption
MakeButton = _CopyImage(temp, 33) 'make the hardware button
_Dest d 'restore the destination
_FreeImage temp 'free the temp image
End Function

Notice here that the vast majority of the time we're not even using _DISPLAY to update the screen. We print what we want on it, draw the buttons over it... and then basically forget about it until we have to update the screen again. We're still doing the input checking and the processing and everything else, but we're doing absolutely *nothing* with images. We're not putting anything on the screen, or making copies of anything, or freeing anything... We're just leaving the screen as it was until we need to do something to change it.

My CPU usage here? 0.1%... and I think that might be because it never seems to be 0.0% on an active program. Big Grin
Reply


Messages In This Thread
Hardware Acceleration and Uses - by Pete - 02-18-2025, 04:57 PM
RE: Hardware Acceleration and Uses - by SMcNeill - 02-18-2025, 05:42 PM
RE: Hardware Acceleration and Uses - by a740g - 02-18-2025, 05:47 PM
RE: Hardware Acceleration and Uses - by Pete - 02-18-2025, 10:35 PM
RE: Hardware Acceleration and Uses - by SMcNeill - 02-18-2025, 11:23 PM
RE: Hardware Acceleration and Uses - by SMcNeill - 02-18-2025, 11:36 PM
RE: Hardware Acceleration and Uses - by Pete - 02-18-2025, 11:45 PM
RE: Hardware Acceleration and Uses - by SMcNeill - 02-19-2025, 06:06 AM
RE: Hardware Acceleration and Uses - by SMcNeill - 02-19-2025, 06:42 AM
RE: Hardware Acceleration and Uses - by SMcNeill - 02-19-2025, 06:58 AM
RE: Hardware Acceleration and Uses - by SMcNeill - 02-19-2025, 07:06 AM
RE: Hardware Acceleration and Uses - by Pete - 02-19-2025, 12:05 PM
RE: Hardware Acceleration and Uses - by SMcNeill - 02-19-2025, 02:28 PM
RE: Hardware Acceleration and Uses - by SMcNeill - 02-19-2025, 02:16 PM
RE: Hardware Acceleration and Uses - by Pete - 02-19-2025, 06:00 PM
RE: Hardware Acceleration and Uses - by SMcNeill - 02-19-2025, 07:54 PM
RE: Hardware Acceleration and Uses - by Pete - 02-19-2025, 08:52 PM
RE: Hardware Acceleration and Uses - by SMcNeill - 02-20-2025, 04:23 PM
RE: Hardware Acceleration and Uses - by Pete - 02-21-2025, 02:28 AM
RE: Hardware Acceleration and Uses - by SMcNeill - 02-21-2025, 03:13 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Half baked pipe dream questions - hardware and os Parkland 9 1,329 05-23-2025, 03:00 PM
Last Post: madscijr
  Fun with hardware acceleration. Pete 0 459 10-20-2022, 10:25 PM
Last Post: Pete

Forum Jump:


Users browsing this thread: 1 Guest(s)