Is this a bug in FreeBasic graphics?

General FreeBASIC programming questions.
Post Reply
neil
Posts: 594
Joined: Mar 17, 2022 23:26

Is this a bug in FreeBasic graphics?

Post by neil »

I'm attempting to erase a sprite without utilizing the CLS feature.
Even though I'm not using RGBA; I'm using RGB. I have to erase the ball sprite using Alpha.
In my opinion, while utilizing RGB, I shouldn't have to use Alpha in my code.
Could someone please check my code to see if there are any mistakes?
Here's an example:

Code: Select all

' sprite erase ball test without using CLS
' updated code using Pset

Screenres 640, 480, 32

Dim As Any Ptr DrawBall = ImageCreate( 80, 80, RGB(255, 255, 255)) 
Dim As Any Ptr EraseBall = ImageCreate( 80, 80, RGB(255, 255, 255))

Dim As Integer x, y, i

x = 40: y = 40

CIRCLE DrawBall, (x, y), 37, RGB(0, 255, 0),,,,F ' Green

' not needed
' CIRCLE EraseBall, (x, y), 37, RGB(0, 0, 0),,,,F ' Black

Color rgb(0 ,0, 0), rgb(255,255,255)
Cls

x = 10
for i = 1 to 136
ScreenLock

' this erases the ball using Alpha

' old code
' put(x, y),EraseBall, Alpha

' updated code
' Pset is needed to erase sprite
put (x, y), EraseBall, Pset


' this does not erase the ball as it should
' put(x, y),EraseBall

x += 4 ' move the ball 4 pixels at a time

' old code
' put(x, y),DrawBall

' updated code
' if you don't use Pset here it messes up the colors
put(x, y),DrawBall, Pset

ScreenUnlock

Sleep 5, 1

next
Locate 10,35:Print "Test Ended"

ImageDestroy DrawBall
ImageDestroy EraseBall
sleep
Last edited by neil on Apr 14, 2024 7:38, edited 2 times in total.
fxm
Moderator
Posts: 12139
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Is this a bug in FreeBasic graphics?

Post by fxm »

With 'Put', the default method used to draw the image to the destination buffer is XOR.
To erase the ball, use rather:
put(x, y),EraseBall, Pset
neil
Posts: 594
Joined: Mar 17, 2022 23:26

Re: Is this a bug in FreeBasic graphics?

Post by neil »

@fxm
I updated my code with comments. I also added.

put(x, y),DrawBall, Pset

Would it be better not to use Pset with DrawBall?

Maybe it runs faster without using it on DrawBall.
fxm
Moderator
Posts: 12139
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Is this a bug in FreeBasic graphics?

Post by fxm »

Minimum code without 'Put':

Code: Select all

Dim As Integer x = 40, y = 40

Screenres 640, 480, 32
For i As Integer = 1 To 140
    ScreenLock
    CIRCLE (x, y), 37, RGB(0, 0, 0),,,,F    '' erase the previous ball
    x += 4                                  '' move the ball 4 pixels at a time
    CIRCLE (x, y), 37, RGB(0, 255, 0),,,,F  '' draw the ball
    ScreenUnlock
    Sleep 5, 1
Next
Locate 10,35:Print "Test Ended"
Sleep
neil
Posts: 594
Joined: Mar 17, 2022 23:26

Re: Is this a bug in FreeBasic graphics?

Post by neil »

@fxm
I was only using the circle function to make a sprite.
I am trying to learn how to use Put correctly, so later I can use bit-mapped graphics and erase them without using CLS.
After I changed the screen color to white, I discovered I had to use Pset with DrawBall also.
Without using Pset with DrawBall, it messed up the colors. Anyway, thanks for your help.
fxm
Moderator
Posts: 12139
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Is this a bug in FreeBasic graphics?

Post by fxm »

How to optimize the size of image buffers:

Code: Select all

Screenres 640, 480, 32

Dim As Integer x, y, i
x = 37: y = 37
Dim As Any Ptr DrawBall = ImageCreate( 75, 75, RGB(255, 255, 255))   '' 75*75 pixels from index : 0 to 74
CIRCLE DrawBall, (x, y), 37, RGB(0, 255, 0),,,,F ' Green             '' circle from index : 37-37=0 to 37+37 = 74
Dim As Any Ptr EraseBall = ImageCreate( 75, 75, RGB(255, 255, 255))  '' 75*75 pixels from index : 0 to 74

Color rgb(0 ,0, 0), rgb(255,255,255)
Cls

x = 10
for i = 1 to 136
    ScreenLock
    put (x, y), EraseBall, Pset
    x += 4 ' move the ball 4 pixels at a time
    put(x, y),DrawBall, Pset
    ScreenUnlock
    Sleep 5, 1
next
Locate 10,35:Print "Test Ended"

ImageDestroy DrawBall
ImageDestroy EraseBall
sleep
Post Reply