Hardware images: Difference between revisions
Jump to navigation
Jump to search
Hardware Images (QB64 version 1.000 and up)
Demonstration of the Advantages of Using Hardware Images
Example by Johny B.
Example by Johny B.
Wiki Pages
Main Page with Articles and Tutorials
QB64 specific keywords (alphabetical)
Original QBasic keywords (alphabetical)
QB64 OpenGL keywords (alphabetical)
Keywords by Usage
Got a question about something?
Frequently Asked Questions about QB64
QB64 Phoenix Edition Community Forum
Links to other QBasic Sites:
Pete's QBasic Forum
Pete's QBasic Downloads
m (Protected "Hardware images" ([Edit=Allow only autoconfirmed users] (indefinite) [Move=Allow only autoconfirmed users] (indefinite))) |
No edit summary |
||
(8 intermediate revisions by the same user not shown) | |||
Line 7: | Line 7: | ||
<center>'''Demonstration of the Advantages of Using Hardware Images'''</center> | <center>'''Demonstration of the Advantages of Using Hardware Images'''</center> | ||
: The first example uses software images while using between 20 - 30% processor power: | : The first example uses software images while using between 20 - 30% processor power: | ||
{{CodeStart}}{{Cl|SCREEN}} {{Cl|_NEWIMAGE}}(640, 480, 32) | {{CodeStart}} | ||
{{Cl|SCREEN}} {{Cl|_NEWIMAGE}}({{Text|640|#F580B1}}, {{Text|480|#F580B1}}, {{Text|32|#F580B1}}) | |||
'create some software screens | {{Text|<nowiki>'create some software screens</nowiki>|#919191}} | ||
scr_bg = {{Cl|_NEWIMAGE}}(640, 480, 32) | scr_bg = {{Cl|_NEWIMAGE}}({{Text|640|#F580B1}}, {{Text|480|#F580B1}}, {{Text|32|#F580B1}}) | ||
scr_fg = {{Cl|_NEWIMAGE}}(50, 50, 32) | scr_fg = {{Cl|_NEWIMAGE}}({{Text|50|#F580B1}}, {{Text|50|#F580B1}}, {{Text|32|#F580B1}}) | ||
'draw to the background one, and make a nice pattern | {{Text|<nowiki>'draw to the background one, and make a nice pattern</nowiki>|#919191}} | ||
{{Cl|_DEST}} scr_bg | {{Cl|_DEST}} scr_bg | ||
{{Cl | {{Cl|FOR}} i = {{Text|1|#F580B1}} {{Cl|TO}} {{Text|100|#F580B1}} | ||
{{Cl|LINE}} ({{Cl|RND}} * 640, {{Cl|RND}} * 480)-({{Cl|RND}} * 640, {{Cl|RND}} * 480), {{Cl|_RGBA32}}({{Cl|RND}} * 255, {{Cl|RND}} * 255, {{Cl|RND}} * 255, {{Cl|RND}} * 255), BF | {{Cl|LINE}} ({{Cl|RND}} * {{Text|640|#F580B1}}, {{Cl|RND}} * {{Text|480|#F580B1}})-({{Cl|RND}} * {{Text|640|#F580B1}}, {{Cl|RND}} * {{Text|480|#F580B1}}), {{Cl|_RGBA32}}({{Cl|RND}} * {{Text|255|#F580B1}}, {{Cl|RND}} * {{Text|255|#F580B1}}, {{Cl|RND}} * {{Text|255|#F580B1}}, {{Cl|RND}} * {{Text|255|#F580B1}}), BF | ||
{{Cl|NEXT}} i | {{Cl|NEXT}} i | ||
'then do the same thing for the foreground | {{Text|<nowiki>'then do the same thing for the foreground</nowiki>|#919191}} | ||
{{Cl|_DEST}} scr_fg | {{Cl|_DEST}} scr_fg | ||
{{Cl|LINE}} (0, 0)-(50, 50), {{Cl|_RGBA32}}(255, 255, 255, 200), BF | {{Cl|LINE}} ({{Text|0|#F580B1}}, {{Text|0|#F580B1}})-({{Text|50|#F580B1}}, {{Text|50|#F580B1}}), {{Cl|_RGBA32}}({{Text|255|#F580B1}}, {{Text|255|#F580B1}}, {{Text|255|#F580B1}}, {{Text|200|#F580B1}}), BF | ||
'set image destination to main screen | {{Text|<nowiki>'set image destination to main screen</nowiki>|#919191}} | ||
{{Cl|_DEST}} 0 | {{Cl|_DEST}} {{Text|0|#F580B1}} | ||
DO | {{Cl|DO}} | ||
{{Cl|CLS}} | {{Cl|CLS}} | ||
{{Cl|_PUTIMAGE}} , scr_bg | {{Cl|_PUTIMAGE}} , scr_bg | ||
Line 35: | Line 35: | ||
k = {{Cl|_KEYHIT}} | k = {{Cl|_KEYHIT}} | ||
{{Cl|SELECT CASE}} k | {{Cl|SELECT CASE}} k | ||
{{Cl|CASE}} {{Cl|ASC}}("w"): y = y - 1 | {{Cl|CASE}} {{Cl|ASC (function)|ASC}}({{Text|<nowiki>"w"</nowiki>|#FFB100}}): y = y - {{Text|1|#F580B1}} | ||
{{Cl|CASE}} {{Cl|ASC}}("a"): x = x - 1 | {{Cl|CASE}} {{Cl|ASC (function)|ASC}}({{Text|<nowiki>"a"</nowiki>|#FFB100}}): x = x - {{Text|1|#F580B1}} | ||
{{Cl|CASE}} {{Cl|ASC}}("s"): y = y + 1 | {{Cl|CASE}} {{Cl|ASC (function)|ASC}}({{Text|<nowiki>"s"</nowiki>|#FFB100}}): y = y + {{Text|1|#F580B1}} | ||
{{Cl|CASE}} {{Cl|ASC}}("d"): x = x + 1 | {{Cl|CASE}} {{Cl|ASC (function)|ASC}}({{Text|<nowiki>"d"</nowiki>|#FFB100}}): x = x + {{Text|1|#F580B1}} | ||
{{Cl|END SELECT}} | {{Cl|END SELECT}} | ||
{{Cl|_DISPLAY}} 'render image after changes | {{Cl|_DISPLAY}} {{Text|<nowiki>'render image after changes</nowiki>|#919191}} | ||
{{Cl|_LIMIT}} 30 'we're doing all this at 30 cycles/second | {{Cl|_LIMIT}} {{Text|30|#F580B1}} {{Text|<nowiki>'we're doing all this at 30 cycles/second</nowiki>|#919191}} | ||
LOOP | {{Cl|LOOP}} | ||
{{CodeEnd}} | {{CodeEnd}} | ||
{{Small|Example by Johny B.}} | |||
: The second example converts the foreground and background software screens to hardware using 6-7% processor power: | : The second example converts the foreground and background software screens to hardware using 6-7% processor power: | ||
{{CodeStart}}{{Cl|SCREEN}} {{Cl|_NEWIMAGE}}(640, 480, 32) | {{CodeStart}} | ||
{{Cl|SCREEN}} {{Cl|_NEWIMAGE}}({{Text|640|#F580B1}}, {{Text|480|#F580B1}}, {{Text|32|#F580B1}}) | |||
'create some software screens | {{Text|<nowiki>'create some software screens</nowiki>|#919191}} | ||
scr_bg = {{Cl|_NEWIMAGE}}(640, 480, 32) | scr_bg = {{Cl|_NEWIMAGE}}({{Text|640|#F580B1}}, {{Text|480|#F580B1}}, {{Text|32|#F580B1}}) | ||
scr_fg = {{Cl|_NEWIMAGE}}(50, 50, 32) | scr_fg = {{Cl|_NEWIMAGE}}({{Text|50|#F580B1}}, {{Text|50|#F580B1}}, {{Text|32|#F580B1}}) | ||
'draw to the background one, and make a nice pattern | {{Text|<nowiki>'draw to the background one, and make a nice pattern</nowiki>|#919191}} | ||
{{Cl|_DEST}} scr_bg | {{Cl|_DEST}} scr_bg | ||
{{Cl | {{Cl|FOR}} i = {{Text|1|#F580B1}} {{Cl|TO}} {{Text|100|#F580B1}} | ||
{{Cl|LINE}} ({{Cl|RND}} * 640, {{Cl|RND}} * 480)-({{Cl|RND}} * 640, {{Cl|RND}} * 480), {{Cl|_RGBA32}}({{Cl|RND}} * 255, {{Cl|RND}} * 255, {{Cl|RND}} * 255, {{Cl|RND}} * 255), BF | {{Cl|LINE}} ({{Cl|RND}} * {{Text|640|#F580B1}}, {{Cl|RND}} * {{Text|480|#F580B1}})-({{Cl|RND}} * {{Text|640|#F580B1}}, {{Cl|RND}} * {{Text|480|#F580B1}}), {{Cl|_RGBA32}}({{Cl|RND}} * {{Text|255|#F580B1}}, {{Cl|RND}} * {{Text|255|#F580B1}}, {{Cl|RND}} * {{Text|255|#F580B1}}, {{Cl|RND}} * {{Text|255|#F580B1}}), BF | ||
{{Cl|NEXT}} i | {{Cl|NEXT}} i | ||
'create a hardware screen version of the background | {{Text|<nowiki>'create a hardware screen version of the background</nowiki>|#919191}} | ||
scrh_bg = {{Cl|_COPYIMAGE}}(scr_bg, 33) | scrh_bg = {{Cl|_COPYIMAGE}}(scr_bg, {{Text|33|#F580B1}}) | ||
{{Cl|_FREEIMAGE}} scr_bg 'we no longer need the software version in memory | {{Cl|_FREEIMAGE}} scr_bg {{Text|<nowiki>'we no longer need the software version in memory</nowiki>|#919191}} | ||
'then do the same thing for the foreground | {{Text|<nowiki>'then do the same thing for the foreground</nowiki>|#919191}} | ||
{{Cl|_DEST}} scr_fg | {{Cl|_DEST}} scr_fg | ||
{{Cl|LINE}} (0, 0)-(50, 50), {{Cl|_RGBA32}}(255, 255, 255, 200), BF | {{Cl|LINE}} ({{Text|0|#F580B1}}, {{Text|0|#F580B1}})-({{Text|50|#F580B1}}, {{Text|50|#F580B1}}), {{Cl|_RGBA32}}({{Text|255|#F580B1}}, {{Text|255|#F580B1}}, {{Text|255|#F580B1}}, {{Text|200|#F580B1}}), BF | ||
'copy to hardware screen | {{Text|<nowiki>'copy to hardware screen</nowiki>|#919191}} | ||
scrh_fg = {{Cl|_COPYIMAGE}}(scr_fg, 33) | scrh_fg = {{Cl|_COPYIMAGE}}(scr_fg, {{Text|33|#F580B1}}) | ||
{{Cl|_FREEIMAGE}} scr_fg 'and free software screen from memory | {{Cl|_FREEIMAGE}} scr_fg {{Text|<nowiki>'and free software screen from memory</nowiki>|#919191}} | ||
'set image destination to main screen | {{Text|<nowiki>'set image destination to main screen</nowiki>|#919191}} | ||
{{Cl|_DEST}} 0 | {{Cl|_DEST}} {{Text|0|#F580B1}} | ||
{{Cl|_DISPLAYORDER}} _HARDWARE 'do not even render the software layer, just the hardware one. | {{Cl|_DISPLAYORDER}} {{Cl|_HARDWARE}} {{Text|<nowiki>'do not even render the software layer, just the hardware one.</nowiki>|#919191}} | ||
{{Cl | {{Cl|DO}} {{Text|<nowiki>'main program loop</nowiki>|#919191}} | ||
'_putimage knows these are hardware screens, so destination of 0 is taken as hardware layer | {{Text|<nowiki>'_putimage knows these are hardware screens, so destination of 0 is taken as hardware layer</nowiki>|#919191}} | ||
{{Cl|_PUTIMAGE}} , scrh_bg | {{Cl|_PUTIMAGE}} , scrh_bg | ||
{{Cl|_PUTIMAGE}} (x, y), scrh_fg | {{Cl|_PUTIMAGE}} (x, y), scrh_fg | ||
'just some input processing | {{Text|<nowiki>'just some input processing</nowiki>|#919191}} | ||
k = {{Cl|_KEYHIT}} | k = {{Cl|_KEYHIT}} | ||
{{Cl|SELECT CASE}} k | {{Cl|SELECT CASE}} k | ||
{{Cl|CASE}} {{Cl|ASC}}("w"): y = y - 1 | {{Cl|CASE}} {{Cl|ASC (function)|ASC}}({{Text|<nowiki>"w"</nowiki>|#FFB100}}): y = y - {{Text|1|#F580B1}} | ||
{{Cl|CASE}} {{Cl|ASC}}("a"): x = x - 1 | {{Cl|CASE}} {{Cl|ASC (function)|ASC}}({{Text|<nowiki>"a"</nowiki>|#FFB100}}): x = x - {{Text|1|#F580B1}} | ||
{{Cl|CASE}} {{Cl|ASC}}("s"): y = y + 1 | {{Cl|CASE}} {{Cl|ASC (function)|ASC}}({{Text|<nowiki>"s"</nowiki>|#FFB100}}): y = y + {{Text|1|#F580B1}} | ||
{{Cl|CASE}} {{Cl|ASC}}("d"): x = x + 1 | {{Cl|CASE}} {{Cl|ASC (function)|ASC}}({{Text|<nowiki>"d"</nowiki>|#FFB100}}): x = x + {{Text|1|#F580B1}} | ||
{{Cl|END SELECT}} | {{Cl|END SELECT}} | ||
{{Cl|_DISPLAY}} 'render image after changes | {{Cl|_DISPLAY}} {{Text|<nowiki>'render image after changes</nowiki>|#919191}} | ||
{{Cl|_LIMIT}} 30 'we're doing all this at 30 cycles/second | {{Cl|_LIMIT}} {{Text|30|#F580B1}} {{Text|<nowiki>'we're doing all this at 30 cycles/second</nowiki>|#919191}} | ||
LOOP | {{Cl|LOOP}} | ||
{{CodeEnd}} | {{CodeEnd}} | ||
{{Small|Example by Johny B.}} | |||
{{PageSeeAlso}} | |||
* [[_LOADIMAGE]], [[_COPYIMAGE]] | * [[_LOADIMAGE]], [[_COPYIMAGE]], [[_SAVEIMAGE]] | ||
* [[_PUTIMAGE]], [[_MAPTRIANGLE]] | * [[_PUTIMAGE]], [[_MAPTRIANGLE]] | ||
* [[_DISPLAYORDER]] | * [[_DISPLAYORDER]] | ||
* [[_FREEIMAGE]] | * [[_FREEIMAGE]] | ||
{{ | {{PageReferences}} |
Latest revision as of 13:16, 19 November 2024
- QB64 can create hardware images using _LOADIMAGE files or _COPYIMAGE with mode 33 as the second parameter.
- Hardware images can be displayed using _PUTIMAGE or _MAPTRIANGLE with special texture properties.
- _COPYIMAGE mode 33 can convert images created by _NEWIMAGE, _LOADIMAGE or _SCREENIMAGE to 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 |
- 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 |
See also