Page 1 of 1

GrabSprite makes black transparent

Posted: Mon Nov 11, 2024 6:11 am
by coco2
Possible bug?

Code: Select all

OpenWindow(0, 100, 100, 500, 500, "Test GrabSprite", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
InitSprite()
OpenWindowedScreen(WindowID(0), 0, 0, 500*DesktopResolutionX(), 500*DesktopResolutionY())
CreateSprite(0, 20, 20, #PB_Sprite_AlphaBlending)
ClearScreen(#Blue)
StartDrawing(ScreenOutput())
Box(240*DesktopResolutionX(), 240*DesktopResolutionY(), 10*DesktopResolutionX(), 10*DesktopResolutionY(), RGBA(0, 0, 0, 255))
Box(250*DesktopResolutionX(), 240*DesktopResolutionY(), 10*DesktopResolutionX(), 10*DesktopResolutionY(), RGBA(255, 255, 255, 255))
Box(240*DesktopResolutionX(), 250*DesktopResolutionY(), 10*DesktopResolutionX(), 10*DesktopResolutionY(), RGBA(255, 255, 255, 255))
Box(250*DesktopResolutionX(), 250*DesktopResolutionY(), 10*DesktopResolutionX(), 10*DesktopResolutionY(), RGBA(0, 0, 0, 255))
StopDrawing()
GrabSprite(0, 240*DesktopResolutionX(), 240*DesktopResolutionY(), 20*DesktopResolutionX(), 20*DesktopResolutionY(), #PB_Sprite_AlphaBlending)
DisplayTransparentSprite(0, 150*DesktopResolutionX(), 150*DesktopResolutionY())
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow

Re: GrabSprite makes black transparent

Posted: Mon Nov 11, 2024 8:02 am
by infratec
Hm ...

black is a special colour.
If you use CreateSprite() the default color is black. And black is used as transparent color.
(You can comment out your blck boxes to see that)

If you use 1, 1, 1, 255 as color, it works as expected,

https://www.purebasic.com/documentation ... prite.html

Re: GrabSprite makes black transparent

Posted: Mon Nov 11, 2024 8:08 am
by coco2
Black doesn't need to be a special colour does it? Perhaps this is some legacy code going back to the early days?

Re: GrabSprite makes black transparent

Posted: Mon Nov 11, 2024 8:08 am
by infratec

Re: GrabSprite makes black transparent

Posted: Mon Nov 11, 2024 9:27 am
by coco2
Isn't it unnecessary to have a certain colour as transparent on 32 bit graphics with an alpha channel?

Re: GrabSprite makes black transparent

Posted: Mon Nov 11, 2024 12:36 pm
by DarkDragon
coco2 wrote: Mon Nov 11, 2024 9:27 am Isn't it unnecessary to have a certain colour as transparent on 32 bit graphics with an alpha channel?
Nowadays, yes. IIRC this command is from DX7 times where blitting was still used.

Re: GrabSprite makes black transparent

Posted: Mon Nov 11, 2024 1:29 pm
by coco2
I will set all my sprites to #Magenta and try to remember it.

Re: GrabSprite makes black transparent

Posted: Mon Nov 11, 2024 3:00 pm
by DarkDragon
coco2 wrote: Mon Nov 11, 2024 1:29 pm I will set all my sprites to #Magenta and try to remember it.
You can also use DisplaySprite instead if you don't want transparency.

Re: GrabSprite makes black transparent

Posted: Tue Nov 12, 2024 1:04 am
by coco2
You can also use DisplaySprite instead if you don't want transparency.
Thanks for letting me know. It could be used for background sprites etc.

Re: GrabSprite makes black transparent

Posted: Tue Nov 12, 2024 11:58 pm
by Olli

Code: Select all

OpenWindow(0, 100, 100, 500, 500, "Test GrabSprite", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
InitSprite()
OpenWindowedScreen(WindowID(0), 0, 0, 500*DesktopResolutionX(), 500*DesktopResolutionY())
ClearScreen(#Blue)
StartDrawing(ScreenOutput())
Box(240*DesktopResolutionX(), 240*DesktopResolutionY(), 10*DesktopResolutionX(), 10*DesktopResolutionY(), RGBA(0, 0, 0, 255))
Box(250*DesktopResolutionX(), 240*DesktopResolutionY(), 10*DesktopResolutionX(), 10*DesktopResolutionY(), RGBA(255, 255, 255, 255))
Box(240*DesktopResolutionX(), 250*DesktopResolutionY(), 10*DesktopResolutionX(), 10*DesktopResolutionY(), RGBA(255, 255, 255, 255))
Box(250*DesktopResolutionX(), 250*DesktopResolutionY(), 10*DesktopResolutionX(), 10*DesktopResolutionY(), RGBA(0, 0, 0, 255))
StopDrawing()
GrabSprite(0, 240*DesktopResolutionX(), 240*DesktopResolutionY(), 20*DesktopResolutionX(), 20*DesktopResolutionY(), #PB_Sprite_AlphaBlending)
DisplayTransparentSprite(0, 150*DesktopResolutionX(), 150*DesktopResolutionY())
FlipBuffers()
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow

; HomeBoard indexAll times are UTC+01:00

Re: GrabSprite makes black transparent

Posted: Wed Nov 13, 2024 7:54 am
by SPH
@Olli :

Completely black in your code !

Re: GrabSprite makes black transparent

Posted: Wed Nov 13, 2024 7:46 pm
by Olli
@sph

We have a real black. As you can see, and conforming to the title description, the problem is solved also !! :mrgreen:

Also, in 2010, G-ROM told the order of 'clearScreen', 'examineKeyboard' and 'examineMouse' might be kept on Linux.

Re: GrabSprite makes black transparent

Posted: Thu Nov 14, 2024 9:12 am
by Olli
I am writing a full screen small example.
Since then 4.40, I think, we can open and close, a full screen and a windowed screen on the fly.

Re: GrabSprite makes black transparent

Posted: Sat Nov 16, 2024 1:49 pm
by Olli
You set the alpha after having grabed.

Code: Select all

StartDrawing(SpriteOutput(0) )
 DrawingMode(#PB_2DDrawing_AlphaChannel)
 Box(0, 0, OutputWidth(), OutputHeight(), RGBA(0,0,0,255) )
StopDrawing()