Loading Icons: Difference between revisions
Jump to navigation
Jump to search
[unchecked revision] | [unchecked revision] |
Content deleted Content added
Don't link to ancient version of stb_image that doesn't even have the functions this references. |
m Bot: Replace deprecated source tag with syntaxhighlight |
||
Line 14: | Line 14: | ||
===Targa=== |
===Targa=== |
||
A much better choice would be Targa format (.tga). It is a very very simple format, used by many game engines (like Quake) too. Essentially you can save uncompressed bitmap images with a 18 bytes header: |
A much better choice would be Targa format (.tga). It is a very very simple format, used by many game engines (like Quake) too. Essentially you can save uncompressed bitmap images with a 18 bytes header: |
||
< |
<syntaxhighlight lang="c"> |
||
typedef struct { |
typedef struct { |
||
unsigned char magic1; // must be zero |
unsigned char magic1; // must be zero |
||
Line 28: | Line 28: | ||
unsigned char pixeltype; // must be 40 |
unsigned char pixeltype; // must be 40 |
||
} __attribute__((packed)) tga_header_t; |
} __attribute__((packed)) tga_header_t; |
||
</ |
</syntaxhighlight>This is followed by the data, each pixel on 4 bytes: blue, green, red, alpha channels in order. This simple. Many image editors support this format (like The GIMP), or you can use [https://imagemagick.org/index.php ImageMagick] CLI tool to convert any image format into .tga with a simple command (available in all Linux distributions). |
||
< |
<syntaxhighlight lang="bash"> |
||
$ convert image.png image.tga |
$ convert image.png image.tga |
||
</ |
</syntaxhighlight>When saving with The GIMP, first convert the image to RGB (Image / Mode / RGB). Then add Alpha channel (Layer / Transparency / Add Alpha Channel). If these options are inactive, that means your image is already RGB or has alpha. Finally choose Export As... and enter a filename ending with ".tga". In the popup, uncheck "RLE compression" and select origin "Top". |
||
If you want to support all TGA options, including palette images and RLE compression, then that's still pretty simple. Just use the following code snippet: |
If you want to support all TGA options, including palette images and RLE compression, then that's still pretty simple. Just use the following code snippet: |