Feature Request: Font/text object support

View previous topic View next topic Go down

Feature Request: Font/text object support

Post by Quork on Tue May 17, 2016 9:24 pm

The topic of mileage posts on BWR brought my mind back to this, I think I once mentioned it back on Michelle's boards. A support for text objects, parametrised in anmiated, route and panel files, would be really great for many things like signs. LokSim3D e.g. has a very simple implementation of this; font files are simple textures and a text file outlining the coordinates for every letter.
avatar
Quork

Posts : 1087
Join date : 2012-05-05
Age : 26
Location : Hofheim a.T., Hessen (Hesse), European Union

Back to top Go down

Re: Feature Request: Font/text object support

Post by MattD6R on Tue May 17, 2016 10:00 pm

I would find this useful and make it much easier with my WIP route as I am using different signal number plates for each signal.

MattD6R

Posts : 243
Join date : 2013-06-16
Location : Brisbane, Australia

Back to top Go down

Re: Feature Request: Font/text object support

Post by leezer3 on Wed May 18, 2016 1:51 am

That's actually quite easy Smile

(Relatively speaking....)

Tonight's build has a first draft implementation of this, using a variant on the Texture command.
First off, I'll show you a sample CSV implementation:
Code:
SetText,Hello World!
SetBackgroundColor,255,0,0
SetTextColor,0,0,255
SetTextPadding,0,120
SetFont,Times New Roman
SetTextureCoordinates,0,0,1
SetTextureCoordinates,1,0,0
SetTextureCoordinates,2,1,0
SetTextureCoordinates,3,1,1

In essence, this will dynamically create an appropriate texture at load time, using the following paramaters:
Text - The text to print
BackgroundColor - The background color of the image
TextColor - The color of the text
TextPadding - The amount of horizontal and vertical padding in pixels
Font - The full name to use when creating this text.

Texture co-ordinates should be set exactly as normal to get the text displaying as you wish.

B3D files are still a WIP, as I need to figure exactly what to do with spaces in text/ font names (They work as per above, but with Text, TextColor etc.)
Object Viewer and Route Viewer have both been updated, but I haven't generated a new build for those, will do so tomorrow.

Known bugs & limitations:
Text length is limited to 1024 pixels, and line wrapping is not currently supported.
No current way to set font size.

Both of these will be fixed, I just need to figure out the most appropriate way of dealing with them.

Cheers

Chris Lees

http://www.bvecornwall.co.uk

leezer3

Posts : 955
Join date : 2011-08-23

http://www.bvecornwall.co.uk

Back to top Go down

Re: Feature Request: Font/text object support

Post by MattD6R on Wed May 18, 2016 5:04 am

I tried this on one of my signs but it only displayed as a white textures without any errors being displayed. I added your sample to a csv object file in place of a texture and I can't see where I have gone wrong.

Thanks for this, though I still have to index separate objects. It would be nice if it could be done from a route command if that is possible.

MattD6R

Posts : 243
Join date : 2013-06-16
Location : Brisbane, Australia

Back to top Go down

Re: Feature Request: Font/text object support

Post by Quork on Wed May 18, 2016 8:18 am

Wow! Great =D And you're fast Shocked Hope you don't get a ticket for overspeed coding Laughing

And yes, doing it from the Route File would be what helps most and is what I meant, but I guess Chris first wants to get it to work itself before putting it deep into the code.
avatar
Quork

Posts : 1087
Join date : 2012-05-05
Age : 26
Location : Hofheim a.T., Hessen (Hesse), European Union

Back to top Go down

Re: Feature Request: Font/text object support

Post by leezer3 on Thu May 19, 2016 12:42 am

Updated the tools build:
http://vps.bvecornwall.co.uk/OpenBVE/Stable/developerTools_1.4.4.0.7z

This also contains one further interesting change for Route Viewer:
Renderer statistics (FPS, total static objects etc.) are now displayed by default.
Press F10 to hide them.

