Forum Discussion

Pete1995's avatar
Pete1995
Channel Surfer
6 months ago

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. 

 

4 Replies

  • renojim's avatar
    renojim
    Community Streaming Expert

    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.

    • Pete1995's avatar
      Pete1995
      Channel Surfer

      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?

      • renojim's avatar
        renojim
        Community Streaming Expert

        I just tried it and it does seem like a bug, but it would be hard to believe that no one noticed it by now.  The bitmap seems to get updated when screen.Finish() gets called.