Author Topic: Dynamic fonts  (Read 12058 times)

d3x0r

  • Jr. Member
  • **
  • Posts: 75
    • View Profile
Dynamic fonts
« on: November 19, 2015, 06:37:54 am »
I've been tinkering with making a C# port, and was looking for a way to render fonts dynamically instead of having a fixed bitmap font of limited characters.   I stumbled on a C header-only font rendering library https://github.com/nothings/stb/blob/master/stb_truetype.h which is part of  https://github.com/nothings/stb

so I have this class

which uses the c# port of that library and renders characters dynamically into a texture.  (as each character is needed, if it doesn't exist on the bitmap already, render it, copy it to the bitmap, mark the bitmap dirty, then when drawing, if dirty, re-download the image to OpenGL.  Works pretty good...  the GetCharacter routine would have to be changed to support utf-8 decoding instead of utf-16; GetCharacter takes a string and an index and returns  a 32 bit 'rune' named after the character type in Go.

----
Instead of porting squirrel and the assembly language I was planning on using C# scripts.  I have basic functionality to load .cs files, compile them and use them.  I don't have the reactor done.  so for now it's just a static rendering.  I made a GLSL shader that generates output that look like the general texture with lines on edges... can even control the thickness of the lines dynamically and face/edge color.

Implemented a texture atlas for everything else; but had to scale the images down and extract single faces to fit in an atlas correctly; but was planning on using the texture more as a decal image and the face-edge shader as the background.  So then moved the face/edge colors into the description file.

But; I'm working on interfacing with a physics engine... I was going to use Bullet, even spent some time to make a new C# port of that since the other is obsolete by 3-4 years.... but in the process ended up stumbling on BEPUPhysics which is already C# and has 4-5x the speed of bullet and already supports multi-threaded dispatch of work.   

I also played with the game 'fortresscraft' which is also voxel based and has conveyors/smelters/etc.  Their version makes ore types un-minable by the player, and you attach a drill to a block and get unlimited ore generated from the drill on the ore; kind of unrealistic... but then you can spend time on the automation instead of strip-mining the world...

----
For now I do very little checking of the C# scripts; but will eventually limit their functionality to just classes the game engine provides and not all of C# library; would be bad to get a script that reads your file system, opens a network connection and dumps all your stuff :)  Or worse... I do limit them now from using 'System.IO' but will eventually need more checks.  Will be nice once MS has compiler-as-a-service support released; can already do it in Mono.

Enigma

  • Administrator
  • Jr. Member
  • *****
  • Posts: 68
    • View Profile
Re: Dynamic fonts
« Reply #1 on: November 20, 2015, 01:23:02 am »
Hi d3x0r,

That's a great job you are doing here. And we are really proud to see you are using Blackvoxel as a base for your game. :)

Maybe the start of a great adventure for you.

The choice of C# is slightly surprising to me  :o. But why not if you like it... so I'm just curious to know why you choose this language.

Why not a C# robot. I'm not a C# expert at all, but that could be interesting to add one in Blackvoxel. Our long term goal is to add many languages. (The problem will be how to make it in a "clean" way).

I see you have mentionned that your work is derived from blackvoxel, that is right.
I know your code is at a preliminary state, but there is something very important you must add in your code ;). As a derived work of a GNU GPL v3 software, you must mention the GPLv3 licence AND original copyrights, both on a Copyright/License files and in the headers of the source code. (GPL V3 Licence).
That's not only for legal reason about the Blackvoxel license, but also for the guys crawling on your github : Even if your game is only in source form at this time, someone could go into your github and take code or assets without knowing licencing conditions. Imagine someone make proprietary software with it or simply use this code without mentionning copyright, they can and end up with troubles with us (Blackvoxel code was legaly registered in order to protect the licence).
Third party libraries should also be listed with their copyrights, authors and licencing conditions. Cross compatibility legal issues should be avoided.
Above legal reason, that's important for authors and contributors to be listed : that could help some to find a job.
I understand (as I remember that by the past, you said) you are not aware of all theses picky legal stuff . But we have worked a lot (and unfortunately spent a lot of time) about these legal details in order to avoid problems.
But, don't worry, we can help you and explain what must be done and even help you to write some of these "legal stuff" files for you.

That could also be interesting for you to know why we made the choice of free software. And why we choose the particular GPL V3+ licence that is a free licence, but somewhat restrictive in some way compared to MIT or BSD like licences : In few words, a software derived from a GPL v3+ free software must be a GPL v3+ free software without exception. That's a way to protect the work for free software programmers : Everybody can use the code freely and make their stuff with it, but in return, they must do the same. Of course, licencing terms have heavy consequences depending on your goals.

About the font class, that's an interesting developpment. As you know, in Blackvoxel, we made a particular design choice with "8 bit computer style fixed font" kind of text. But as you know the font rendering system is made only for this particular case. The static rendering way of vector font is a good choice. No need for dynamic one that would be... slower.  :)

