SUBSIM Radio Room Forums



SUBSIM: The Web's #1 resource for all submarine & naval simulations since 1997

Go Back   SUBSIM Radio Room Forums > Silent Hunter 3 - 4 - 5 > SH4 Mods Workshop
Forget password? Reset here

Reply
 
Thread Tools Display Modes
Old 09-29-08, 02:13 PM   #1
skwasjer
The Old Man
 
Join Date: Apr 2007
Location: Netherlands
Posts: 1,547
Downloads: 26
Uploads: 3
Default [TEC] How to create new game fonts (bitmap/OFF)

I don't think this has been modded alot, either for the lack of interest or for the lack of knowledge. The latter I can help with, with this tutorial.

I think some of the ingame fonts can use an overhaul, and perhaps this triggers some modders to take a look at the current game fonts.

DOWNLOAD - Mini mod I created with this tutorial. It also contains a PSD-template in the Support-folder.


How to create new game fonts (aka. bitmap fonts, aka. OFF-definition fonts) - PART 1

Most 3D games use so-called 'bitmap fonts'. Bitmap fonts are fonts based on bitmaps instead of vectors, like most fonts you use in every day life (like TTF, OTF, or PS-fonts, etc). The reasons are that it doesn't require installation of such fonts, allows for faster rendering as the system it's core font pipeline can be bypassed, no real math is involved as bitmaps can simply be pushed to screen without any processing required and generally a custom bitmap font implementation is platform-indepedent.

Silent Hunter uses a combination of a bitmap, containing the font-art, and a definition file (OFF-extension) that contains the coordinates where each character is located in the bitmap. The combination of these 2 files is used by the game to render each character seperately:
  1. Find the character definition in the OFF-file
  2. Get the coordinates for the character
  3. Lookup the bitmap-character in the bitmap
  4. Render it
  5. Repeat for next character
This tutorial shows you how to create a font from scratch.

Requirements
  • Photoshop or similar
  • Photoshop DDS-plugin (or a converter or similar functionality in other software)
  • S3D v0.9
  • SH4
Creating the bitmap

1. Creating a new bitmap
In this tutorial, I am going to create a new game font based on 'Courier New' (for sake of this tutorial, you can use any font you like)



- You can pick any size you need (with small fonts, you can use a smaller canvas size)
- Resolution: 72 dpi
- Color mode: RGB8
- Make sure the background is white


2. Add an alpha channel



3. Select the RGB channels again, and deselect the Alpha channel



4. Add a text object, and specify all the characters you want your font to support.

I used this, but you do not have to use all of them (if the purpose of the font is limited). You can also add others, as long as they are defined in Windows 1252 codepage (unverified!!!).

ABCDEFGHIJKLMNOPQRSTU
VWXYZabcdefghijklmnop
qrstuvwxyz1234567890&
-+=_().,;:’”?!/%°®™
ÄÖÜÁÀÂÉÈÊËÇ€ÎÏÔŒÙÛß«»
äöüáàâéèêëç¢îïôœùû



Make sure to set the character and line spacing such, that no character touches or extends into the bounds of another character.

Note: Monospace fonts are the easiest, as each character has the same size.

In this example, I used font-size 34, with a custom linespacing of 37 and character spacing of 107%


5. Done adding the characters, this is what we have now



6. Now, hide the text layer



7. Select Layer Transparency

Right-click on the small window in the layer (with the 'T' of our text object), and select 'Select Layer Transparency'.

All our characters are now added to the selection.




8. Choose to save the selection



9. Save the selection to our alpha channel

Note: make sure to 'replace' the channel if you repeat the process more than once.




10. This is the end result, we now have a bitmap based on our new font.



11. Save the bitmap as a DDS-file to your mod directory.

- Use DXT5, ARGB8 mode
- Don't save any mipmaps. We don't need them in 2D screen space.
- Save the file under your mod directory: <mod>\Data\Menu\Fonts using a name of your choice (no spaces).

I saved the file to Courier34.dds.



Now, we are done with Photoshop. Make sure to save a PSD of this file as well. If at any one point you wish to update or change your font, just unhide the text-layer, and repeat the process from step 4 down.

