Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Another way to think about hardware accelerated images in Screen 0
#3
@Pete
yes I dunno why but in my mind has taken place the idea that overwriting the handle the relative image in memory comes into garbage memory ready to be re-used! (an automatic malloc!)
So I have used the same handle for software image and hardware accellerated image!
Wrong.. so here the corrected code with the right economic management of the RAM.

Code: (Select All)

Screen 0
_DisplayOrder _Software , _Hardware ' this says only what must be shown
Dim As Long Img1, Img2, Img3, Img1H, Img2H, Img3H
Dim As Integer X, Y, Mb, Xm, Ym

' here it creates a square to overlap menu to make the shadow of selection
Img1 = _NewImage(112, 16, 32)
_Dest Img1
Cls , _RGBA32(127, 205, 255, 125)
Img1H = _CopyImage(Img1, 33)
_FreeImage Img1
' here it creates the Button image
Img2 = _NewImage(100, 50, 32)
_Dest Img2
Cls , _RGBA32(127, 0, 255, 180)
Color _RGBA32(183, 10, 140, 180), _RGBA32(0, 0, 0, 100)
_PrintString (10, 17), "Click Here"
Img2H = _CopyImage(Img2, 33)
_FreeImage Img2
' it creates image of popup from screen 0
Img3 = _NewImage(112, 64, 32)
_Dest Img3
Color _RGBA32(211, 166, 6, 255), _RGBA32(44, 44, 255, 255)
_PrintString (1, 1), "New.....Ctrl+N"
_PrintString (1, 16), "Open....Ctrl+O"
_PrintString (1, 32), "Close...Ctrl+X"
_PrintString (1, 48), "Quit....Ctrl+Q"
Img3H = _CopyImage(Img3, 33)
_FreeImage Img3

Screen 0
' inizialization and main loop
_Dest 0
Color 11, 3
Cls , 2
X = 0
Y = 0
Xm = 0
Ym = 0
Mb = 0
Do
    Cls , 2
    Locate 1, 1: Print "Left click to show popup menu"; ' it shows help on first line of text
    _PutImage (300, 300), Img2H, 0 ' button
    If _MouseInput Then
        X = _MouseX
        Y = _MouseY
        If _MouseButton(1) Then Mb = 1
        If _MouseButton(2) Then Mb = 2
    End If
    If Mb = 1 Then
        If X < 1 Or X + 13 > 80 Or Y < 1 Or Y + 3 > 24 Then
            Beep ' mouse's popup menu goes out of window's area
        Else
            Xm = X: Ym = Y ' X and Y  for popup and hovering menu
            ' popup menu
        End If
        Mb = 0
    End If
    If Xm And Ym Then
        _PutImage (1 + ((Xm - 1) * 8), 1 + ((Ym - 1) * 16)), Img3H, 0
        If (X >= Xm And X <= Xm + 13) And (Y >= Ym And Y <= Ym + 3) Then
            _PutImage ((Xm - 1) * 8, (Y - 1) * 16), Img1H, 0 ' hover / selection item of popup menu
        End If
    End If
    _Display
Loop Until Mb = 2
_FreeImage Img1H
_FreeImage Img2H
_FreeImage Img3H
End

the behaviour is the same, but we don't waste ram blocking pieces of this. 
In a large or intensive program that makes software images and convert them into hardware accellerated images, the management of unused software images makes the difference in performance of the application!

I must think that the same rule stands for re-using the same handle for more different software images. We must free ram from previous image before using again the same handle for another _NEWIMAGE!

explicative code:
Code: (Select All)

Dim As Long Img, Scr
Dim As Integer Counter
Scr = _NewImage(800, 600, 32)
Screen Scr
_Title "Freeimage for software images"
Img = _NewImage(100, 100, 32)
_Dest Img
For Counter = 1 To 10 Step 2
    Circle (50, 50), Counter * 2, _RGBA32(Counter + (Rnd * 200), Counter + (Rnd * 200), Counter + (Rnd * 200), 255)
Next Counter
_PutImage (100, 150), Img, 0,
_FreeImage Img

Img = _NewImage(200, 200, 32)
_Dest Img
For Counter = 10 To 100 Step 10
    Line (20 + Counter, 20 + Counter)-Step(80, 80), _RGBA32(Counter + (Rnd * 200), Counter + (Rnd * 200), Counter + (Rnd * 200), 255), B
Next Counter
_PutImage (100, 300), Img, 0,
_FreeImage Img

Img = _NewImage(300, 200, 32)
_Dest Img
For Counter = 1 To 50 Step 5
    Line (20 + Counter, 20 + Counter)-Step(100, 30), _RGBA32(Counter + (Rnd * 200), Counter + (Rnd * 200), Counter + (Rnd * 200), 255)
Next Counter
_PutImage (300, 350), Img, 0,
_FreeImage Img

End
Reply


Messages In This Thread
RE: Another way to think about hardware accelerated images in Screen 0 - by TempodiBasic - 03-30-2025, 08:33 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  about Hardware Images and _DisplayOrder,Help! qbfans 11 541 02-11-2026, 07:10 AM
Last Post: SMcNeill
  Nth problem with hardware images Ikerkaz 9 474 01-23-2026, 02:58 PM
Last Post: bplus
  Hardware images questions Dav 5 462 12-04-2025, 04:18 PM
Last Post: Pete
  Hardware images...Talk to me! Unseen Machine 5 723 09-22-2025, 11:12 PM
Last Post: TempodiBasic
  Transparency with Hardware Images NakedApe 8 1,021 07-10-2025, 09:47 AM
Last Post: Pete

Forum Jump:


Users browsing this thread: 1 Guest(s)