Page 1 of 1

alphablend not working on font with screen output (5.72 x64)

Posted: Sat Jun 13, 2020 3:13 pm
by case
it's not possible to use the alphablend mode on drawtext on a screenoutput() but this work on a canvas.

also on a canvas if the frontcolor is transparent and the font backcolor is not, the font will not display the background image under the font.
but display the font backcolor.

Code: Select all

InitSprite()
Global main=OpenWindow(#PB_Any,800,600,800,600,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
Global scr=OpenWindowedScreen(WindowID(main),0,0,800,600)
Global fnt=LoadFont(#PB_Any,"consolas",16)

; dessine un fond aleatoire pour le test
StartDrawing(ScreenOutput())
For k=0 To 24
  LineXY(0,k,24,k,RGB(Random(200)+55,Random(200)+55,Random(200)+55))
Next
fond=GrabDrawingImage(#PB_Any,0,0,24,24)
StopDrawing()

; affiche les glyphes de la font par dessus le fond en transparence... ne fonctionne pas

For a =032 To 255
  WaitWindowEvent(0)
  ClearScreen(0)
  StartDrawing(ScreenOutput())
  DrawingFont(FontID(fnt))
  DrawImage(ImageID(fond),0,0)
  DrawImage(ImageID(fond),0,24)
  DrawingMode(#PB_2DDrawing_AlphaBlend)
  FrontColor(RGBA(255,255,255,100))   ; devrait etre transparent (alpha a zero)
  BackColor(RGBA(0,0,0,100))       
  DrawText(0,0,Chr(a))
  DrawText(0,24,Chr(a),RGBA(0,0,0,0),RGB(255,255,100)); devrait etre transparent (alpha a zero)
  StopDrawing() 
  FlipBuffers()
  Delay(100)
Next
// Edit: Moved to "Coding Questions" (Kiffi)

Re: alphablend not working on font with screen output (5.72

Posted: Sat Jun 13, 2020 6:01 pm
by Saki
Hi, this is a little strange, use it so :

Code: Select all

      DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Transparent)
Best Regards Saki

Re: alphablend not working on font with screen output (5.72

Posted: Sat Jun 13, 2020 6:53 pm
by STARGĂ…TE
#PB_2DDrawing_AlphaBlend is only supported for ImageOutput() and CanvasOutput(), but not ScreenOutput()!
https://www.purebasic.com/documentation ... gmode.html

Re: alphablend not working on font with screen output (5.72

Posted: Sat Jun 13, 2020 9:34 pm
by case
my bad... i didn't read the small prints :)

Re: alphablend not working on font with screen output (5.72

Posted: Sat Jun 13, 2020 11:27 pm
by Olli
case wrote:it's not possible to use the alphablend mode on drawtext on a screenoutput()
Here(Windows only but easily available on Linux) you have draw text in sprites, far quicker than immediate DrawText() and than immediate DrawAlphaImage(). This to do what you describe.

This is largely better than #PB_2DDrawing_AlphaBlend.
It's definitively not a bug.

Re: alphablend not working on font with screen output (5.72

Posted: Sun Jun 14, 2020 3:35 pm
by RASHAD
Hi case
Just in case you want to use ScreenOutput()

Code: Select all

InitSprite()
Global main=OpenWindow(#PB_Any,800,600,800,600,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
Global scr=OpenWindowedScreen(WindowID(main),0,0,800,600)
Global fnt=LoadFont(#PB_Any,"consolas",16)
Global fond
; dessine un fond aleatoire pour le test
StartDrawing(ScreenOutput())
For k=0 To 24
  LineXY(0,k,24,k,RGB(Random(200)+55,Random(200)+55,Random(200)+55))
Next
fond=GrabDrawingImage(#PB_Any,0,0,24,24)
StopDrawing()

CreateImage(100,24,48,24)

Procedure drwtext(a)
  StartDrawing(ImageOutput(100))
    DrawImage(ImageID(fond),0,0)
    DrawImage(ImageID(fond),0,24)
    DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Transparent )
    DrawingFont(FontID(fnt))
    FrontColor(RGBA(255,255,255,100))
    BackColor(RGBA(0,0,0,100))
    DrawText(0,0,Chr(a))
    FrontColor(RGBA(0,0,0,100))
    BackColor(RGBA(255,255,255,100))
    DrawText(0,24,Chr(a))
  StopDrawing()
EndProcedure

; affiche les glyphes de la font par dessus le fond en transparence... ne fonctionne pas

For a =032 To 255
  WaitWindowEvent(0)
  ClearScreen(0)
  drwtext(a)
  StartDrawing(ScreenOutput())
  DrawImage(ImageID(100),0,0)
  StopDrawing()
  FlipBuffers()
  Delay(100)
Next

Re: alphablend not working on font with screen output (5.72

Posted: Fri Jun 19, 2020 8:53 am
by Mesa
For a max of speed, use only sprites, not images:

Code: Select all

If InitSprite()
  InitKeyboard()
  InitMouse()
EndIf

Global main=OpenWindow(#PB_Any,800,600,800,600,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu) 
Global scr=OpenWindowedScreen(WindowID(main),0,0,800,600) 
Global fnt=LoadFont(#PB_Any,"consolas",16)  


fond=CreateSprite(#PB_Any, 800, 600)
StartDrawing(SpriteOutput(fond))
For k=0 To 600 
  LineXY(0,k,800,k,RGB(Random(200)+55,Random(200)+55,Random(200)+55)) 
Next 
StopDrawing()


Dim chars(255)
For a =032 To 255
  chars(a) = CreateSprite(#PB_Any, 24, 24, #PB_Sprite_AlphaBlending)
  StartDrawing(SpriteOutput(chars(a)))
  DrawingMode(#PB_2DDrawing_Transparent)
  DrawText(0,0,Chr(a),RGBA(255,0,0,128),RGBA(0,0,0,255))
  StopDrawing()
Next a


Repeat 
  
  Repeat
    
    Evenement = WindowEvent() 
    
    Select Evenement   
      Case #PB_Event_CloseWindow
        End
    EndSelect 
  Until Evenement=0
  
  
  FlipBuffers() 
  ExamineKeyboard() 
  
  a=Random(255,32)
  DisplaySprite(fond,0,0)
  TransparentSpriteColor(chars(a),$0) 
  DisplayTransparentSprite(chars(a), Random(800),Random(600))
  Delay(100)   
  
  
Until KeyboardPushed(#PB_Key_Escape)

M.