Next, we need to make the OFF-file, and set up the menu_xxx.ini file to use the font ingame. Please wait for the next post (in an hour or so) which will describe this process.

Last edited by skwasjer; 09-29-08 at 03:53 PM.
skwasjer is offline   Reply With Quote
Old 09-29-08, 02:14 PM   #2
skwasjer
The Old Man
 
Join Date: Apr 2007
Location: Netherlands
Posts: 1,547
Downloads: 26
Uploads: 3
Default

How to create new game fonts (aka. bitmap fonts, aka. OFF-definition fonts) - PART 2


Creating the font definition file (OFF)

There's 2 methods to creating an OFF-file. One is creating it from scratch, and another is reusing an existing one (and modifying it). Whichever suits you best, allthough I have to admit right from the start S3D v0.9 contains 2 bugs making it nearly impossible to create an OFF-file from scratch. I only ran into these bugs while making the tutorial, so But consider this fixed in v0.9.1.

In the mean time, the screenshots will discuss creating a new file from scratch, but the process is similar when reusing an existing file.

Fire up S3D v0.9 or higher now.

1. Create new OFF-file

- Choose File > New and from the dialog that pops up, choose Font-character file (OFF).




2. A new empty file is created in memory.

- Notice how the Viewer panel indicates no texture was found and loaded.
- After the new file is opened, save it immediately to our mod folder under:

<mod>\Data\Menu\Fonts

IMPORTANT: use the exact same name as the DDS-file saved earlier, only the extension must be different now.

I used Courier34.off as I saved the bitmap earlier to Courier34.dds.





3. DDS file is loaded

After saving, notice how the DDS-file is now loaded into the viewer. S3D recognizes the alpha channel in the same way the game does, but inverts the mask for clarity in the S3D-viewer.

Note: In game, the actual white background is masked out, leaving white characters with a transparent background. The white color is then used to blend with colors specified in Menu_xxx.ini.




4. Start adding each character

Next up, the tedious process begins of defining 'rectangles' (if you reused an OFF-file this is somewhat faster!). These are the coordinates at which each seperate character can be found.

First, click the button in the toolbar to add a new character definition.




5. Specify the character details

Type the character, and specify the box coordinates. The viewer will show a blue rectangle based on the values you specify.

Important:
- Use the same height for each character. This way all characters have the same baseline.
- Make sure to use the height of the tallest character.

Here's two examples for A and B.




6. All characters defined

Once we are done adding/changing all characters, we have a long list of definitions.

- We can optionally change global character spacing. I used -4 to move the characters a bit closer together.

Save the file once more. Now we can use the font in the game.




7. Change menu_1024_768.ini file

- Copy the menu_1024_768.ini to your mod folder: <mod>\Data\Menu
- Open the file with notepad
- Scroll to the [Fonts] section.

I will be adding a new font to the bottom of the font-list. For this to work, we must also increment the font-count. Notice how the number of fonts in the list is always one more than the last font-identifier. This is a so-called 0-based array (starts counting at 0). Our new font has an index of 24.

[Fonts]
Fonts=25
Font0=DATA/Menu/Fonts/FPHunt26.tga
.
.
.
.
Font24=DATA/Menu/Fonts/Courier34.dds


8. Use your font throughout the menu_1024_768.ini file

Now we have to decide which text in the game uses our new font. For the sake of this example, I chose the bottom 3 items from the main menu.

[G63 I6]
Name=Exit
Type=1032;Button
.
.
Font=24; Changed from 22.

[G63 I7]
Name=Credits
Type=1032;Button
.
.
Font=24; Changed from 22.

[G63 I8]
Name=Options
Type=1032;Button
.
.
Font=24; Changed from 22.


9. Save the file, enable the mod and test in game.

And here's the result:


Last edited by skwasjer; 10-01-08 at 02:00 PM.
skwasjer is offline   Reply With Quote
Old 09-29-08, 02:41 PM   #3
Hitman
Pacific Aces Dev Team
 
Hitman's Avatar
 
Join Date: Sep 2002
Location: Spain
Posts: 6,099
Downloads: 109
Uploads: 2


