Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Pete1995
Reel Rookie

Strange Bitmap Update Behavior

I fail to understand the rules for updating Draw2D ops. My expectation is that bm.Finish() should update any cached drawing ops. However, when I GetByteArray(), there is nothing there. The following is a minimal working example. I do a Clear(). DrawRect(), Finish(), GetByteArray() and then manually write a value into the red byte. Then I print the byteArray. It's "empty", except the red value.

I display the bitmap and it looks as expected (minus the red pixel, of course). I GetByteArray() again, and now the Draw2D stuff is there! Do I misunderstand bm.Finish()? Or is this a bug?

Sub Main()
pixWidth = 10
bytesPerPix = 4
bytesPerRow = (pixWidth * bytesPerPix)
printRow = 3
screen = CreateObject("roScreen")

bm = CreateObject("roBitmap", {width:pixWidth, height:10, AlphaEnable:true, name:"test"})
bm.clear( &h808080FF)
bm.DrawRect( 2, 2, 6, 6, &hFFFFFFFF)
bm.Finish()
ba = bm.GetByteArray( 0, 0, pixWidth, 10)
ba[ (printRow * bytesPerRow) + (4 * bytesPerPix)] = &hFF

' Set index to start of 4th row. Setup to read a line of 10 pixels
indx = printRow * (pixWidth * bytesPerPix)

print "i"; TAB(16)"Red";TAB(22)"Grn";TAB(28)"Blu";TAB(34)"Alp"
for i = 0 to (pixWidth-1)
r = ba[indx ] : g = ba[indx+1] : b = ba[indx+2] : a = ba[indx+3]
print indx; TAB(16)r;TAB(22)g;TAB(28)b;TAB(34)a
indx += 4
endfor

screen.DrawObject( 0, 0, bm)
screen.SwapBuffers()
sleep(5000)
 
ba = bm.GetByteArray( 0, 0, pixWidth, 10)
print "i"; TAB(16)"Red";TAB(22)"Grn";TAB(28)"Blu";TAB(34)"Alp"
for i = 0 to (pixWidth-1)
r = ba[indx ] : g = ba[indx+1] : b = ba[indx+2] : a = ba[indx+3]
print indx; TAB(16)r;TAB(22)g;TAB(28)b;TAB(34)a
indx += 4
endfor
 
Any insight would be helpful. 

 

0 Kudos
2 REPLIES 2
renojim
Community Streaming Expert

Re: Strange Bitmap Update Behavior

It would help the readability of your code tremendously if you enclosed it in code tags (click the 3 dots and look for </>).

The first thing that jumps out is that you're creating a single buffered screen and using SwapBuffers which is for double buffered screens.

Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
0 Kudos
Pete1995
Reel Rookie

Re: Strange Bitmap Update Behavior

RenoJim, sorry about just dumping my code into the post. It's my first post with code and I didn't know how to include the example. Thanks for the tip.

I don't think buffering has any relevance to the issue. The example doesn't even need to be displayed. The issue is: draw into a bitmap, finish it, get the byte array, it's empty. It only takes 4 lines of code to reproduce. I just got verbose about it.  

My guess it's an issue with caching of draw ops in OpenGL, but what do I know?

0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.