Tutorial; DisplayIconsInGame - HWRM/KarosGraveyard GitHub Wiki

How To Display Custom Icons In Game (using Relic's method)

1. Background Info About Icon Files:

Ship and subsystem icons are located in the data/ship/icons/ directory. They are managed by a file: shipicons.lua. That file, for each ship model, points to the picture file and its UV map.

The picture file can be either a plain Targa file or a DDS. It can be included in a ROT file, but this is not necessary. Targa files are rather heavy. DDS files are lighter; they should be coded as DXT5 rather than DXT3. Mipmap is not necessary. You can use Spooky's ROT Tool to create a ROT file from a tga or dds. However, be warned that this conversion can create bugs when the picture is displayed in game. Whether Targa or DDS, the picture must have an alpha channel for the icon masks. Note: it seems that players and modders have encountered different bugs with the same icon files, so it is possible that graphic cards and HW2 version (mac/PC) play a role; however, as far as I know, tga files sized as specified in this tutorial never create bugs.

In the stock HW2, distinct icon picture files are made for each of the following four screen width resolutions: 800x, 1024x, 1280x and 1600x.

2. Scale of Icon Pictures:

2.1 Single Icon Picture

Let's assume you have a nice icon picture for your custom ship. Resize it to 128 pixel height (with proportional reduction of width). For very long ships, whose length exceeds 3 times the height, you must not resize according to height, but to 384 wide. Select the whole resized image and copy.

Create a new image of 384x128; that is the sized used by Relic for 1600 screen resolutions. Paste your icon image. Adjust the pasted image to the left if necessary. You've got the icon in final format. Save in TGA or DXT format.

2.2 Multiple Icons File

If you are making several icons, you might want to put them all in a single file. Then make sure to carefully align the small icons on a grid with 384x128 pixel cells. It will make your life a lot easier when UV mapping. The picture containing all icons should be of dimensions in powers of 2 (like 2048x2048 or 1024x1024 or 1024x512 etc).

2.3 Rescale in Different Resolutions

To rescale the icon file in different resolutions, you just need to resize the image to 102 pixel height (res 1280), 82 pixel height (res 1024) and 64 pixel height (res 800). If you created a picture with several icons, the best way is to first rescale the image to the proper size (ie 1280/1600, 1024/1600, 800/1600 ratios) and then resize the image zone to 1024x1024 or 2048x2048, keeping the initial image in the top left corner.

3. Resolution Recognition

HW2 knows which file to use depending on the resolution thanks to .mres files. Those files contains small scripts that match width resolutions and files.

This is an example of what you want to put in your .mres file when you have scaled your icon pictures into four resolutions:

baseRes = 800
res800 = "DATA:/Ship/Icons/PDS_Icons_800_New.dds"
res1024 = "DATA:/Ship/Icons/PDS_Icons_1024_New.dds"
res1280 = "DATA:/Ship/Icons/PDS_Icons_1280_New.dds"
res1600 = "DATA:/Ship/Icons/PDS_Icons_1600_New.dds"

4. UV map for the icons

In the shipicons.lua file, add an entry for the ship, pointing to the picture file. Example (icon in the first column form left, third row from top):

Vgr_Heavyinterceptor =
{ 
    LargeIcon = 
    { 
        texture = "DATA:\Ship\Icons\icon_ships_pds.mres", 
        textureUV_TL = { 0, 128, }, 
        textureUV_WH = { 192, 64, }, 
        stretchOnDraw = 1, 
    }, 
}

The texture refers to the mres file that was created at step 3.

textureUV_TL indicates the top left coordinates of the box where the icon picture will be copied. textureUV_WH determines the size of the box. The mapping is normalised in the 800x resolution. That way, mapping is done once and for all for every resolutions.

SunTzu
9 June 2006

Comments

Page Status

Updated Formatting? Initial
Updated for HWRM? Initial