Even if ores aren't un-minable by hand in Blackvoxel, the required quantities to make an airplane are very important for simple hand mining. But I'm not completely sure that every players understand that. In the future, there will be more in-game tutorial and missions to help player to understand what are the best ways. Blackvoxel is a long term project and there is a lot of things remaining to do.

About physics engines, I can't say what is the best depending on what you want to do. Including vector entities or making multi-grids interactions might mean different approachs. In Blackvoxel, the choice of an unique grid and "pure voxel" interactions is a strong choice. But we understand that someone wanting to make a different game could want some different choices. The two library you mentioned are free and have compatible licence.

The ability to well sandbox code in C# is interesting. C# is a fast and efficient language compared to little scripting ones. Of course, not as fast as C/C++, but C/C++ is unsuitable for doing sandboxed parts(unless wanting to play with heavy hardware processor sandboxing stuff...).

The Blackvoxel Team

d3x0r

  • Jr. Member
  • **
  • Posts: 75
    • View Profile
Re: Dynamic fonts
« Reply #2 on: November 22, 2015, 08:30:14 pm »
Hi d3x0r,

That's a great job you are doing here. And we are really proud to see you are using Blackvoxel as a base for your game. :)

Maybe the start of a great adventure for you.

The choice of C# is slightly surprising to me  :o. But why not if you like it... so I'm just curious to know why you choose this language.

Why not a C# robot. I'm not a C# expert at all, but that could be interesting to add one in Blackvoxel. Our long term goal is to add many languages. (The problem will be how to make it in a "clean" way).
The choice was primarily that C# comes with the compiler itself so it can build itself.  If you install C# you install the compiler.  It's certainly not without penalties though... like without resorting to 'unsafe' code you can't use pointers to walk arrays, and every access to an array is bounds checked against the instanced array boundaries.  In C# 'struct' is actually a different behavior from 'class' in that struct is a value type like int or float, where classes are always reference types.  So primitives like vectors are good as struct types, but you can't keep a reference to a struct; you can pass a reference to a struct to a function, but can't say 'use that struct over there for this'.  *shrug*

Adding an interop module could have been done; but not without huge expense.  It's not so easy for MS C# and would have to be done with Mono, which is quite a download; but seems to work pretty well for Unity.


I see you have mentionned that your work is derived from blackvoxel, that is right.
I know your code is at a preliminary state, but there is something very important you must add in your code ;). As a derived work of a GNU GPL v3 software, you must mention the GPLv3 licence AND original copyrights, both on a Copyright/License files and in the headers of the source code. (GPL V3 Licence).
That's not only for legal reason about the Blackvoxel license, but also for the guys crawling on your github : Even if your game is only in source form at this time, someone could go into your github and take code or assets without knowing licencing conditions. Imagine someone make proprietary software with it or simply use this code without mentionning copyright, they can and end up with troubles with us (Blackvoxel code was legaly registered in order to protect the licence).
Third party libraries should also be listed with their copyrights, authors and licencing conditions. Cross compatibility legal issues should be avoided.
Above legal reason, that's important for authors and contributors to be listed : that could help some to find a job.
I understand (as I remember that by the past, you said) you are not aware of all theses picky legal stuff . But we have worked a lot (and unfortunately spent a lot of time) about these legal details in order to avoid problems.
But, don't worry, we can help you and explain what must be done and even help you to write some of these "legal stuff" files for you.

That could also be interesting for you to know why we made the choice of free software. And why we choose the particular GPL V3+ licence that is a free licence, but somewhat restrictive in some way compared to MIT or BSD like licences : In few words, a software derived from a GPL v3+ free software must be a GPL v3+ free software without exception. That's a way to protect the work for free software programmers : Everybody can use the code freely and make their stuff with it, but in return, they must do the same. Of course, licencing terms have heavy consequences depending on your goals.
I'll spend some time today updating sources; in the process of the porting I created original files and copied header/source file contents as appropriate.  (Actually make that past-tense.)  I have no issue propagating GNU GPLv3 to this :)

About the font class, that's an interesting developpment. As you know, in Blackvoxel, we made a particular design choice with "8 bit computer style fixed font" kind of text. But as you know the font rendering system is made only for this particular case. The static rendering way of vector font is a good choice. No need for dynamic one that would be... slower.  :)
Yes I know all about the 'style choices' :)  I just figured I'd mention it as it was a small source addition (some 3000 lines) and not a lot of work to implement; though does remove stylized look; and ends up making rather fuzzy characters when blown up large.  Looks nice in small cases.... will have to provide a couple different renderings in the future for things like the large text on the main menu.... a slowdown of only a tiny fraction of a percent in the grand scheme; except the one-time hit to render to the texture when a character doesn't exist.  *shrug*  It still fits within the idle time of a frame at 60fps... 

