Mintoris Forum

Author Topic: Displaying text  (Read 3306 times)

Crazy C

  • Full Member
  • ***
  • Posts: 19
Displaying text
« on: Jun 07, 2018, 08:49 PM »
Just bought Mintoris Basic.

How can text be displayed in Game engine mode?
I used GenFont, GenText (using the font) and GenAddText,
nothing displayed…

sraffens

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 220
Re: Displaying text
« Reply #1 on: Jun 07, 2018, 09:17 PM »
I would assume that you have added the text object to a layer.
I would assume the the color of the text is different then the background.

What does your code looks like?

Crazy C

  • Full Member
  • ***
  • Posts: 19
Re: Displaying text
« Reply #2 on: Jun 08, 2018, 02:12 PM »
My program looks like this:


Orientation 2
GameEngine On
FonEnc=GenFont("/TEST/FONTS/ENCODE-SANS/ENCODESANS-BOLD.TTF")
TexMin=GenText("Some text…",FonEnc,150,150,800,0)

GenAddText TexMin,15
GenSetTextColor TexMin,100,100,100,50

Wait


That's all…

Mintoris

  • Administrator
  • Full Member
  • *****
  • Posts: 57
Re: Displaying text
« Reply #3 on: Jun 08, 2018, 02:55 PM »
You need to put your font into the tile atlas.


Code: [Select]
' Create a tile atlas
atlas = GenTileAtlas(1024, 1024)

' Put the font into the atlas
GenMapToAtlas atlas, font, 0, 0

' Load the atlas into the GPU
GenLoadAtlas atlas

Crazy C

  • Full Member
  • ***
  • Posts: 19
Re: Displaying text
« Reply #4 on: Jun 08, 2018, 04:23 PM »
Yes, I now see the text:

It looks AWFUL‼

The text has small lines and points below of some of the characters
and the antialiasing produces big pixels, what's this???


Crazy C

  • Full Member
  • ***
  • Posts: 19
Re: Displaying text
« Reply #5 on: Jun 08, 2018, 05:18 PM »
My resolution is 800 x 480 in landscape mode.
Is there something wrong with scaling?
I omitted the width and height in the GameEngine On command…
With all characters there's missing the most upper line(s) of pixels, for example the upper case 'D'.
The lower case 'i's point above the i is not a complete circle, but has one or two missing lines of top most pixels.
So it seems the characters are copied beginning from the SECOND or THIRD line (too late) and there are also copied the first one or two lines of the characters which are positioned below these characters in the atlas (if I let all the characters be only in the first line in the atlas, the additional pixels that are copied are black, so you don't notice that effect then). But the first vertical pixels of all chars that reach the upper bound of the charset are always missing, no matter if the chars are in just one line or in two lines in the atlas.

(Sorry for my english‼)

Also used another ttf font, the same problem…

What is the original or minimum charsize I should use for the GenFont command?
« Last Edit: Jun 09, 2018, 12:19 PM by Crazy C »

Mintoris

  • Administrator
  • Full Member
  • *****
  • Posts: 57
Re: Displaying text
« Reply #6 on: Jun 08, 2018, 07:01 PM »
First of all, sorry for the state of the game engine documentation, it needs a lot of work.

I'm pretty sure the problem with the text has to do with the scaling. Text should look perfect if all the scaling is right

Understanding tilesets and tile atlases is the key to understanding the game engine.

Please read the following link: Tiles, Tilesets and Tile Atlases

I'm planning to create custom editors in the new Version 8 platform to help in creating tilesets and atlases. (I'm coding as fast as I can :) )

I think the program below is a good starting point.

Code: [Select]
include "Game Engine Constants.inc"

' Create the game engine font
font = GenDefaultFont(Font_Normal)

' Get the bitmap from the font just so
' we can look at it.
bitmap = GenGetBitmap(font)

orientation 2
Graphics on

' Show the font for a few seconds
DrawBitmap bitmap, screenx()/2, screeny()/2

wait 2000

GameEngine On

' Create a tile atlas
atlas = GenTileAtlas(512, 512)

' Put the font into the atlas
GenMapToAtlas atlas, font, 0, 0

' Load the atlas into the GPU
GenLoadAtlas atlas

' Create a Game Engine text object.
text = GenText("Hello World", font, ScreenX()/2, ScreenY()/2, ScreenX(), Align_Center)

' Add the text to layer 0 to
' make it visible.
GenAddText text, 0
« Last Edit: Jun 08, 2018, 09:22 PM by Mintoris »

Crazy C

  • Full Member
  • ***
  • Posts: 19
Re: Displaying text
« Reply #7 on: Jun 09, 2018, 10:47 AM »
Okay, I used all combinations of parameters in your atlas, tileset, font and text routines and I can tell you that it is nothing but a mess.
Sad.

Mintoris

  • Administrator
  • Full Member
  • *****
  • Posts: 57
Re: Displaying text
« Reply #8 on: Jun 09, 2018, 12:12 PM »
try:

font = GenFont("font.ttf", 16, 16)

or

font = GenFont("font.ttf", 32, 16)


Crazy C

  • Full Member
  • ***
  • Posts: 19
Re: Displaying text
« Reply #9 on: Jun 09, 2018, 12:25 PM »
…16,16
…32,16

The same problem.

Mintoris

  • Administrator
  • Full Member
  • *****
  • Posts: 57
Re: Displaying text
« Reply #10 on: Jun 09, 2018, 06:25 PM »
Not sure now, text has always looked perfect. What version of Android are you running and has anyone else had this problem.