I've tested this complete object with the main OpenBVE build, Object Viewer and Route Viewer:
Code:
CreateMeshBuilder,
AddVertex,-3.2, 1.81, 0,
AddVertex,-0.8, 1.81, 0,
AddVertex,-0.8, 1, 0,
AddVertex,-3.2, 1, 0,
AddFace,0,1,2,3,
GenerateNormals,
SetText,Hello World Sign!
SetTextureCoordinates,0, 0, 0,
SetTextureCoordinates,1, 1, 0,
SetTextureCoordinates,2, 1, 1,
SetTextureCoordinates,3, 0, 1,
SetDecalTransparentColor,0,0,0,
SetEmissiveColor,60,60,60

CreateMeshBuilder,
AddVertex,-2.4, 1.81, 0.02,
AddVertex,-1.6, 1.81, 0.02,
AddVertex,-1.6, 1, 0.02,
AddVertex,-2.4, 1, 0.02,
AddFace,3,2,1,0,
SetColor,150,150,150

CreateMeshBuilder,
AddVertex,-2.025, 1.7, 0.04,
AddVertex,-1.955, 1.7, 0.04,
AddVertex,-1.955, -0.3, 0.04,
AddVertex,-2.025, -0.3, 0.04,
AddFace2,0,1,2,3,
SetColor,100,100,100

Very simple 'hello world' sign Smile

Previous bugs still apply, no further work has been done today.

Route Files:
Generating a texture is easy, but there's nowhere in the current object placement commands that would let us add a text parameter easily.
In order to do this properly, it'll require a totally new command, and this isn't in the absolute immediate plans-

I want to add a complete set of 'new' commands to provide an standardized way to do things such as approach controlled signalling, power gaps etc. but I haven't got the details worked out at present.
Even when I've figured out an approximate plan, it'll (hopefully) need some input from some of the other established route authors before making it into full production mode.

Cheers

Chris Lees

http://www.bvecornwall.co.uk

leezer3

Posts : 955
Join date : 2011-08-23

http://www.bvecornwall.co.uk

Back to top Go down

Re: Feature Request: Font/text object support

Post by MattD6R on Thu May 19, 2016 1:13 am

My sign works fine with the updated route and object viewer but not with the main program. I did re download the main program to make sure but it still displays a white texture.

Good to see the stats on route viewer though the FPS changes too quickly to be able to read the number.

It will be good to do it from the route file, but there's no hurry. Thanks for your great work you are doing. Very Happy

MattD6R

Posts : 243
Join date : 2013-06-16
Location : Brisbane, Australia

Back to top Go down

Re: Feature Request: Font/text object support

Post by Greater Anglia Metro on Thu May 19, 2016 8:29 am

Could I request the possibility to set a background texture with the text on, and the possibility to use custom fonts (can be included in object folder)?
avatar
Greater Anglia Metro

Posts : 117
Join date : 2012-03-24
Age : 24
Location : London

Back to top Go down

Re: Feature Request: Font/text object support

Post by leezer3 on Thu May 19, 2016 12:15 pm

MattD6R wrote:My sign works fine with the updated route and object viewer but not with the main program. I did re download the main program to make sure but it still displays a white texture.

Good to see the stats on route viewer though the FPS changes too quickly to be able to read the number.

It will be good to do it from the route file, but there's no hurry. Thanks for your great work you are doing. Very Happy

Will check the main program later, not sure why it's not working for you Sad

Final note:
Stats in Route Viewer are marginally different to those in the main program, as the renderer is a rather cut-down variant, which also handles animations a little differently. The raw numbers are still useful though Smile

At some stage, I'm probably going to merge the two programs, as Route Viewer has no support for the plugin interface, and it's a pain porting changes between the two, but that's in the planning stages at the minute.

Greater Anglia Metro wrote:Could I request the possibility to set a background texture with the text on, and the possibility to use custom fonts (can be included in object folder)?

Background texture is easy, but would only be available for textures natively supported by the .Net framework, as opposed to any others. (bmp, png, gif and tiff)