Even if ores aren't un-minable by hand in Blackvoxel, the required quantities to make an airplane are very important for simple hand mining. But I'm not completely sure that every players understand that. In the future, there will be more in-game tutorial and missions to help player to understand what are the best ways. Blackvoxel is a long term project and there is a lot of things remaining to do.
Actually; ores don't last 'forever' but instead are consumed over time, apparently removing the furthest block of ore attached to a seam until it's all gone.  I hadn't played long enough to exhaust an ore until yesterday... then I had to move my coal and tin drills to another vein.

Yea; I didn't actually make it to genuinely making a plane, and instead ended up enabling creative mode and just created one :)

About physics engines, I can't say what is the best depending on what you want to do. Including vector entities or making multi-grids interactions might mean different approachs. In Blackvoxel, the choice of an unique grid and "pure voxel" interactions is a strong choice. But we understand that someone wanting to make a different game could want some different choices. The two library you mentioned are free and have compatible licence.

The ability to well sandbox code in C# is interesting. C# is a fast and efficient language compared to little scripting ones. Of course, not as fast as C/C++, but C/C++ is unsuitable for doing sandboxed parts(unless wanting to play with heavy hardware processor sandboxing stuff...).

The Blackvoxel Team
Actually javascript is all the craze now; the Chome V8 javascript engine actually emits native instructions and is very fast; amazingly so given the generic-ness of javascript.

Medieval/Space Engineers is C# entirely; they use Havok as a physics engine.  https://github.com/KeenSoftwareHouse/SpaceEngineers

I've seen quite a few C# games coming out so I guess it is a viable platform for rather large spaces.  I'm still iffy on this whole garbage collection thing and would much rather release/delete things in a controlled manner.
I'm using OpenTK as the graphics interface layer (which provides OpenGL and sound in theory)  But I have yet to have any sounds ported.

BEPU has a voxel physics demo - it is the engine for Lemma http://lemmagame.com/ https://github.com/etodd/Lemma  which is another voxel based game.  The demo source includes creating a custom voxel collision shape handler; basically it's a large array of bools instead of building actual box shapes and stuffing them into a compound object.  Will be interesting :) 

Enigma

  • Administrator
  • Jr. Member
  • *****
  • Posts: 68
    • View Profile
Re: Dynamic fonts
« Reply #3 on: November 29, 2015, 08:18:04 am »
Hi, d3x0r,

Sorry for my late response...

Unfortunately, I was verry busy this week.

The choice was primarily that C# comes with the compiler itself so it can build itself.  If you install C# you install the compiler.  It's certainly not without penalties though... like without resorting to 'unsafe' code you can't use pointers to walk arrays, and every access to an array is bounds checked against the instanced array boundaries.  In C# 'struct' is actually a different behavior from 'class' in that struct is a value type like int or float, where classes are always reference types.  So primitives like vectors are good as struct types, but you can't keep a reference to a struct; you can pass a reference to a struct to a function, but can't say 'use that struct over there for this'.  *shrug*

As you seem to know well the pro and cons of this choice and you feel that's the way you want to follow, that's good.

About the problem of installing some language runtime along with a program, in Linux, that's really simple to solve : package managers provide dependency management.

But with Windows, that's a true problem.

Quote
Adding an interop module could have been done; but not without huge expense.  It's not so easy for MS C# and would have to be done with Mono, which is quite a download; but seems to work pretty well for Unity.

We are thinking about this kind of module for Blackvoxel since some time because a lot of people told us "I want to use Blackvoxel with my favorite language".
This include some functionnal languages like Scheme...
But the idea isn't yet mature as there is a lot of considerations and maybe different ways to do depending on the languages.
Some languages could be embedded while others would be better added through some kind of communication.

Quote
I'll spend some time today updating sources; in the process of the porting I created original files and copied header/source file contents as appropriate.  (Actually make that past-tense.)  I have no issue propagating GNU GPLv3 to this :)

Ok, I saw you put the headers, copyright mentions an global licence files with GPL V3.

We'll look on that when we'll have time and eventually make some remarks if needed.

Dont forget to put some header licence on all your own new files (You forgot on some).

Quote
Yes I know all about the 'style choices' :)  I just figured I'd mention it as it was a small source addition (some 3000 lines) and not a lot of work to implement; though does remove stylized look; and ends up making rather fuzzy characters when blown up large.  Looks nice in small cases.... will have to provide a couple different renderings in the future for things like the large text on the main menu.... a slowdown of only a tiny fraction of a percent in the grand scheme; except the one-time hit to render to the texture when a character doesn't exist.  *shrug*  It still fits within the idle time of a frame at 60fps... 