Crazy C

  • Full Member
  • ***
  • Posts: 19
Re: Displaying text
« Reply #11 on: Jun 09, 2018, 06:29 PM »
Android version is 4.4.4 KITKAT…

Mintoris

  • Administrator
  • Full Member
  • *****
  • Posts: 57
Re: Displaying text
« Reply #12 on: Jun 09, 2018, 06:36 PM »
Hmm, that's pretty old and I bet the GPU functions are being emulated in software. Is it possible to try a newer device?

Crazy C

  • Full Member
  • ***
  • Posts: 19
Re: Displaying text
« Reply #13 on: Jun 09, 2018, 06:59 PM »
Could it be that hardware acceleration has something to do with it?
Hardware acceleration is said to be supported since Android 3.0.
RFO BASIC works fine with hardware acceleration turned on (60 fps) and without (30 fps), no problems, text and images look much better than with Mintoris BASIC, perfect‼

And: I have no performance problems, but there are bugs in the font or atlas routines.
« Last Edit: Jun 09, 2018, 07:31 PM by Crazy C »

Crazy C

  • Full Member
  • ***
  • Posts: 19
Re: Displaying text
« Reply #14 on: Jun 10, 2018, 11:53 AM »
Here's an attachment: A screenshot of my text output in the program…
If you tap it to enlarge it you can see that the upper pixels are missing (look at the little i, there is not a full circle, the upper lines of pixels are missing).
Also, there are additional pixels below some of the characters (I think they are from the characters that are below the first line of the font characters in the atlas).
« Last Edit: Jun 10, 2018, 12:07 PM by Crazy C »

Mintoris

  • Administrator
  • Full Member
  • *****
  • Posts: 57
Re: Displaying text
« Reply #15 on: Jun 11, 2018, 02:00 AM »
You were right, there was a bug in the text measuring routines. I just released 7.5.11 to fix this problem. It should be available as soon as Google approves it.

Mintoris

  • Administrator
  • Full Member
  • *****
  • Posts: 57
Re: Displaying text
« Reply #16 on: Jun 11, 2018, 04:17 AM »
Well the update is live. Please let me know if this solved the problem. I didn't do anything with the anti-alias. I can adjust, but I remember experimenting when I wrote that section and this setting looked the best. But then again I thought the text measuring was working correctly too. Took me all day to fix this, half the day was spent getting the old version 7.5 to compile. It looks like it's been over a year since the last update. I was a little miffed about losing a days work on version 8, but when I was done I realize that it was this exact same problem causing me trouble with the dialog box text sizes. I copied the new measuring routine into version 8 and wow, the dialog box text looks great now. So cool.

Oh, text in the game engine looks best if it's not scaled. Make your text the size you need it to be and all will look well. It's ok to use scaling when you are doing a fast text effect. If it's fast you won't notice anything. The way the game engine generates graphics is totally different than the old bitmap approach. I mean you load your bitmaps into the GPU's (on chip) memory and then it's all tiles. There is no easy access to pixels. It's all moving graphic tiles around. I've hidden most of the gory details from you, but it's still rather complicated. I plan to make things so much simpler and gui in version 8. Right now we have version 1 of the game engine.
« Last Edit: Jun 11, 2018, 04:30 AM by Mintoris »

Crazy C

  • Full Member
  • ***
  • Posts: 19
Re: Displaying text
« Reply #17 on: Jun 11, 2018, 08:52 AM »
Next round…

The additional lines of pixels below the characters vanished.

But see the difference between RFO BASIC and Mintoris:
In both of the screenshots I used char size 50 (in Mintoris in the GenFont command and with no GenSetTextScale command, so it's default, 1.0 and I made sure that no tileset below the font tileset in the atlas overlaps with the font tileset, see the difference (size, antialiasing? and maybe the distance between characters in some cases)…
« Last Edit: Jun 11, 2018, 04:02 PM by Crazy C »

Crazy C

  • Full Member
  • ***
  • Posts: 19
Re: Displaying text
« Reply #18 on: Jun 12, 2018, 11:32 AM »
With charsizes that are powers of 8 it looks much better, but not as good as with RFO BASIC. SetTextScale always ruins the look of the characters. The same with image sprites: The images look good when they are drawn on the screen, but SetSpriteScale let the images become bad antialiasing.
Is there any antialiasing performed when scaling at all?
Are such scaling commands really useful?
And you should be able to have nice font rendering with any charsizes, not only powers of 8…


Mintoris

  • Administrator
  • Full Member
  • *****
  • Posts: 57
Re: Displaying text
« Reply #19 on: Jun 13, 2018, 12:50 AM »
There was a bug in the Android anti-alias routine before API 18 (4.3.x).  Your phone is doing with software something that is done with hardware in later devices. I spent all day yesterday working on the text routines. I even downloaded the RFO source and checked out how they were displaying text. The only difference I could find was that they set the stroke width to 0. That prevents the letter outline from being drawn. That could be causing the problems so I did the same. And, yes we both use the same anti-alias setting. I also worked more on the text sizing routines and there should be some improvement there. You can't compare the RFO text size to the tile size used in the game engine. The game engine text size sets the size of the letter tile. Then the font is created to fit inside the tile. RFO text size is in scaled pixels, which have their own rules about sizing.

Version 7.5.12 should be available now with these changes.
« Last Edit: Jun 13, 2018, 01:09 AM by Mintoris »