GrabSprite makes black transparent

Just starting out? Need help? Post your questions and find answers here.
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

GrabSprite makes black transparent

Post 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
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: GrabSprite makes black transparent

Post 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
Last edited by infratec on Mon Nov 11, 2024 8:08 am, edited 1 time in total.
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: GrabSprite makes black transparent

Post 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?
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: GrabSprite makes black transparent

Post by infratec »

coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: GrabSprite makes black transparent

Post by coco2 »

Isn't it unnecessary to have a certain colour as transparent on 32 bit graphics with an alpha channel?
DarkDragon
Addict
Addict
Posts: 2347
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: GrabSprite makes black transparent

Post 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.
bye,
Daniel
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: GrabSprite makes black transparent

Post by coco2 »

I will set all my sprites to #Magenta and try to remember it.
DarkDragon
Addict
Addict
Posts: 2347
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: GrabSprite makes black transparent

Post 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.
bye,
Daniel
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: GrabSprite makes black transparent

Post 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.
Olli
Addict
Addict
Posts: 1266
Joined: Wed May 27, 2020 12:26 pm

Re: GrabSprite makes black transparent

Post 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
User avatar
SPH
Enthusiast
Enthusiast
Posts: 593
Joined: Tue Jan 04, 2011 6:21 pm

Re: GrabSprite makes black transparent

Post by SPH »

@Olli :

Completely black in your code !

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
Olli
Addict
Addict
Posts: 1266
Joined: Wed May 27, 2020 12:26 pm

Re: GrabSprite makes black transparent

Post 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.
Olli
Addict
Addict
Posts: 1266
Joined: Wed May 27, 2020 12:26 pm

Re: GrabSprite makes black transparent

Post 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.
Olli
Addict
Addict
Posts: 1266
Joined: Wed May 27, 2020 12:26 pm

Re: GrabSprite makes black transparent

Post 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()
Post Reply