DrawingMode, AllChannels, Transparent

Linux specific forum
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

DrawingMode, AllChannels, Transparent

Post by #NULL »

The DrawingMode combination of AllChannels and Transparent seems not to be working correctly.
In case of 'spr4' the text background is drawn even with the transparent flag set, and it's drawn using the frontcolor.
In case of 'spr5' the AllChannels operation is separated from the Transparent one, which is working fine even in combination with the AlphaBlend flag, but i'm not sure the resulting blended color is correct, though that could be my ignorance about blending modes.

Ubuntu 16.04.3 LTS
PureBasic 5.61 (Linux - x64)
PureBasic 5.46 LTS Beta 1 (Linux - x64) (tested in fullscreen)

Code: Select all

InitSprite()
InitKeyboard()

ww=800
wh=600

win=OpenWindow(#PB_Any, 50,100, ww,wh, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(win), 0,0, ww,wh, 1,0,0)

w = 45
h = 45

spr1 = CreateSprite(#PB_Any, w, h, #PB_Sprite_AlphaBlending)
StartDrawing(SpriteOutput(spr1))
  DrawingMode(#PB_2DDrawing_AllChannels)
  Box(0, 0, w, h, $ff00ff00)
StopDrawing()

spr2 = CreateSprite(#PB_Any, w, h, #PB_Sprite_AlphaBlending)
StartDrawing(SpriteOutput(spr2))
  DrawingMode(#PB_2DDrawing_AllChannels)
  DrawText(0, 0, "Text")
StopDrawing()

spr3 = CreateSprite(#PB_Any, w, h, #PB_Sprite_AlphaBlending)
StartDrawing(SpriteOutput(spr3))
  DrawingMode(#PB_2DDrawing_AlphaBlend)
  DrawText(0, 0, "Text")
StopDrawing()

spr4 = CreateSprite(#PB_Any, w, h, #PB_Sprite_AlphaBlending)
StartDrawing(SpriteOutput(spr4))
  DrawingMode(#PB_2DDrawing_AllChannels | #PB_2DDrawing_Transparent) ; transparent, should not draw text background
  Box(0,0,20,30,$8800ff00)
  DrawText(0, 0, "Text")                         ; background is drawn, using frontcolor
  DrawText(5, 5, "Text", $88888888)              ; background is drawn, using frontcolor
  DrawText(10, 10, "Text", $880000ff, $00000000) ; background is drawn, using frontcolor
StopDrawing()

spr5 = CreateSprite(#PB_Any, w, h, #PB_Sprite_AlphaBlending)
StartDrawing(SpriteOutput(spr5))
  DrawingMode(#PB_2DDrawing_AllChannels)
  Box(0,0,20,30,$0)
  DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Transparent)
  DrawText(0, 0, "Text")
  DrawText(5, 5, "Text", $88888888)
  DrawText(10, 10, "Text", $880000ff, $00000000)
  
  Debug Hex(AlphaBlend($000000ff,$88888888)) ; 88888888
  Debug Hex(AlphaBlend($88888888,$000000ff)) ; 88888888

StopDrawing()

Repeat
  ExamineKeyboard()
  
  Repeat
    event = WindowEvent()
    Select event
      Case #PB_Event_CloseWindow
        quit = #True
    EndSelect
  Until Not event
  
  DisplayTransparentSprite(spr1, 10, 10)
  DisplayTransparentSprite(spr2, 60, 10)
  DisplayTransparentSprite(spr3, 110, 10)
  DisplayTransparentSprite(spr4, 160, 10)
  DisplayTransparentSprite(spr5, 210, 10)
  
  FlipBuffers()
  ClearScreen($333333)
Until quit Or KeyboardPushed(#PB_Key_Escape)
User avatar
Demivec
Addict
Addict
Posts: 4086
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: DrawingMode, AllChannels, Transparent

Post by Demivec »

Just a small note in case you are unaware, DrawingMode()'s flags AllChannels and AlphaBlend should only work with ImageOutput() and CanvasOutput() and should be ignored for all other outputs.

This still makes what you are reporting a bug if those flags are not ignored for SpriteOutput() and if they cause the flag Tranparent not to function correctly with DrawText().
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: DrawingMode, AllChannels, Transparent

Post by walbus »

As a hint :
With BucketFill_advanced (BF ) you can output all things as BF sprites on PB sprites
With alpha blending and invisible color, simple all available PB 2D graphic functions, what ever you want
BF sprites can be inserted directly into PB sprites like a drawing function or animated with FlipBuffers_BF
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: DrawingMode, AllChannels, Transparent

Post by walbus »

Because this problems to the BF code packet new demo codes added :
BucketFill_Text_output_with_DrawText_BF_as_PB_Sprite.pb
BucketFill_Text_output_with_DrawText_BF_directly_in_a_PB_Sprite.pb
BucketFill_Text_output_with_DrawText_BF_directly_on screen.pb
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: DrawingMode, AllChannels, Transparent

Post by #NULL »

Demivec wrote:Just a small note in case you are unaware, DrawingMode()'s flags AllChannels and AlphaBlend should only work with ImageOutput() and CanvasOutput() and should be ignored for all other outputs.
Yes, i was unaware of that. I used those flags with sprites and they always worked :o but you're right, it's in the documentation.

Now i wonder what the official support for Alphachannel with Sprites and Drawing looks like, if something like that exists at all? You would need something like AllChannells to clear the sprite via Box() and something like AlphaBlend for, well, alphablending with the drawing commands like Box(),Line() etc. .Would i have to take the additional step by drawing to an image and draw the image to the sprite?
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: DrawingMode, AllChannels, Transparent

Post by walbus »

A Sample
Create a new sprite with a black background
Define black a invisible color
Now, you can output this new sprite with alpha blending and invisible color on screen

The problem with text is often a other
Is the output with edge smoothing (Antialiasing)
Antialiasing is nice, but....
This Antialiasing damage the sprite mask on the edges
So you can not get the output without artifacts and your text looking ugly
Also this antialiasing effects are different on different OS

Before output your text sprite you should remove this artifacts :wink:

Here a little sample for simple using
This sample works, but looking, you see on the red background little antialiasing artifacts
For fixing this, you must use a invisible sprite color nearly the red mask color
Then, it looks on the red background good, but not on blue and black backgrounds
So you must use for each different output a suitable invisible color for the background
Depending on what you do, these negative effects can be small or extremely strong and very ugly

Code: Select all

InitSprite()

EnableExplicit

LoadFont(1, "Arial", 48, #PB_Font_Bold)

Define width=400
Define height=200

Define window_ID=OpenWindow(#PB_Any, 0, 0, width, height, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

OpenWindowedScreen(WindowID(window_ID), 0, 0, width, height)

Define sprite_1_ID=CreateSprite(#PB_Any, width, height)

Define sprite_2_ID=CreateSprite(#PB_Any, width, height)

StartDrawing(SpriteOutput(sprite_1_ID))
Box(0, 0, width/4, height, $FF0000)
Box(width-width/4, 0, width/4, height, $FF)
StopDrawing()

StartDrawing(SpriteOutput(sprite_2_ID))
DrawingFont(FontID(1))
Circle(100, 100, 80, $FFFF00)
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(10, 10, "Hello World")
StopDrawing()

Repeat
  Repeat ; Get all window events before FlipBuffers
    Define win_event=WaitWindowEvent(1)
    If win_event=#PB_Event_CloseWindow
      End
    EndIf
  Until Not win_event
    FlipBuffers()
    ClearScreen(RGB(0, 0, 0))
    DisplaySprite(sprite_1_ID, 0, 0)
    DisplayTransparentSprite(sprite_2_ID, 10, 10, 128)
ForEver
Post Reply