Page 1 of 1
PB 5.0 & XP 32 DrawText
Posted: Tue Nov 20, 2012 11:17 am
by Grunz
I can't find a way to make PB draw smooth = anti-aliased text.
At least not using the sprite & screen stuff. (Did not test gadgets)
Code: Select all
SmallFont = LoadFont(#PB_Any, "Microsoft YaHei", 10, #PB_Font_HighQuality)
I can make it use different fonts/sizes, but they all look ugly under Windows.
Under Linux, I still get beautiful smooth text.
Is it only XP or do other systems suffer from this too?
Can I somehow make PB draw smoothly?
Re: PB 5.0 & XP 32 DrawText
Posted: Tue Nov 20, 2012 4:11 pm
by TI-994A
Grunz wrote:I can't find a way to make PB draw smooth = anti-aliased text.
At least not using the sprite & screen stuff. (Did not test gadgets)
I can make it use different fonts/sizes, but they all look ugly under Windows.
Hi Grunz. I could be misunderstanding your point, but is this what you're talking about:
Code: Select all
EnableExplicit
UseJPEGImageDecoder()
UsePNGImageDecoder()
Enumeration
#Window
#Text
#Font
#Sprite
EndEnumeration
Define.s fileFilter, spriteFileName, wFlags.i
LoadFont(#Font, "Arial", 24)
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
If InitSprite() And OpenWindow(#Window, 0, 0, 300, 300, "Fonts on Window & Screen", wFlags)
TextGadget (#Text, 20, 10, 280, 30, "ABCDEFGHIJK...")
SetGadgetFont(#Text, FontID(#Font))
If OpenWindowedScreen(WindowID(#Window), 10, 50, 280, 240, 0, 0, 0)
fileFilter = "Graphic Files (BMP JPG PNG)|*.bmp;*.jpg;*.png"
spriteFileName = OpenFileRequester("Select image to use:", "C:\", fileFilter, 0)
If spriteFileName And LoadSprite(#Sprite, spriteFileName)
DisplaySprite(#Sprite, 0, 0)
StartDrawing(ScreenOutput())
DrawingFont(FontID(#Font))
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(10, 10, "ABCDEFGHIJK...", #Black)
StopDrawing()
EndIf
EndIf
EndIf
While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
The font results are pretty good, both on the window as well as on the screen, which is drawn alongside the displayed sprite. Perhaps this is not what you mean?
Re: PB 5.0 & XP 32 DrawText
Posted: Wed Nov 21, 2012 6:36 am
by Grunz
Try with smaller font:
Code: Select all
EnableExplicit
Enumeration
#Window
#Text
#Font
#Sprite
EndEnumeration
Define.s fileFilter, spriteFileName, wFlags.i
LoadFont(#Font, "Arial", 10)
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
If InitSprite() And OpenWindow(#Window, 0, 0, 300, 300, "Fonts on Window & Screen", wFlags)
TextGadget (#Text, 20, 10, 280, 30, "Ugly pixel font X / V")
SetGadgetFont(#Text, FontID(#Font))
If OpenWindowedScreen(WindowID(#Window), 10, 50, 280, 240, 0, 0, 0)
StartDrawing(ScreenOutput())
DrawingFont(FontID(#Font))
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(10, 10, "Ugly pixel font X / V", #bhite)
StopDrawing()
EndIf
EndIf
While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
I get clearly un-aliased output with this. "Stairs" are pretty obvious in diagonal lines.
Re: PB 5.0 & XP 32 DrawText
Posted: Wed Nov 21, 2012 7:18 am
by IdeasVacuum
Using Alpha_Blend mode will give a better result.
Re: PB 5.0 & XP 32 DrawText
Posted: Wed Nov 21, 2012 8:06 am
by TI-994A
Grunz wrote:Try with smaller font:
I get clearly un-aliased output with this. "Stairs" are pretty obvious in diagonal lines.
Hello again Grunz. Perhaps this workaround could work for you:
Code: Select all
EnableExplicit
Define.i wFlags, loop, font3, font4, sampleTxt.s, cFont.LOGFONT
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(0, 0, 0, 300, 150, "Font Qualities", wFlags)
SetWindowColor(0, #Black)
cFont\lfHeight = 16
cFont\lfWeight = #FW_REGULAR
cFont\lfQuality = #CLEARTYPE_QUALITY
PokeS(@cfont\lfFaceName[0], "Arial")
font3 = CreateFontIndirect_(@cFont)
cFont\lfQuality = #CLEARTYPE_NATURAL_QUALITY
font4 = CreateFontIndirect_(@cFont)
LoadFont(1, "Arial", 10)
LoadFont(2, "Arial", 10, #PB_Font_HighQuality)
While loop < 4
loop + 1
Read.s sampleTxt
TextGadget(loop, 20, 20 + (loop - 1) * 30, 300, 30, "ABC 123 - " + sampleTxt)
SetGadgetColor(loop, #PB_Gadget_FrontColor, #White)
SetGadgetColor(loop, #PB_Gadget_BackColor, #Black)
Wend
SetGadgetFont(1, FontID(1))
SetGadgetFont(2, FontID(2))
SetGadgetFont(3, font3)
SetGadgetFont(4, font4)
While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
DataSection
Data.s "Purebasic regular font...", "Purebasic high quality font..."
Data.s "Created cleartype font...", "Created cleartype natural font..."
EndDataSection
The
ClearType property smoothens out the font pixelations quite well.
Re: PB 5.0 & XP 32 DrawText
Posted: Wed Nov 21, 2012 5:13 pm
by Michael Vogel
Because of some drawtext restrictions (search for "Unsharp font when using AlphaBlend" or "Font is only in high quality if #PB_Font_Bold used" in the forum), I have decided to use the following workaround when needed: I create images which are twice as big (or even four times larger) than the needed result and resize the image after having done all text output on it. The outcome is great, but the CPU gets stressed.
Re: PB 5.0 & XP 32 DrawText
Posted: Thu Nov 22, 2012 12:34 am
by Grunz
Thanks for the info. Scaling might be most easy to do as I had to make the game write everything onto sprites anyway for PB4.x Windows.
Though I might instead scale all other things up and use a bigger screen anyway.
Old pixel gfx won't improve with a simple scale, but text will be a lot better.