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

Just starting out? Need help? Post your questions and find answers here.
case
Enthusiast
Enthusiast
Posts: 141
Joined: Thu Aug 07, 2003 11:09 am

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

Post 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)
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

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

Post by Saki »

Hi, this is a little strange, use it so :

Code: Select all

      DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Transparent)
Best Regards Saki
地球上の平和
User avatar
STARGÅTE
Addict
Addict
Posts: 2231
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

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

Post by STARGÅTE »

#PB_2DDrawing_AlphaBlend is only supported for ImageOutput() and CanvasOutput(), but not ScreenOutput()!
https://www.purebasic.com/documentation ... gmode.html
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
case
Enthusiast
Enthusiast
Posts: 141
Joined: Thu Aug 07, 2003 11:09 am

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

Post by case »

my bad... i didn't read the small prints :)
Olli
Addict
Addict
Posts: 1240
Joined: Wed May 27, 2020 12:26 pm

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

Post 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.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4953
Joined: Sun Apr 12, 2009 6:27 am

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

Post 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
Egypt my love
Mesa
Enthusiast
Enthusiast
Posts: 433
Joined: Fri Feb 24, 2012 10:19 am

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

Post 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.
Post Reply