It is currently Wed Jan 27, 2021 8:06 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: draw transparent text on a transparent background problem ?
PostPosted: Sun Oct 18, 2020 5:49 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu May 06, 2010 10:16 am
Posts: 621
Location: Belgium
Hello,

After a lot of time of testing, I still have this transparent text problem ...
see https://www.purebasic.fr/english/viewtopic.php?f=13&t=76081

When I draw transparent text on a transparent background, the text quality is very, very bad ?
Is this a bug or is this normal ?

Image

Tested with WIN10 - x64 - PB5.72 x64 and PB5.72 x86 - (PB5.73 x64)

marc

_________________
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...


Top
 Profile  
Reply with quote  
 Post subject: Re: draw transparent text on a transparent background proble
PostPosted: Sun Nov 01, 2020 1:09 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jan 10, 2008 1:30 pm
Posts: 1369
Location: Germany, Glienicke
On this example code, I can not see any differents:
Code:
Enumeration
   #Window
   #Gadget
   #Image
   #Font
EndEnumeration

Procedure CustomBackground(X, Y, Front, Back)
   If X % 40 < 20 XOr Y % 40 < 20
      ProcedureReturn $FF0000C0
   Else
      ProcedureReturn $FF0000FF
   EndIf
EndProcedure

OpenWindow(#Window, 0, 0, 800, 450, "Vector Canvas Gadget", #PB_Window_MaximizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
CanvasGadget(#Gadget, 0, 0, WindowWidth(#Window), WindowHeight(#Window), #PB_Canvas_Keyboard)

LoadFont(#Font, "Calibri", 48)

CreateImage(#Image, 800, 450, 32)
If StartDrawing(ImageOutput(#Image))
   DrawingMode(#PB_2DDrawing_Gradient|#PB_2DDrawing_AllChannels)
   LinearGradient(0, 0, 0, 450)
   GradientColor(0.0, $FFFF0000)
   GradientColor(1.0, $00FF0000)
   Box(0, 0, 400, 450)
   DrawingMode(#PB_2DDrawing_AllChannels)
   Box(400, 0, 400, 450, $00000000)
   Line(400, 0, 1, 450, $FF000000)
   DrawingMode(#PB_2DDrawing_AlphaBlend|#PB_2DDrawing_Transparent)
   DrawText(20, 20, "Text on semi-transparent image", $FFFFFFFF)
   DrawText(420, 20, "Text on transparent image", $FFFFFFFF)
   DrawingFont(FontID(#Font))
   For I = 50 To 350 Step 50
      DrawText(25, I, "Hello World!", $FFFFFFFF)
      DrawText(425, I, "Hello World!", $FFFFFFFF)
   Next
   StopDrawing()
EndIf

If StartDrawing(CanvasOutput(#Gadget))
   DrawingMode(#PB_2DDrawing_CustomFilter)
   CustomFilterCallback(@CustomBackground())
   Box(0, 0, 800, 450)
   DrawingMode(#PB_2DDrawing_AlphaBlend)
   DrawAlphaImage(ImageID(#Image), 0, 0)
   StopDrawing()
EndIf

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow

End

Image

_________________
ImageImage


Top
 Profile  
Reply with quote  
 Post subject: Re: draw transparent text on a transparent background proble
PostPosted: Sun Nov 01, 2020 6:45 pm 
Offline
Addict
Addict
User avatar

Joined: Mon Jul 25, 2005 3:51 pm
Posts: 3767
Location: Utah, USA
@marc_256: See my solution code in the thread you linked to. It draws the text consistently over both backgrounds.

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: draw transparent text on a transparent background proble
PostPosted: Thu Nov 05, 2020 11:30 am 
Offline
Enthusiast
Enthusiast

Joined: Thu May 06, 2010 10:16 am
Posts: 621
Location: Belgium
Hallo STARGÅTE,

I use Windowed ScreenOutput ...

@Demivec,

I tested it and is not working for my application,
so I use a workaround now ... but I loos some speed now.
And speed is all I need in my CAD/CAM/CNC program.


thanks,
marco

_________________
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...


Top
 Profile  
Reply with quote  
 Post subject: Re: draw transparent text on a transparent background proble
PostPosted: Thu Nov 05, 2020 10:01 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jan 10, 2008 1:30 pm
Posts: 1369
Location: Germany, Glienicke
marc_256 wrote:
Hallo STARGÅTE,

I use Windowed ScreenOutput ...
For ScreenOutput() the flag #PB_2DDrawing_AlphaBlend is not supported by DrawingMode()!
That meens you can not draw a text with semi-transparent anti-aliased border!
The text is just drawed with "clear type" mode, if this is activated in windows.
Here an image for comparison:
Image
___



However, you can draw the text on an semi-transparent image, and draw this image with DrawAlphaImage, which supported this alpha channel. (as you can see in code below).

Code:
Enumeration
   #Window
   #Image
   #Font
EndEnumeration

InitSprite()

OpenWindow(#Window, 0, 0, 1200, 450, "Vector Canvas Gadget", #PB_Window_MaximizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(#Window), 0, 0, 1200, 450)

LoadFont(#Font, "Calibri", 48)

CreateImage(#Image, 800, 450, 32)
If StartDrawing(ImageOutput(#Image))
   DrawingMode(#PB_2DDrawing_Gradient|#PB_2DDrawing_AllChannels)
   LinearGradient(0, 0, 0, 450)
   GradientColor(0.0, $FFFF0000)
   GradientColor(1.0, $00FF0000)
   Box(0, 0, 400, 450)
   DrawingMode(#PB_2DDrawing_AllChannels)
   Box(400, 0, 400, 450, $00000000)
   Line(400, 0, 1, 450, $FF000000)
   DrawingMode(#PB_2DDrawing_AlphaBlend|#PB_2DDrawing_Transparent)
   DrawText(20, 20, "Text on semi-transparent image", $FFFFFFFF)
   DrawText(420, 20, "Text on transparent image", $FFFFFFFF)
   DrawingFont(FontID(#Font))
   For I = 50 To 350 Step 50
      DrawText(25, I, "Hello World!", $FFFFFFFF)
      DrawText(425, I, "Hello World!", $FFFFFFFF)
   Next
   StopDrawing()
EndIf

If StartDrawing(ScreenOutput())
   Box(0, 0, 1200, 450, $000000)
   DrawAlphaImage(ImageID(#Image), 0, 0)
   DrawingMode(#PB_2DDrawing_Transparent)
   DrawText(820, 20, "Text on screen do not support alpha blending!", $FFFFFF)
   DrawingFont(FontID(#Font))
   For I = 50 To 350 Step 50
      DrawText(825, I, "Hello World!", $FFFFFF)
   Next
   StopDrawing()
EndIf

Repeat
   FlipBuffers()
Until WaitWindowEvent() = #PB_Event_CloseWindow

End

_________________
ImageImage


Top
 Profile  
Reply with quote  
 Post subject: Re: draw transparent text on a transparent background proble
PostPosted: Fri Nov 06, 2020 12:44 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu May 06, 2010 10:16 am
Posts: 621
Location: Belgium
Hi STARGÅTE,

OK, now I understand why it don't work in Windowed Screen mode ...

thanks for clearing this up,
marco

_________________
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...


Top
 Profile  
Reply with quote  
 Post subject: Re: draw transparent text on a transparent background proble
PostPosted: Fri Nov 06, 2020 6:03 pm 
Offline
Always Here
Always Here

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 5219
Location: Germany
You can use a CanvasGadget which fills the whole 'screen' and draw everything on this gadget.


Top
 Profile  
Reply with quote  
 Post subject: Re: draw transparent text on a transparent background proble
PostPosted: Fri Nov 06, 2020 9:09 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Jun 24, 2006 3:29 am
Posts: 269
Location: Edinburgh, Scotland.
Just an aside, I really like the UI of your CAD/CAM program - especially in other screenshots :) Elegant and simple. Congrats for that...

_________________
Proud supporter of PB! * Musician * C64/6502 Freak


Top
 Profile  
Reply with quote  
 Post subject: Re: draw transparent text on a transparent background proble
PostPosted: Sun Nov 08, 2020 12:36 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu May 06, 2010 10:16 am
Posts: 621
Location: Belgium
@ infratec,
Can I use images and sprites on canvas gadget ?
First at all I lover PB, I have an love/hate relationship with PB.
In the last 10 years I use PB, I never could finish one huge program with PB.
There was always a bug or a malfunction in PB to finish my work.
So, now I will never use one PB gadget anymore in my programs ...
and create them myself inside the screen mode.

@oreopa
Thanks for your support ...
my latest CNC part is the best GUI I ever created,
will show it in other forum selection soon ...

thanks,
marco

_________________
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...


Top
 Profile  
Reply with quote  
 Post subject: Re: draw transparent text on a transparent background proble
PostPosted: Sun Nov 08, 2020 1:08 pm 
Offline
Always Here
Always Here

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 5219
Location: Germany
You can use images, since a canvas can be a container.

As I know you can not place gadgets on a screen, only inside a window.
So if you now use a screen for sprites, how can you place gedgets on it?
And if ou use a window 'beside' you can place a canvas over the whole window to draw on it.

If you want to use something like gadgets on a screen you have to do this by yourself.
This is the case since I use PB.


Top
 Profile  
Reply with quote  
 Post subject: Re: draw transparent text on a transparent background proble
PostPosted: Sun Nov 08, 2020 1:30 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Apr 05, 2020 11:28 am
Posts: 426
Location: Pandora
On canvas everything is actually much easier.
Sprites can also be output on canvas, you just have to clip the mask away.
Images and text can be output directly to canvas.
The chunk of your program are the many graphic outputs.
The output on canvas or image is very fast.
The time needed to code all this is in my opinion much less and more simple than if you do it all on screen.
Speed is often just a matter of precise consideration.

The more you deal with all these things the better you can do it.
Actually you are constantly learning.
When you are finished with a big project, you often realize that you could have done a lot better with new insights.
That is just so, annoying, but with more learning hardly to avoid.

Best Regards Saki

_________________
地球上の平和


Last edited by Saki on Mon Nov 30, 2020 2:30 pm, edited 3 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: draw transparent text on a transparent background proble
PostPosted: Sun Nov 08, 2020 7:50 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1791
Location: Germany
infratec wrote:
As I know you can not place gadgets on a screen, only inside a window.

infratec wrote:
If you want to use something like gadgets on a screen you have to do this by yourself.
This is the case since I use PB.

You may try PureBasic's library Gadget3D instead of Gadget (just try PureBasic's example Gadget3d.pb - it's even cross-platform!):
The Gadget3D library allows to create complex Graphical User Interface (GUI) directly over the screen area, using the 3D engine. This is mainly intended for game or application which needs user inputs while running in fullscreen mode.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 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