Custom fonts is do-able, but I'm a little more ambivalent about that-
The code itself isn't hard, but I'm not sure it's the best idea in the world to start loading custom fonts with multi-platform and licensing issues in mind.
Which font are you looking at specifically?

Cheers

Chris Lees

http://www.bvecornwall.co.uk

leezer3

Posts : 955
Join date : 2011-08-23

http://www.bvecornwall.co.uk

Back to top Go down

Re: Feature Request: Font/text object support

Post by Quork on Thu May 19, 2016 12:45 pm

Well the LS3D approach is to have the object creator make a texture with all relevant font symbols and that's what is being used by the program; different to your approach. This has the big advantage of the whole trouble of licensing issues etc. is being sorted by the creator and everyone else gets a usable object without any prerequisites required.
Also this way arguably the font isn't being redistributed, since the simple image file (thus pixel graphics) doesn't get even close to substituting an actual, usable font. It's just a series of pixel graphics getting glued together in a very specific, fixed context, lacking the versatility and features of the actual font with all its weights and types, kerning, special chars, scalability, and so on. As to parametrising this from within the route file: Wouldn't there be space for the text attribute behind all other current parameters?

Track.FreeObj RailIndex; FreeObjStructureIndex; X; Y; Yaw; Pitch; Roll; Text


Obviously, you could only reference one text per object, but I think that's a sensible limitation.
avatar
Quork

Posts : 1087
Join date : 2012-05-05
Age : 26
Location : Hofheim a.T., Hessen (Hesse), European Union

Back to top Go down

Re: Feature Request: Font/text object support

Post by MattD6R on Thu May 19, 2016 1:07 pm

The stats you have added are useful but the fps values change too frequently in my opinion to be able to read it. It would be good if it can be slowed down.

MattD6R

Posts : 243
Join date : 2013-06-16
Location : Brisbane, Australia

Back to top Go down

Re: Feature Request: Font/text object support

Post by Greater Anglia Metro on Thu May 19, 2016 1:46 pm

leezer3 wrote:
Greater Anglia Metro wrote:Could I request the possibility to set a background texture with the text on, and the possibility to use custom fonts (can be included in object folder)?

Background texture is easy, but would only be available for textures natively supported by the .Net framework, as opposed to any others. (bmp, png, gif and tiff)

Custom fonts is do-able, but I'm a little more ambivalent about that-
The code itself isn't hard, but I'm not sure it's the best idea in the world to start loading custom fonts with multi-platform and licensing issues in mind.
Which font are you looking at specifically?

Cheers

Chris Lees

http://www.bvecornwall.co.uk

The open version of New Johnston - Transport for London/London Underground's font.
avatar
Greater Anglia Metro

Posts : 117
Join date : 2012-03-24
Age : 24
Location : London

Back to top Go down

Re: Feature Request: Font/text object support

Post by leezer3 on Sat May 21, 2016 12:20 am

Both builds have now been updated.
http://vps.bvecornwall.co.uk/OpenBVE/Builds/OpenBVE-2016-05-20.tar.gz
http://vps.bvecornwall.co.uk/OpenBVE/Builds/OpenBVE-2016-05-20.dmg
http://vps.bvecornwall.co.uk/OpenBVE/Stable/developerTools_1.4.4.0.7z

Changes:

  • If an image is provided, text added using the SetText command will be overlaid onto it, using the padding as the top-left text coordinate.
  • Transparent colors now work.
  • Text overlay method moved into the API. (Seemed the logical place for it)


Text overlays should also work this time in the main build (typo.....)

Font loading isn't implemented at the minute, but probably will be- Need to think about the best way to do this without messing up the font search, although as noted above I'm not entirely thrilled with the idea.

Haven't tested what this does to loading speeds either, so use with a little caution; 100s of signal numberplates may cause troubles.

Cheers

Chris Lees

http://www.bvecornwall.co.uk

leezer3

Posts : 955
Join date : 2011-08-23

http://www.bvecornwall.co.uk

Back to top Go down

Re: Feature Request: Font/text object support

