Code: Select all
InitSprite()
InitKeyboard()
InitMouse()
WindowID = OpenWindow(0, 100, 100, 800, 600, "64x64 Red Square", #PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(0), 0, 0, 800, 600, 0, 0, 0)
#SquareWidth = 64
#SquareHeight = 64
#PixelCount = #SquareWidth * #SquareHeight
*redSquare = AllocateMemory(#PixelCount * 4) ; 4 bytes per pixel
If *redSquare
; Fill memory with red pixel values (BGRA: $0000FFFF)
For i = 0 To #PixelCount - 1
PokeL(*redSquare + i * 4, $FFFF0000)
Next
; Create a 64x64 image from raw memory
If CreateImage(0, #SquareWidth, #SquareHeight, 32)
StartDrawing(ImageOutput(0))
CopyMemory(*redSquare, DrawingBuffer(), #PixelCount * 4)
StopDrawing()
EndIf
EndIf
; Main loop
Repeat
Event = WindowEvent()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape)
Break
EndIf
If StartDrawing(ScreenOutput())
Box(0, 0, 800, 600, RGB(0, 0, 0)) ; Clear screen
DrawImage(ImageID(0), 100, 100) ; Draw red square at (100, 100)
StopDrawing()
FlipBuffers()
EndIf
ForEver
FreeMemory(*redSquare)
End
Code: Select all
InitSprite()
InitKeyboard()
InitMouse()
WindowID = OpenWindow(0, 100, 100, 800, 600, "10x10 Red Square (DataSection)", #PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(0), 0, 0, 800, 600, 0, 0, 0)
#SquareWidth = 10
#SquareHeight = 10
#PixelCount = #SquareWidth * #SquareHeight
*redSquare = AllocateMemory(#PixelCount * 4)
If *redSquare
Restore RedSquareData
For i = 0 To #PixelCount - 1
;ReadLong color
PokeL(*redSquare + i * 4, color)
Next
If CreateImage(0, #SquareWidth, #SquareHeight, 32)
StartDrawing(ImageOutput(0))
CopyMemory(*redSquare, DrawingBuffer(), #PixelCount * 4 )
StopDrawing()
EndIf
EndIf
Repeat
Event = WindowEvent()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape)
Break
EndIf
If StartDrawing(ScreenOutput())
Box(0, 0, 800, 600, RGB(0, 0, 0))
DrawImage(ImageID(0), 100, 100)
StopDrawing()
FlipBuffers()
EndIf
ForEver
FreeMemory(*redSquare)
End
DataSection
RedSquareData:
Data.l $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000
Data.l $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000
Data.l $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000
Data.l $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000
Data.l $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000
Data.l $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000
Data.l $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000
Data.l $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000
Data.l $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000
Data.l $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000
Data.l $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000, $FFF0000
EndDataSection
So that it doesn't work I don't see the red and I don't know to make this one
. This last method that I would want to see more that