#include #include #include #include #include #include #include "dffviewer.h" #include "../libdff/dff.h" #include "../libtxd/txd.h" int TxdToOglTex(int start, FILE *txd, Texture **tl) { int i; int texcount; Texture *piclist; // Texture *texlist; texcount = ReadTxd(start, txd, &piclist); // texlist = (Texture *) malloc(texcount*sizeof(Texture)); for (i = 0; i < texcount; i++) { // strcpy(texlist[i].name, piclist[i].name); // strcpy(texlist[i].alpha, piclist[i].alpha); // texlist[i].width = piclist[i].width; // texlist[i].height = piclist[i].height; // if (piclist[i].channels == 3) // piclist[i].format = GL_RGB; // else if (piclist[i].channels == 4) // piclist[i].format = GL_RGBA; // else { // fprintf(stderr, "Unknown texture format\n"); // exit(2); // } // texlist[i].bpp = piclist[i].bpp; // texlist[i].channels = piclist[i].channels; // texlist[i].data = piclist[i].data; // piclist[i].data = NULL; } // free(piclist); // *tl = texlist; *tl = piclist; return texcount; } int GetTextureIndex(char **imagefiles, char *filename) { int i; i = 0; while (imagefiles[i] != NULL) { if (strcmp(imagefiles[i], filename) == 0) return i; i++; } return -1; } char **AddTexture(char **imagefiles, char *filename) { int i; int length; if (imagefiles == NULL) { imagefiles = (char **) malloc(4); imagefiles[0] = NULL; } i = 0; while (imagefiles[i] != NULL) { if (strcmp(imagefiles[i], filename) == 0) return imagefiles; i++; } length = strlen(filename); imagefiles[i] = (char *) malloc(length+1+4); strcpy(imagefiles[i], filename); i++; imagefiles = realloc(imagefiles, (i+1)*4); imagefiles[i] = NULL; return imagefiles; } void GetTextures(clump *clp, char ***texturefiles) { int i, j; geometry *geo; texture *tex; for (i = 0; i < clp->geocount; i++) { for (j = 0; j < clp->geo[i].matcount; j++) { geo = &clp->geo[i]; if (geo->mat[j].hastexture) { tex = &geo->mat[j].tex; if (strcmp(tex->tex, "") != 0) *texturefiles = AddTexture(*texturefiles, tex->tex); if (strcmp(tex->alpha, "") != 0) { *texturefiles = AddTexture(*texturefiles, tex->alpha); } } if (geo->mat[j].hasreflection) { tex = &geo->mat[j].reflection; if (strcmp(tex->tex, "") != 0) *texturefiles = AddTexture(*texturefiles, tex->tex); if (strcmp(tex->alpha, "") != 0) { *texturefiles = AddTexture(*texturefiles, tex->alpha); } } } } }