"TheEndless" wrote:
You should always call .finish() after drawing to a bitmap.
I'm confused. If I call bitmap.finish() I get the tearing. If I don't call bitmap.finish() I don't get tearing, but you're saying this is the opposite of what should happen?
Furthermore, this has to do with my Roku 2 XS?
Library "v30/bslDefender.brs"
function Main()
? "bitmap tear v2"
screen = CreateObject("roScreen", True, 1280, 720)
msgport = CreateObject("roMessagePort")
screen.SetPort(msgport)
bitmap = CreateObject("roBitmap", { Width: 1280, Height: 720, AlphaEnable: True })
doFinish = True
codes = bslUniversalControlEventCodes()
? "Press 'B' to toggle bitmap.finish() on/off | Any other key to exit."
? "Calling bitmap.finish() = " ; doFinish
While True
msg = msgport.getmessage() ' poll for a button press
' returns IMMEDIATELY
if msg <> invalid and type(msg)="roUniversalControlEvent" then
b% = msg.GetInt()
if b% = codes.BUTTON_B_RELEASED then
doFinish = NOT doFinish
? "Calling bitmap.finish() = " ; doFinish
else if b% <> codes.BUTTON_B_PRESSED then
exit while
end if
end if
' Initiate drawing the the back buffer by clearing it.
screen.Clear(0)
' Create a bitmap in memory. We're not going to use it for anything.
' I believe the allocation of memory is what causes the flicker/tear.
' Comment this line out, replace it with a roBitmap created from a local path, or just move it above the Clear() and the flicker goes away.
' bitmap = CreateObject("roBitmap", { Width: 100, Height: 100, AlphaEnable: False }) 'Height and Width don't matter here
' Draw a red rect over the screen to make the issue more apparent
bitmap.DrawRect(0, 0, 1280, 720, &HFF0000FF)
if doFinish then
bitmap.finish()
end if
screen.DrawObject(0,0,bitmap)
screen.SwapBuffers()
End While
screen = Invalid
end function
B toggles bitmap.finish() on/off. Any other key exits.
peace & 42
ps - complete accident that there's 42 lines of code there.[Edit2: added "screen = Invalid" else the main Roku menu disappears after exiting the app.]
Edit: the code above is a tweaked version of code The Endless posted in another thread. Link is above.