#include #include #include #include "txd.h" int main(int argc, char *argv[]) { int texcount; FILE *txd, *tga; image img; unsigned char colors[256][4]; unsigned char *indices; char name[64]; char alpha[64]; char file[1024]; indices = 0; if (argc < 2) { fprintf(stderr, "Usage: %s txd\n", argv[0]); exit(1); } if ((txd = fopen(argv[1], "rb+")) == NULL) { if ((txd = fopen(argv[1], "wb")) == NULL) { fprintf(stderr, "Could not open file: %s\n", argv[1]); exit(1); } } fseek(txd, 0, SEEK_END); rwvers = 0x310; texcount = 0; if (ftell(txd) == 0) { WriteHeader(TEXTUREDICT, 0, rwvers, txd); WriteHeader(STRUCT, 4, rwvers, txd); fwrite(&texcount, 4, 1, txd); } else { fseek(txd, 24, 0); fread(&texcount, 4, 1, txd); } printf("Texture name: "); fgets(name, 64, stdin); name[strlen(name)-1] = '\0'; printf("Alpha name (can be left empty): "); fgets(alpha, 64, stdin); alpha[strlen(alpha)-1] = '\0'; printf("TGA file name: "); fgets(file, 1024, stdin); file[strlen(file)-1] = '\0'; if ((tga = fopen(file, "rb")) == NULL) { fprintf(stderr, "Could not open file: %s\n", file); exit(1); } indices = ReadTga(colors, indices, &img, tga); MakeTexture(256, 256, 8, indices, colors, name, alpha, txd); texcount++; UpdateTexCount(txd, texcount); UpdateTexDict(txd); return 0; }