Yes, vector font are nice but the counterpart is the needs to manage the different size.
There are different approach for this problem.
Some are converting vector fonts to polygons. Some other are caching different sizes on different textures.
As I understand, you want to make rendering character textures on an "as needed" basis.
As a comparison to fully prerendering all size and fonts at startup, I guess you expect some gain (memory ?) as a counterpart ?

Quote
Actually; ores don't last 'forever' but instead are consumed over time, apparently removing the furthest block of ore attached to a seam until it's all gone.  I hadn't played long enough to exhaust an ore until yesterday... then I had to move my coal and tin drills to another vein.

Yea; I didn't actually make it to genuinely making a plane, and instead ended up enabling creative mode and just created one :)

It seems some players prefer playing with the game than playing in the game ;)

But... why not.

Quote
Actually javascript is all the craze now; the Chome V8 javascript engine actually emits native instructions and is very fast; amazingly so given the generic-ness of javascript.

Yes, there are some guys that just want to put some javascript everywhere... even in micro-controllers  ::).
No need to say I'm not convinced with some of these "uses" nor by the Javascript language itself.
That said, a Javascript Robot could be added because it is an "everyday use" popular language.
As you said, some Javascript runtimes are really efficient.

Quote
Medieval/Space Engineers is C# entirely; they use Havok as a physics engine.  https://github.com/KeenSoftwareHouse/SpaceEngineers
I've seen quite a few C# games coming out so I guess it is a viable platform for rather large spaces.  I'm still iffy on this whole garbage collection thing and would much rather release/delete things in a controlled manner.

Maybe good programmers can make good games whatever language they use.

But "large space" can mean different technical considerations depending on the game.

I don't know what Space Engineers does as I'm avoiding looking their game code : I believe that doing so would break my creativity.

C/C++ is faster in performance and provide more fine control. But the managed languages like C# or Java can help to develop faster and avoid some kinds of weird bugs caused by "crazy pointers".

Anyway, it's difficult to compare different games and approaches. And no one can say what Minecraft or Space Engineers would have been if made in C/C++.

Quote
I'm using OpenTK as the graphics interface layer (which provides OpenGL and sound in theory)  But I have yet to have any sounds ported.

As I understand it's something equivalent to SDL. But I can't give any though on that.

Quote
BEPU has a voxel physics demo - it is the engine for Lemma http://lemmagame.com/ https://github.com/etodd/Lemma  which is another voxel based game.  The demo source includes creating a custom voxel collision shape handler; basically it's a large array of bools instead of building actual box shapes and stuffing them into a compound object.  Will be interesting :)

That's an interesting approach. It's mean you have to update your array from the grid... which takes some overhead. But this doesn't mean it's bad : physics engine could maybe take advantage of data on a particular format and maybe could have lost more time in accessing directly the grid. Too difficult to say without a deep analysis.

Anyway, the use if an existing physics engine is a significant time saving.

The Blackvoxel Team

d3x0r

  • Jr. Member
  • **
  • Posts: 75
    • View Profile
Re: Dynamic fonts
« Reply #4 on: December 16, 2015, 02:35:12 am »
Dynamic fonts....
   well only a certain subset of characters is required for most games; if a translation to something like russian or an asian language happens, then none of the latin characters are required... and rather than saying 'for every possible character' it's not that much more 'work' to 'for each character Ii'm outputting, get the character information; and create if it doesn't exist'  You already have to do a 'for each character' loop to ooutput the texture uv's/coords of each character cell... so rather than a computation c%16, c / 16 + character sizes... I get back a struct that has the UV array already created for that source texture... (current character map is only like 23 characters... lots don't get rendered like 'q' 'Q' 'z' 'Z' ... but like 'O' and 'o' exist in 'Options' )

Physics...
  Basically the update to the physics info happens during culling (if some face is drawn, needs a physical representation).   decided for now to not update transparent voxels (water) to physics... though maybe someday; would almost like to do a displacement model (if thing is in water, shove water out of the way) which depending on distances required to cause a 'shove' would provide a bouyancy... but I think that will have to be a wish... I'm only at 500k water voxels update in twice the time I had 2 million updates in blackvoxel engine itself.  (C# sucks :) the always-check-array-bounds is the overhead )

After a few fixes to sector recycling code I had ended up bypassing, did get it to run on my Android tablet :)

stepped away a bit to implement networking... but I need to implement a listbox control...

But it's progressing slowly.  Still basically non-functional though; Inventory doesn't display - complicated that by using a procedural shader for first 10 block types; was looking to making more procedural texture shaders for like metals (ingots) etc; but I don't see how they are done... Implemented a BitStream class to compress sectors (basically RLE; but also scan the sector for all voxel types used, and build a dictionary, then use that count to get the number of bits required; and store counts/voxel types with that number of bits... (like most sectors by default use 8 or fewer block types... even at 16 types the voxel storage is then 1/4 the default type)

Still missing sound support... list goes oh :)