⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 converter.cpp

📁 游戏编程精粹6第1章 通用编程,对入门的游戏开发者很有帮助.
💻 CPP
字号:
#include "tgahelpers.h"#include "../viewer/TextureResource.h"#include <cstdio>#include <cstring>bool WriteTexture (const TextureResource* texture, const char* filename){    FILE* fout = fopen(filename, "wb");    if (fout == NULL)        return false;      	    const int sizeInBytes = sizeof(TextureResource) + texture->dataSize;    const int bytesWritten = (int)fwrite (texture, 1, sizeInBytes, fout);            fclose(fout);    return (bytesWritten == sizeInBytes);}void CalculateOutputFilename (char* outFile, const char* inFile){    strcpy (outFile, inFile);    char* ext = strrchr(outFile, '.');    if (ext == NULL)        strcat (outFile, ".texture");    else        strcpy (ext, ".texture");}int main(int argc, char **argv){    if (argc != 2)    {        printf ("Usage: converter file.tga\n");        printf ("       Converts a tga file (without compression) to a binary texture ready to be\n");        printf ("       used in the runtime. The output file is file.tga.texture.\n");        return 1;    }        const char* srcFile = argv[1];    TextureResource* texture = LoadTGA(srcFile);    if (texture == NULL)    {        printf ("Could not load %s. File could be missing or using TGA comppression.\n", srcFile);        return 1;    }            char destFile[256];    CalculateOutputFilename(destFile, srcFile);        if (!WriteTexture(texture, destFile))    {        printf ("Could not write %s texture.\n", destFile);        delete [] texture;        return 1;    }        delete [] texture;        return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -