PB 5.0 & XP 32 DrawText

Windows specific forum
Grunz
User
User
Posts: 59
Joined: Sat Nov 12, 2011 7:21 pm

PB 5.0 & XP 32 DrawText

Post 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?
User avatar
TI-994A
Addict
Addict
Posts: 2702
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: PB 5.0 & XP 32 DrawText

Post 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?
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Grunz
User
User
Posts: 59
Joined: Sat Nov 12, 2011 7:21 pm

Re: PB 5.0 & XP 32 DrawText

Post 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.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: PB 5.0 & XP 32 DrawText

Post by IdeasVacuum »

Using Alpha_Blend mode will give a better result.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
TI-994A
Addict
Addict
Posts: 2702
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: PB 5.0 & XP 32 DrawText

Post 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.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: PB 5.0 & XP 32 DrawText

Post 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.
Grunz
User
User
Posts: 59
Joined: Sat Nov 12, 2011 7:21 pm

Re: PB 5.0 & XP 32 DrawText

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