Dear Cerberus X User!
As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.
Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.
Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!
Accepting ensures:
- Continued access to your account with a short break for the actual transfer.
- Retention of your data under the same terms.
Without consent:
- You don't have further access to your forum user account.
- Your account and personal data will be deleted after April 5, 2024.
- Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.
We hope to keep you in our community and see you on the forum soon!
All the best
Your Cerberus X Team
Yes!I need to use a databuffer and readpixels function?
Import mojo2
Import brl
Class MyApp Extends App
Field canvas:Canvas
Field myCanvas:Canvas
Field myImage:Image
Field myData:DataBuffer
Method OnCreate:Int()
canvas = New Canvas()
' Set up a sprite that you can draw to
myImage = New Image(256, 256)
myCanvas = New Canvas(myImage)
myData = New DataBuffer(256 * 256 * 4)
End
Method OnRender:Int()
' Draw 256 x 256 green sprite
myCanvas.Clear(0,1,0)
' Plot pixel
myData.PokeInt(0,myData.PeekInt(0) & $00000000) ' Make a pixel in the sprite black (0 is mapped to x & y)
myImage.WritePixels(0,0,1,1, myData)
myCanvas.Flush()
' Read pixel
myCanvas.ReadPixels(0,0,1,1,myData)
Local value:Int = myData.PeekInt(0) ' Read a pixel in the sprite black (0 is mapped to x & y)
' ---------------------------------------
' Draw our canvas-image-combo, to main canvas
canvas.SetBlendMode(BlendMode.Opaque2)
canvas.Clear(0,0,0)
canvas.DrawImage(myImage, 50,50)
canvas.Flush()
End
End
Function Main:Int()
New MyApp()
End
Import mojo2
Import brl.databuffer
Class MyApp Extends App
Field mainCanvas:Canvas
Field myImage:Image
Field myData:DataBuffer
Field myCanvas:Canvas
Method OnCreate:Int()
mainCanvas = New Canvas()
myImage = New Image(256, 256)
myCanvas = New Canvas(myImage)
myData = New DataBuffer(256 * 256 * 4)
End
Method OnRender:Int()
myCanvas.Clear(0,1,0)
' Plot pixel
myData.PokeInt(0, $ffffffff)
myImage.WritePixels(0, 0, 1,1, myData)
myCanvas.Flush()
' Read pixel
myCanvas.ReadPixels(0, 0, 1,1 myData)
Local value:Int = myData.PeekInt(0)
mainCanvas.SetBlendMode(BlendMode.Opaque2)
mainCanvas.Clear()
mainCanvas.DrawImage(myImage, 200,200)
mainCanvas.Flush()
End
End
Function Main:Int()
New MyApp()
Return 0
End
Local value:Int = myData.PeekInt(0) ' This is the read
Import mojo2
Import brl
Class MyApp Extends App
Field mainCanvas:Canvas
Field myImage:Image
Field myData:DataBuffer
Field myCanvas:Canvas
Method OnCreate:Int()
mainCanvas = New Canvas()
myImage = New Image(256, 256)
myCanvas = New Canvas(myImage)
myData = New DataBuffer(256 * 256 * 4)
End
Method OnRender:Int()
myCanvas.Clear(0,0.1,0)
' Read all pixels so we can change a single pixel because reading and writing 1x1 area gives artefacts)
myCanvas.ReadPixels(0,0,256,256,myData)
' Plot pixel
myData.PokeInt(0,$ffffffff)
myImage.WritePixels(0,0,256,256,myData)
myCanvas.Flush()
' Read pixel
Local value:Int = myData.PeekInt(0) ' This is the read
' To proove we read it, let's write a clone-pixel, 2 steps to the right
myData.PokeInt(2*4,value)
myImage.WritePixels(0,0,256,256,myData)
myCanvas.Flush()
Local myString:String = Int(value) ' Cast (meaning convert) the integer (which is the pixel we read) to a string
mainCanvas.SetBlendMode(BlendMode.Opaque2)
mainCanvas.Clear(0,0,0)
mainCanvas.DrawImage(myImage,200,200)
mainCanvas.DrawText "The pixel value is",200,200,.5,.5
mainCanvas.DrawText myString,200,240,.5,.5
mainCanvas.Flush()
End
End
Function Main:Int()
New MyApp()
End
Local rgba:Int = a Shl 24 | b Shl 16 | g Shl 8 | r
a = rgba Shr 24) & $ff
b = (rgba Shr 16) & $ff
g = (rgba Shr 8) & $ff
r = (rgba) & $ff
Import mojo2
Import brl
Class MyApp Extends App
Field mainCanvas:Canvas
Field myImage:Image
Field myData:DataBuffer
Field myCanvas:Canvas
Method OnCreate:Int()
mainCanvas = New Canvas()
myImage = New Image(256, 256)
myCanvas = New Canvas(myImage)
myData = New DataBuffer(256 * 256 * 4)
End
Method OnRender:Int()
myCanvas.Clear(0,0.1,0)
myCanvas.ReadPixels(0,0,256,256,myData) ' Step one is to read all pixels from canvas into buffer (myData)
myCanvas.Flush()
Local rgba:Int = myData.PeekInt(0) ' Next step is to read pixel from the buffer
Local a:Int = (rgba Shr 24) & $ff ' Now check the pixel out
Local b:Int = (rgba Shr 16) & $ff
Local g:Int = (rgba Shr 8) & $ff
Local r:Int = (rgba) & $ff
Local myString:String = Int(a) ' We want to print alpha of pixel
mainCanvas.Clear(0,0,0)
mainCanvas.DrawText myString,200,240,.5,.5
mainCanvas.Flush()
End
End
Function Main:Int()
New MyApp()
End