It is currently Mon Dec 16, 2019 7:00 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: #PB_Sprite_AlphaBlending and TransparentSpriteColor()
PostPosted: Sun Jul 07, 2019 7:50 am 
Offline
Enthusiast
Enthusiast

Joined: Wed Sep 18, 2013 11:54 am
Posts: 392
Location: France
Hi,

I think I've spotted a bug, or at least an error somewhere, either in the doc or the general behavior of a transparent sprite.

Code:
EnableExplicit

#screen_width = 1920
#screen_height = 1080

Define sprite_mouse.i, sprite_fps.i, sprite_square.i
Define frame.i, frame$, frame_time.i, event.i

InitKeyboard() : InitMouse() : InitSprite()

OpenWindow(0, 0, 0, #screen_width, #screen_height, "TITLE", #PB_Window_BorderLess | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, #screen_width, #screen_height)

sprite_mouse = CreateSprite(#PB_Any, 7, 7)
StartDrawing(SpriteOutput(sprite_mouse))
Box(0, 0, OutputWidth(), OutputHeight(), #Black)
  Box(0, 0, OutputWidth() - 2, OutputHeight() - 2, #White)
StopDrawing()

sprite_fps = CreateSprite(#PB_Any, 40, 20)

MouseLocate(DesktopMouseX(), DesktopMouseY())

sprite_square = CreateSprite(#PB_Any, 200, 200, #PB_Sprite_AlphaBlending)   ; #PB_Sprite_AlphaBlending does not seem mandatory unlike what the doc says.
;sprite_square = CreateSprite(#PB_Any, 200, 200)
StartDrawing(SpriteOutput(sprite_square))
Box(0, 0, 100, 100, #White)
StopDrawing()
TransparentSpriteColor(#PB_Default, #Black)       ; 1/ Default should be black, but it's not. 2/ Assigning a new value to #PB_Default has no effect.
;TransparentSpriteColor(sprite_square, #Black)    ; TODO Comment out to see the change. This actually is the only way to make #Black transparent on this sprite (other than drawing on an intermediary transparent image, or changing the blending method).

Repeat
  Repeat
    event.i = WindowEvent()
    If event = #PB_Event_CloseWindow : Break 2 : EndIf
  Until event = 0
 
  ExamineKeyboard() : ExamineMouse()
 
  FlipBuffers()
  ClearScreen(RGB(50, 65, 70))
 
  DisplayTransparentSprite(sprite_square, ScreenWidth() / 2, ScreenHeight() / 2)
 
   ; FPS
  frame + 1
  If ElapsedMilliseconds() > frame_time
    frame_time = ElapsedMilliseconds() + 1000
    frame$ = Str(frame)
    frame = 0
    StartDrawing(SpriteOutput(sprite_fps))
      DrawText(0, 0, "fps:" + frame$)
    StopDrawing()
  EndIf
  DisplaySprite(sprite_fps, 0, 0)
 
  DisplaySprite(sprite_mouse, MouseX(), MouseY())
 
  Delay(1)
Until KeyboardReleased(#PB_Key_Escape)


My concern is from line 24 to line 30.

  • sprite_square is created with an alpha channel. But even with TransparentSpriteColor(#PB_Default, #Black), the sprite does not show any transparency.
  • Next thing to do is to uncomment line 30: TransparentSpriteColor(sprite_square, #Black). Now it works, #Black is transparent.
  • The weirdest part now. I've been coding with PB for a while now (on a very irregular basis I reckon), and I've always thought that when you want an alpha channel, you need #PB_Sprite_AlphaBlending. Even the documentation says that. So now: uncomment line 25 or create sprite_square without #PB_Sprite_AlphaBlending. Result: there is an alpha channel, and the default transparency color is #Black, as it should.
  • Without #PB_Sprite_AlphaBlending, setting a default transparent color with TransparentSpriteColor(#PB_Default) still doesn't work. TransparentSpriteColor(sprite_square, #White), however, makes #White transparent, as we could expect, even though #PB_Sprite_AlphaBlending is not specified.


Top
 Profile  
Reply with quote  
 Post subject: Re: #PB_Sprite_AlphaBlending and TransparentSpriteColor()
PostPosted: Sun Jul 07, 2019 8:13 am 
Offline
Addict
Addict

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 1165
Location: right here
I also made these observations. TransparentSpriteColor() is older than the alphachannel support. I guess they were never meant to be used together.


Top
 Profile  
Reply with quote  
 Post subject: Re: #PB_Sprite_AlphaBlending and TransparentSpriteColor()
PostPosted: Sun Jul 07, 2019 8:17 am 
Offline
Enthusiast
Enthusiast

Joined: Wed Sep 18, 2013 11:54 am
Posts: 392
Location: France
What about #PB_Sprite_AlphaBlending then? This thing seems useless.

EDIT: ignore that, it actually has an effect. Transparent color is different from variable alpha channel it seems. (no variation without #PB_Sprite_AlphaBlending) Problem is that there's no default transparent color with #PB_Sprite_AlphaBlending... Dilemma dilemma!

EDIT2: well no, I don't get it. Now when changing Box(0, 0, 100, 100, #White) to Box(0, 0, 100, 100, RGBA(255, 255, 255, 10)), there's still no transparency, it's full white (#PB_Sprite_AlphaBlending activated).


Top
 Profile  
Reply with quote  
 Post subject: Re: #PB_Sprite_AlphaBlending and TransparentSpriteColor()
PostPosted: Sun Jul 07, 2019 11:20 am 
Offline
Addict
Addict

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 1165
Location: right here
Joubarbe wrote:
EDIT2: well no, I don't get it. Now when changing Box(0, 0, 100, 100, #White) to Box(0, 0, 100, 100, RGBA(255, 255, 255, 10)), there's still no transparency, it's full white (#PB_Sprite_AlphaBlending activated).

Maybe you forgot to use a drawing mode with alpha channel?
Code:
DrawingMode(#PB_2DDrawing_AllChannels)
Box(0, 0, 100, 100, RGBA(255,255,255,10))


Top
 Profile  
Reply with quote  
 Post subject: Re: #PB_Sprite_AlphaBlending and TransparentSpriteColor()
PostPosted: Sun Jul 07, 2019 4:30 pm 
Offline
Enthusiast
Enthusiast

Joined: Wed Sep 18, 2013 11:54 am
Posts: 392
Location: France
So...

When you use #PB_2DDrawing_AllChannels, it works only without using "TransparentSpriteColor(sprite_square, #Black)". If you put a TransparentSpriteColor(), no matter what DrawingMode you use, it doesn't seem to have an effect.

Which leads me to thinking that on most drawing, "FillArea(0, 0, -1, RGBA(0 ,0 ,0, 0))" must be used if I want to have a transparent background color on my sprite. And that I should forget using TransparentSpriteColor().


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye