01-14-2023, 02:43 PM
Someone on Discord sent me a couple of messages asking what the big deal was with hardware images, and why anyone would ever bother with them. I hope the little demo below here will be sufficient enough to showcase why folks might want to make use of hardware images in their programs.
Code: (Select All)
DIM count AS _INTEGER64
displayScreen = _NEWIMAGE(1024, 720, 32)
workScreen = _NEWIMAGE(512, 360, 32)
SCREEN displayScreen
_DEST workScreen
FOR i = 1 TO 100 'draws something on the drawscreen
LINE (RND * _WIDTH, RND * _HEIGHT)-(RND * _WIDTH, RND * _HEIGHT), _RGB32(RND * 256, RND * 256, RND * 256), BF
NEXT
hardwareScreen = _COPYIMAGE(workScreen, 33)
_DEST displayScreen
PRINT "For this demo, we're going to be scaling and placing a premade image onto the screen."
PRINT "For ease of output, our FPS count is going to be placed up in the TITLE area."
PRINT
PRINT "First, we'll do a FPS cound of simple software images."
PRINT "Let it run a few seconds, and then press <ANY KEY> when you'd like to move on."
PRINT
PRINT "After that, we'll use hardware images AND software images, and see how things compare."
PRINT "As before, watch the TITLE area for updates, and press <ANY KEY> when ready to move on."
PRINT
PRINT "And finally, we'll JUST use hardware images for our display."
PRINT "Once again, our FPS second count will be in the TITLE area, and you can press <ANY KEY> to"
PRINT "move to our final resulsts screen for ease of comparison."
PRINT
PRINT
PRINT "Press <ANY KEY> to begin."
SLEEP
_DELAY .5
_KEYCLEAR 'time to release any key
time# = TIMER + 1
DO
CLS , 0
scount = scount + 1
IF TIMER > time# THEN
_TITLE "Software FPS:" + STR$(scount)
IF scount > smax THEN smax = scount
scount = 0
time# = TIMER + 1
END IF
_PUTIMAGE , workScreen
_DISPLAY
LOOP UNTIL _KEYHIT
_DELAY .5
_KEYCLEAR 'time to release any key
time# = TIMER + 1
DO
CLS , 0
mcount = mcount + 1
IF TIMER > time# THEN
_TITLE "Mixed FPS:" + STR$(mcount)
IF mcount > mmax THEN mmax = mcount
mcount = 0
time# = TIMER + 1
END IF
_PUTIMAGE , hardwareScreen
_DISPLAY
LOOP UNTIL _KEYHIT
_DELAY .5
_KEYCLEAR 'time to release any key
time# = TIMER + 1
_DISPLAYORDER _HARDWARE
CLS , 0
DO
hcount = hcount + 1
IF TIMER > time# THEN
_TITLE "Hardware FPS:" + STR$(hcount)
IF hcount > hmax THEN hmax = hcount
hcount = 0
time# = TIMER + 1
END IF
_PUTIMAGE , hardwareScreen
_DISPLAY
LOOP UNTIL _KEYHIT
_DISPLAYORDER _SOFTWARE , _HARDWARE
CLS , 0
_AUTODISPLAY
PRINT USING "###,###,### FPS with Software Images"; smax
PRINT USING "###,###,### FPS with Software and Hardware Images"; mmax
PRINT USING "###,###,### FPS with Hardware Images only"; hmax
PRINT
PRINT
PRINT "I would think the figures here alone, would showcase why one might want to use hardware images over other types, when possible."