Post by leezer3 on Sat May 21, 2016 12:31 am

Quork wrote:Track.FreeObj RailIndex; FreeObjStructureIndex; X; Y; Yaw; Pitch; Roll; Text


Obviously, you could only reference one text per object, but I think that's a sensible limitation.

If this gets implemented, it'll probably be through a completely separate command, e.g. Track.Sign

Adding extra parameters (overloads technically) to existing well-established commands is IMHO a nasty hack, and one that should be avoided if at all possible.
Using a completely separate command also gives clear separation from any other potential changes made by me or another fork Smile

Quork wrote:Well the LS3D approach is to have the object creator make a texture with all relevant font symbols and that's what is being used by the program; different to your approach. This has the big advantage of the whole trouble of licensing issues etc. is being sorted by the creator and everyone else gets a usable object without any prerequisites required.
Also this way arguably the font isn't being redistributed, since the simple image file (thus pixel graphics) doesn't get even close to substituting an actual, usable font. It's just a series of pixel graphics getting glued together in a very specific, fixed context, lacking the versatility and features of the actual font with all its weights and types, kerning, special chars, scalability, and so on. As to parametrising this from within the route file: Wouldn't there be space for the text attribute behind all other current parameters?

Using a sprite texture for the font is not an easy solution from the program developer's point of view, and would probably take 10 times the code, as well as being a good deal slower Razz
Perfectly valid solution, but I'd rather not make work for myself when I don't have to.

Small additional query:
Can those playing with this please give me your thoughts as to whether an anti-aliasing parameter would be worthwhile?
Not sure whether it's worth it or not, but easy enough to add.

Cheers

Chris Lees

http://www.bvecornwall.co.uk

leezer3

Posts : 955
Join date : 2011-08-23

http://www.bvecornwall.co.uk

Back to top Go down

Re: Feature Request: Font/text object support

Post by Quork on Sat May 21, 2016 12:43 am

Ah, sprite, that's the technical term, thanks =D

I wasn't aware though, that it would be so much more work to do, I'd have guessed the other way round Laughing
avatar
Quork

Posts : 1087
Join date : 2012-05-05
Age : 26
Location : Hofheim a.T., Hessen (Hesse), European Union

Back to top Go down

Re: Feature Request: Font/text object support

Post by MattD6R on Sat May 21, 2016 2:32 am

The text on the sign works using the main program but not correctly. It shown correctly on route viewer as white text on a black background. On the main program it is shown as white on a transparent background but no transparency has been used.

With my hand created signal number plates I have the text on two lines which doesn't seem possible at the moment. Adding anti-aliasing might make it look less pixelated but doesn't look too bad. Even though I have only 22 signal plates on my route and it will be a long time before I use hundreds of them, I probably won't use this on all of them for the moment. Especially as I can easily create them by hand depending on what impact this would have on performance.

MattD6R

Posts : 243
Join date : 2013-06-16
Location : Brisbane, Australia

Back to top Go down

Re: Feature Request: Font/text object support

Post by MattD6R on Sun May 29, 2016 1:13 am

Like it was before, the text on the sign doesn't work in the main program but it does works fine in the Route Viewer. Though as I have said I won't be using this at the moment especially if it could affect performance. This is the code which I think should work:

Code:
CreateMeshBuilder,
AddVertex,-2.65,2.6,-0.4,
AddVertex,-2.95,2.6,-0.4,
AddVertex,-2.95,2.1,-0.4,
AddVertex,-2.65,2.1,-0.4,
AddFace,3,2,1,0,
SetText,FG2
SetBackgroundColor,0,0,0
SetTextColor,255,255,255
SetTextPadding,0,10
SetFont,Times New Roman
SetTextureCoordinates,0,1,0,
SetTextureCoordinates,1,0,0,
SetTextureCoordinates,2,0,1,
SetTextureCoordinates,3,1,1,

MattD6R

Posts : 243
Join date : 2013-06-16
Location : Brisbane, Australia

Back to top Go down

Re: Feature Request: Font/text object support

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum