Hardware images: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 35: Line 35:
     k = {{Cl|_KEYHIT}}
     k = {{Cl|_KEYHIT}}
     {{Cl|SELECT CASE}} k
     {{Cl|SELECT CASE}} k
         {{Cl|CASE}} {{Cl|ASC}}({{Text|<nowiki>"w"</nowiki>|#FFB100}}): y = y - {{Text|1|#F580B1}}
         {{Cl|CASE}} {{Cl|ASC (function)|ASC}}({{Text|<nowiki>"w"</nowiki>|#FFB100}}): y = y - {{Text|1|#F580B1}}
         {{Cl|CASE}} {{Cl|ASC}}({{Text|<nowiki>"a"</nowiki>|#FFB100}}): x = x - {{Text|1|#F580B1}}
         {{Cl|CASE}} {{Cl|ASC (function)|ASC}}({{Text|<nowiki>"a"</nowiki>|#FFB100}}): x = x - {{Text|1|#F580B1}}
         {{Cl|CASE}} {{Cl|ASC}}({{Text|<nowiki>"s"</nowiki>|#FFB100}}): y = y + {{Text|1|#F580B1}}
         {{Cl|CASE}} {{Cl|ASC (function)|ASC}}({{Text|<nowiki>"s"</nowiki>|#FFB100}}): y = y + {{Text|1|#F580B1}}
         {{Cl|CASE}} {{Cl|ASC}}({{Text|<nowiki>"d"</nowiki>|#FFB100}}): x = x + {{Text|1|#F580B1}}
         {{Cl|CASE}} {{Cl|ASC (function)|ASC}}({{Text|<nowiki>"d"</nowiki>|#FFB100}}): x = x + {{Text|1|#F580B1}}
     {{Cl|END SELECT}}
     {{Cl|END SELECT}}
     {{Cl|_DISPLAY}} {{Text|<nowiki>'render image after changes</nowiki>|#919191}}
     {{Cl|_DISPLAY}} {{Text|<nowiki>'render image after changes</nowiki>|#919191}}
Line 81: Line 81:
     k = {{Cl|_KEYHIT}}
     k = {{Cl|_KEYHIT}}
     {{Cl|SELECT CASE}} k
     {{Cl|SELECT CASE}} k
         {{Cl|CASE}} {{Cl|ASC}}({{Text|<nowiki>"w"</nowiki>|#FFB100}}): y = y - {{Text|1|#F580B1}}
         {{Cl|CASE}} {{Cl|ASC (function)|ASC}}({{Text|<nowiki>"w"</nowiki>|#FFB100}}): y = y - {{Text|1|#F580B1}}
         {{Cl|CASE}} {{Cl|ASC}}({{Text|<nowiki>"a"</nowiki>|#FFB100}}): x = x - {{Text|1|#F580B1}}
         {{Cl|CASE}} {{Cl|ASC (function)|ASC}}({{Text|<nowiki>"a"</nowiki>|#FFB100}}): x = x - {{Text|1|#F580B1}}
         {{Cl|CASE}} {{Cl|ASC}}({{Text|<nowiki>"s"</nowiki>|#FFB100}}): y = y + {{Text|1|#F580B1}}
         {{Cl|CASE}} {{Cl|ASC (function)|ASC}}({{Text|<nowiki>"s"</nowiki>|#FFB100}}): y = y + {{Text|1|#F580B1}}
         {{Cl|CASE}} {{Cl|ASC}}({{Text|<nowiki>"d"</nowiki>|#FFB100}}): x = x + {{Text|1|#F580B1}}
         {{Cl|CASE}} {{Cl|ASC (function)|ASC}}({{Text|<nowiki>"d"</nowiki>|#FFB100}}): x = x + {{Text|1|#F580B1}}
     {{Cl|END SELECT}}
     {{Cl|END SELECT}}
     {{Cl|_DISPLAY}} {{Text|<nowiki>'render image after changes</nowiki>|#919191}}
     {{Cl|_DISPLAY}} {{Text|<nowiki>'render image after changes</nowiki>|#919191}}

Revision as of 09:10, 25 September 2024

Hardware Images (QB64 version 1.000 and up)


Demonstration of the Advantages of Using Hardware Images


The first example uses software images while using between 20 - 30% processor power:
SCREEN _NEWIMAGE(640, 480, 32)

'create some software screens
scr_bg = _NEWIMAGE(640, 480, 32)
scr_fg = _NEWIMAGE(50, 50, 32)

'draw to the background one, and make a nice pattern
_DEST scr_bg
FOR i = 1 TO 100
    LINE (RND * 640, RND * 480)-(RND * 640, RND * 480), _RGBA32(RND * 255, RND * 255, RND * 255, RND * 255), BF
NEXT i

'then do the same thing for the foreground
_DEST scr_fg
LINE (0, 0)-(50, 50), _RGBA32(255, 255, 255, 200), BF

'set image destination to main screen
_DEST 0
DO
    CLS
    _PUTIMAGE , scr_bg
    _PUTIMAGE (x, y), scr_fg
    k = _KEYHIT
    SELECT CASE k
        CASE ASC("w"): y = y - 1
        CASE ASC("a"): x = x - 1
        CASE ASC("s"): y = y + 1
        CASE ASC("d"): x = x + 1
    END SELECT
    _DISPLAY 'render image after changes
    _LIMIT 30 'we're doing all this at 30 cycles/second
LOOP
Example by Johny B.


The second example converts the foreground and background software screens to hardware using 6-7% processor power:
SCREEN _NEWIMAGE(640, 480, 32)

'create some software screens
scr_bg = _NEWIMAGE(640, 480, 32)
scr_fg = _NEWIMAGE(50, 50, 32)

'draw to the background one, and make a nice pattern
_DEST scr_bg
FOR i = 1 TO 100
    LINE (RND * 640, RND * 480)-(RND * 640, RND * 480), _RGBA32(RND * 255, RND * 255, RND * 255, RND * 255), BF
NEXT i
'create a hardware screen version of the background
scrh_bg = _COPYIMAGE(scr_bg, 33)
_FREEIMAGE scr_bg 'we no longer need the software version in memory

'then do the same thing for the foreground
_DEST scr_fg
LINE (0, 0)-(50, 50), _RGBA32(255, 255, 255, 200), BF
'copy to hardware screen
scrh_fg = _COPYIMAGE(scr_fg, 33)
_FREEIMAGE scr_fg 'and free software screen from memory

'set image destination to main screen
_DEST 0
_DISPLAYORDER _HARDWARE 'do not even render the software layer, just the hardware one.
DO 'main program loop
    '_putimage knows these are hardware screens, so destination of 0 is taken as hardware layer
    _PUTIMAGE , scrh_bg
    _PUTIMAGE (x, y), scrh_fg
    'just some input processing
    k = _KEYHIT
    SELECT CASE k
        CASE ASC("w"): y = y - 1
        CASE ASC("a"): x = x - 1
        CASE ASC("s"): y = y + 1
        CASE ASC("d"): x = x + 1
    END SELECT
    _DISPLAY 'render image after changes
    _LIMIT 30 'we're doing all this at 30 cycles/second
LOOP
Example by Johny B.


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link