Default

Wow fantastic

I would have changed the fonts in SH3 long ago if I had known how, now I can Many thanks!!!
__________________
One day I will return to sea ...
Hitman is offline   Reply With Quote
Old 09-30-08, 03:56 PM   #4
Hitman
Pacific Aces Dev Team
 
Hitman's Avatar
 
Join Date: Sep 2002
Location: Spain
Posts: 6,099
Downloads: 109
Uploads: 2


Default

A question -though I suppose the answer is positive-: If I keep the same size for the letters and symbols as the original font, then I wouldn't need to do the step 4, right? :hmm: It would just be a swap file and I would get the new fonts?
__________________
One day I will return to sea ...
Hitman is offline   Reply With Quote
Old 10-01-08, 01:48 PM   #5
skwasjer
The Old Man
 
Join Date: Apr 2007
Location: Netherlands
Posts: 1,547
Downloads: 26
Uploads: 3
Default

Quote:
Originally Posted by Hitman
A question -though I suppose the answer is positive-: If I keep the same size for the letters and symbols as the original font, then I wouldn't need to do the step 4, right? :hmm: It would just be a swap file and I would get the new fonts?
Correct. You can copy an existing OFF for that and tweak where neccesary (or not at all). You could also skip the entire menu.ini part if you simply replace an existing OFF+DDS/TGA.

A word of caution is that one or two stock OFF files have a couple of incorrect rectangles for certain characters but that's easily checked with S3D.

PS: for SH3, make a TGA 32-bit. For SH4, a DDS.
PS2: check out my first post at the top. I included the test-mod of the tutorial including a template.psd.

Last edited by skwasjer; 10-01-08 at 02:06 PM.
skwasjer is offline   Reply With Quote
Old 10-01-08, 12:27 PM   #6
Webster
Stowaway
 
Posts: n/a
Downloads:
Uploads:
Default

i have long been interested in changing the font color and size for the orders bar.

can you clue me in on how to do that? :hmm:
  Reply With Quote
Old 10-01-08, 01:51 PM   #7
skwasjer
The Old Man
 
Join Date: Apr 2007
Location: Netherlands
Posts: 1,547
Downloads: 26
Uploads: 3
Default

Quote:
Originally Posted by WEBSTER
i have long been interested in changing the font color and size for the orders bar.

can you clue me in on how to do that? :hmm:
I'm not sure which menu-entries exactly are related to the orders bar, but the process is the same. Create a new font (or use a smaller/bigger existing one) and find the entries in menu.ini file that control the appearance of the orders bar.
skwasjer is offline   Reply With Quote
Old 10-01-08, 02:34 PM   #8
Hitman
Pacific Aces Dev Team
 
Hitman's Avatar
 
Join Date: Sep 2002
Location: Spain
Posts: 6,099
Downloads: 109
Uploads: 2


Default

Quote:
Correct. You can copy an existing OFF for that and tweak where neccesary (or not at all). You could also skip the entire menu.ini part if you simply replace an existing OFF+DDS/TGA.

A word of caution is that one or two stock OFF files have a couple of incorrect rectangles for certain characters but that's easily checked with S3D.

PS: for SH3, make a TGA 32-bit. For SH4, a DDS.
PS2: check out my first post at the top. I included the test-mod of the tutorial including a template.psd.
Cheers
__________________
One day I will return to sea ...
Hitman is offline   Reply With Quote
Old 04-22-10, 12:33 AM   #9
marrydavidson101
Stowaway
 
Posts: n/a
Downloads:
Uploads:
Default

thanks for sharing this
  Reply With Quote
Old 07-04-12, 05:24 PM   #10
stanger
Engineer
 
Join Date: Apr 2012
Location: Poland
Posts: 200
Downloads: 84
Uploads: 0
Default

I can't see the font texture in 'viewer' window in s3d, its just black. Happens with default game .off files and new ones. What can be wrong? (im using s3d 0.9.9, tried it on win7 and win8).
stanger is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 11:27 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright © 1995- 2024 Subsim®
"Subsim" is a registered trademark, all rights reserved.