TICT TUTORIAL SERIES 1 - Part IV | (c) TI-Chess Team 2000 |
Generating Sprites for C-Projects v 1.01 |
This tutorial will show how to make sprites which can be used in C projects.
The TICT Tutorial S1P1 (Handling Uncompressed Images in C-Projects) already shows how images can be handled in C-Projects. But generating sprites this way is a little bit cumbersome, because you have to edit the complete image data by hand.
To overcome this restriction I have implemented a tiny tool (TTTiler) which may be used to split up an image into single rectangle pieces and generate C source code for them. TTiler will be part of the next version of the TIGCC Tools Suite, but for now you have to download it separately.
TIGCC Development Environment for Windows9x/NT - Version 0.8
http://www.ticalc.org/pub/win/asm/tigcc.zipImageStudio 1.1 from Matthew Johnson
http://www.acz.org/programs/istudio.zip
http://www.ticalc.org/pub/win/graphics/istudio.zipTTTiler v1.04
http://www.ticalc.org/pub/win/asm/tttiler.zip
Suppose we have an image (BMP) which holds our sprites (tiles) like this one:
This image holds 12 grayscale sprites (tiles) each of size 16x16 pixels. The complete image is 64x48 pixels large.
If you start TTTiler without any argument the following usage page will be printed:
As first step to generate C source code for the single sprites we have to convert the image itself into a binary format which can be handled by TTTiler. To perform this step we start ImageStudio and load the image into it. By using the menu entry Image->Image Mode we configurate the wanted output type to Monochrome or Standard Grayscales (Enhanced Grayscales are not possible within C-Projects). Now use the sliders to adjust the output until you are pleased with it. To generate the Binary file enter menu entry File->Export and select Binary File to save it (make sure that checkbox RLE compressed is NOT checked).Usage: tttiler [-h|-v|-ht|-vt] <infile> <width> <height> <t_width> <t_height> <entries> <outfile> -h ... tile from left to right and up to down -v ... tile from up to down and left to right -ht ... like -h, but generates complete test program -vt ... like -v, but generates complete test program infile ... binary image file generated with ImageStudio width ... width of infile in pixel height ... height of infile in pixel t_width ... width of one tile in pixel (<=32) t_height ... height of one tile in pixel entries ... number of data fields per line (0<entries<=20) outfile ... output filename splits binary image file generated with ImageStudio in single sprites (tiles) and generates C source code for them. NOTE: only 8, 16 and 32 pixel wide tiles are generated. If the tilewidth is not exactly one of these widths, the sprites are filled up to the right with empty pixels NOTE2: the width of the input file have to be a multiple of 8 otherwise ImageStudio and tttiler will not treat it correctlySuppose we have generated a grayscale binary image file called tiles.bin.
To split up tiles.bin into single tiles so that the sprites are ordered related to their numbers we execute:
tttiler -h tiles.bin 64 48 16 16 10 tiles.c
The output of TTTiler is written to file tiles.c and looks like this:
unsigned int tiles[2][192] = {{ // tile 0 0x0000,0x0000,0x4000,0x4040,0x40c0,0x4140,0x4040,0x4040, 0x4040,0x4040,0x4040,0x4000,0x4000,0x4000,0x3ffc,0x0000, // tile 1 0x0000,0x0000,0x4000,0x41c0,0x4220,0x4020,0x4020,0x4040, 0x4080,0x4100,0x43e0,0x4000,0x4000,0x4000,0x3ffc,0x0000, // tile 2 0x0000,0x0000,0x4000,0x40e0,0x4110,0x4010,0x4060,0x4010, 0x4010,0x4110,0x40e0,0x4000,0x4000,0x4000,0x3ffc,0x0000, // tile 3 0x0000,0x0000,0x4000,0x4020,0x4060,0x40a0,0x40a0,0x4120, 0x41f0,0x4020,0x4020,0x4000,0x4000,0x4000,0x3ffc,0x0000, // tile 3 0x0000,0x0000,0x4000,0x41e0,0x4100,0x4200,0x43c0,0x4020, 0x4020,0x4220,0x41c0,0x4000,0x4000,0x4000,0x3ffc,0x0000, // tile 4 0x0000,0x0000,0x4000,0x40e0,0x4110,0x4100,0x41e0,0x4110, 0x4110,0x4110,0x40e0,0x4000,0x4000,0x4000,0x3ffc,0x0000, // tile 5 0x0000,0x0000,0x4000,0x41f0,0x4020,0x4020,0x4040,0x4040, 0x4080,0x4080,0x4080,0x4000,0x4000,0x4000,0x3ffc,0x0000, // tile 6 0x0000,0x0000,0x4000,0x40e0,0x4110,0x4110,0x40e0,0x4110, 0x4110,0x4110,0x40e0,0x4000,0x4000,0x4000,0x3ffc,0x0000, // tile 6 0x0000,0x0000,0x4000,0x41c0,0x4220,0x4220,0x4220,0x41e0, 0x4020,0x4220,0x41c0,0x4000,0x4000,0x4000,0x3ffc,0x0000, // tile 7 0x0000,0x0000,0x4000,0x4238,0x4644,0x4a44,0x4244,0x4244, 0x4244,0x4244,0x4238,0x4000,0x4000,0x4000,0x3ffc,0x0000, // tile 8 0x0000,0x0000,0x4000,0x4208,0x4618,0x4a28,0x4208,0x4208, 0x4208,0x4208,0x4208,0x4000,0x4000,0x4000,0x3ffc,0x0000, // tile 9 0x0000,0x0000,0x4000,0x4238,0x4644,0x4a04,0x4204,0x4208, 0x4210,0x4220,0x427c,0x4000,0x4000,0x4000,0x3ffc,0x0000, }, // ---- plane 2 ---- { // tile 0 0x3fff,0x6001,0xe001,0xe041,0xe0c1,0xe141,0xe041,0xe041, 0xe041,0xe041,0xe041,0xe001,0xe001,0xffff,0xc002,0xfffc, // tile 1 0x3fff,0x6001,0xe001,0xe1c1,0xe221,0xe021,0xe021,0xe041, 0xe081,0xe101,0xe3e1,0xe001,0xe001,0xffff,0xc002,0xfffc, // tile 2 0x3fff,0x6001,0xe001,0xe0e1,0xe111,0xe011,0xe061,0xe011, 0xe011,0xe111,0xe0e1,0xe001,0xe001,0xffff,0xc002,0xfffc, // tile 3 0x3fff,0x6001,0xe001,0xe021,0xe061,0xe0a1,0xe0a1,0xe121, 0xe1f1,0xe021,0xe021,0xe001,0xe001,0xffff,0xc002,0xfffc, // tile 3 0x3fff,0x6001,0xe001,0xe1e1,0xe101,0xe201,0xe3c1,0xe021, 0xe021,0xe221,0xe1c1,0xe001,0xe001,0xffff,0xc002,0xfffc, // tile 4 0x3fff,0x6001,0xe001,0xe0e1,0xe111,0xe101,0xe1e1,0xe111, 0xe111,0xe111,0xe0e1,0xe001,0xe001,0xffff,0xc002,0xfffc, // tile 5 0x3fff,0x6001,0xe001,0xe1f1,0xe021,0xe021,0xe041,0xe041, 0xe081,0xe081,0xe081,0xe001,0xe001,0xffff,0xc002,0xfffc, // tile 6 0x3fff,0x6001,0xe001,0xe0e1,0xe111,0xe111,0xe0e1,0xe111, 0xe111,0xe111,0xe0e1,0xe001,0xe001,0xffff,0xc002,0xfffc, // tile 6 0x3fff,0x6001,0xe001,0xe1c1,0xe221,0xe221,0xe221,0xe1e1, 0xe021,0xe221,0xe1c1,0xe001,0xe001,0xffff,0xc002,0xfffc, // tile 7 0x3fff,0x6001,0xe001,0xe239,0xe645,0xea45,0xe245,0xe245, 0xe245,0xe245,0xe239,0xe001,0xe001,0xffff,0xc002,0xfffc, // tile 8 0x3fff,0x6001,0xe001,0xe209,0xe619,0xea29,0xe209,0xe209, 0xe209,0xe209,0xe209,0xe001,0xe001,0xffff,0xc002,0xfffc, // tile 9 0x3fff,0x6001,0xe001,0xe239,0xe645,0xea05,0xe205,0xe209, 0xe211,0xe221,0xe27d,0xe001,0xe001,0xffff,0xc002,0xfffc, }};
If you want to see how that sprites can be used, just use flag -vt or -ht instead of -v which adds a tiny test program to the output. This test program just displays the original picture on the calc by composing it again from the single sprites.
Due to the restriction of ImageStudio the maximum width of the original image is limited to 240 pixels and the maximum height is limited to 128 pixels.
Additionally the width of the original image have to be an multiple of 8.
The TIGCC Tools supports functions to draw 8 pixels-wide sprites, 16 pixel-wide sprites and 32 pixel-wide sprites. Therefore TTTiler will generate ONLY sprites of these sizes. If you specify a tile width which is not exactly one of these, TTTiler will add automatically empty pixels to the left until the next valid sprite size is reached.
If the original image is not a multiple of the given tile width some pixel columns at the right side of the original pictures are skipped.
Check the TICT HQ Website at http://tict.ticalc.org for more tutorials and software.More useful tips, tricks and hints can also be found at our Messageboard at: http://pub26.ezboard.com/btichessteamhq.
Suggestions, bug reports and similar are VERY welcome (use our Messageboard for this!!).
Like Xavier from the Doors Team I like it to get postcards from all over the world. If you want to thank me, just send me an postcard with greetings on it. Thats enough.
My address is:Thomas Nussbaumer Heinrichstrasse 112a A-8010 Graz Austria... and please: no mail bombs if one of my programs had crashed your calculator!