76
Programming / Re: emulating a terminal, and how to create a custom font?
« on: February 25, 2013, 09:41:32 PM »
In my implementation, everything was represented as characters... this is how you would be able to use the bitmaps like what dwarf fortress uses.
All languages I have heard of have the ability to cast a character as an int or byte... or what have you. This is because they all use (or used) the standard ascii format. e.g. an 'A' can be cast to a byte which would then be 65... 'B' casts to 66... etc.
That looks something like this in C#:
byte val = (byte)'A'; //val is now set to 65 (the parenthesis are doing the casting)
byte val2 = (byte)'B'; //val2 is now set to 66
utilizing this, you could create an array of points that represent the top left corner of each character. if your characters were 16 x 24 pixels then you could then just create the array based off of the bitmap character size.
(0,0), (16,0), (32,0)... etc.
it is easy to create a forloop that will generate all these for you with good use of modulus.
Then because the point for 'A' is at index 65 in the array just draw out the image that has a top left coordinate of the element at index 65.
Then because you are storing the characters instead of the bytes, it is a lot easier to adapt this to other strings being displayed... you would just need a function that can either convert a string of characters into an array of bytes (using casting) and store it, or one that does it every frame(although the latter is a much less efficient use of processing power)
All languages I have heard of have the ability to cast a character as an int or byte... or what have you. This is because they all use (or used) the standard ascii format. e.g. an 'A' can be cast to a byte which would then be 65... 'B' casts to 66... etc.
That looks something like this in C#:
byte val = (byte)'A'; //val is now set to 65 (the parenthesis are doing the casting)
byte val2 = (byte)'B'; //val2 is now set to 66
utilizing this, you could create an array of points that represent the top left corner of each character. if your characters were 16 x 24 pixels then you could then just create the array based off of the bitmap character size.
(0,0), (16,0), (32,0)... etc.
it is easy to create a forloop that will generate all these for you with good use of modulus.
Then because the point for 'A' is at index 65 in the array just draw out the image that has a top left coordinate of the element at index 65.
Then because you are storing the characters instead of the bytes, it is a lot easier to adapt this to other strings being displayed... you would just need a function that can either convert a string of characters into an array of bytes (using casting) and store it, or one that does it every frame(although the latter is a much less efficient use of processing power)