Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
_PUTIMAGE Question
#1
This question pertains to my work on the hardware acceleration lesson in the tutorial.

According to the Wiki _PUTIMAGE should be allowed to use hardware images as either the source or destination. However this is not working for me. Please take a look at the sample code I included below. Am I missing something obvious or does the Wiki need updating?

Code: (Select All)
OPTION _EXPLICIT '    declare those variables son!

DIM SWimage AS LONG ' software image
DIM HWimage AS LONG ' hardware image

SCREEN _NEWIMAGE(640, 480, 32) '     create a software surface
SWimage = _NEWIMAGE(100, 100, 32) '  create a software image
_DEST SWimage '                      draw on the software image
CIRCLE (49, 49), 49 '                create a full size circle on the software image
HWimage = _COPYIMAGE(SWimage, 33) '  create a hardware version of the software image
CLS '                                clear the software image
CIRCLE (49, 49), 24 '                create a half size circle on the software image
_DEST 0 '                            return to the software surface
_PUTIMAGE (0, 0), SWimage '          place the software image onto the software surface

'+------------------------------------------------------------------------------------------------------------------+
'| According to the Wiki _PUTIMAGE should be allowed to use hardware images, however it's not working.              |
'|                                                                                                                  |
'| "Hardware images (created using mode 33 via _LOADIMAGE or _COPYIMAGE) can be used as the source or destination." |
'|                                                                                                                  |
'| The quote above was taken directly from the Wiki.                                                                |
'+------------------------------------------------------------------------------------------------------------------+

'_PUTIMAGE (0, 0), HWimage, SWimage ' nope, invalid handle           <<--- neither one of these work?
'_PUTIMAGE (0, 0), SWimage, HWimage ' nope, invalid handle           <<---

DO
    _LIMIT 15 '                      slow down hoss
    _PUTIMAGE (0, 0), HWimage '      draw the hardware image over the software image
    _DISPLAY '                       update the surfaces
LOOP UNTIL _KEYDOWN(27) '            leave when ESC pressed
_FREEIMAGE SWimage
_FREEIMAGE HWimage
There are two ways to write error-free programs; only the third one works.
QB64 Tutorial
Reply
#2
Aye.  Hardware images have their own unique layer that you can only put them on.  When they're in use, _DEST image is always blank.
Reply
#3
(09-17-2023, 03:37 AM)SMcNeill Wrote: Aye.  Hardware images have their own unique layer that you can only put them on.  When they're in use, _DEST image is always blank.
Ok, then the description for _MAPTRIANGLE in the Wiki is incorrect as well. Thanks for the clarification Steve.
There are two ways to write error-free programs; only the third one works.
QB64 Tutorial
Reply
#4
Hi Terry,
Hi Steve

I have found this wiki example in which _PUTIMAGE works with hardware images ... AND in this code there is no _DestHandle&.
Before reading Steve's answer I have thought that it was because _DEST 0 is screen in use and displayed as output.
Now I am asking to myself if the absence of _destHandle& is a tip or a coincidence.

Code: (Select All)
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
taken from this wiki page Hardware images.

well Step 1:
we create an image surface on which we put the hardware images
and from this last image we _Putimage on the screen (_Dest 0)

and there is no issue
Code: (Select All)
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
Dim ScreenC As Long
_Dest ScreenC
'_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
    _PutImage (0, 0), ScreenC, 0
    '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

moreover we attempt to _putimage the hardware images directly on a software image and then we copy this last on the screen surface...
(we  delete _Dest 0 and _Dysplayorder instructions!)  and all seem working well!

Code: (Select All)
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 software image that has been copied on the main screen
Dim ScreenC As Long
Do 'main program loop
    '_putimage knows these are hardware screens, so destination of 0 is taken as hardware layer
    _PutImage , scrh_bg, ScreenC
    _PutImage (x, y), scrh_fg, ScreenC
    _PutImage (0, 0), ScreenC, 0
    '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
we need more informations !
Why does Terry get invalid handle error and this code no?
Reply




Users browsing this thread: 1 Guest(s)