mirror of
https://notabug.org/scuti/lib3ddevil1
synced 2025-05-31 14:11:42 +05:30
Unpack textures has correct offsets for textures
This commit is contained in:
45
test/main.c
45
test/main.c
@@ -102,18 +102,55 @@ bool unpackpld (const char *filedata,
|
||||
}
|
||||
free(bds);
|
||||
return;
|
||||
|
||||
const char *fmt = (const char*)malloc(strlen(filename) + 3 + 3);
|
||||
strcat(fmt, filename);
|
||||
strcat(fmt, "%d.dds");
|
||||
} */
|
||||
|
||||
void unpacktextures(const char *filedata,
|
||||
unsigned int filesize) {
|
||||
struct TexturePack *tp = (struct TexturePack*)filedata;
|
||||
|
||||
struct TextureBatch **batches = NULL;
|
||||
batches = (struct TextureBatch**)malloc(tp -> batchNumber);
|
||||
|
||||
struct TextureBatchDescriptor **descripts = NULL;
|
||||
descripts = (struct TextureBatchDescriptor**)malloc(tp -> batchNumber);
|
||||
gettbd(descripts, filedata, filesize);
|
||||
// array of pointers - texture data exists in memory in filedata.
|
||||
unsigned int texturecount = gettexturebatch(batches,
|
||||
descripts,
|
||||
filedata,
|
||||
filesize);
|
||||
struct Texture **textures = NULL;
|
||||
textures = (struct Texture**)malloc(texturecount);
|
||||
|
||||
unsigned int i;
|
||||
unsigned int j;
|
||||
// k is access to index of textures.
|
||||
unsigned int k = 0;
|
||||
unsigned int offset = 0;
|
||||
for (i = 0; i < tp -> batchNumber; i++) {
|
||||
for (j = 0; j < descripts[i] -> texNumber; j++) {
|
||||
printf("texture offsets %x\n", offset + tp -> firstBatchOffset);
|
||||
textures[k] = (struct Texture*)batches + offset;
|
||||
offset += descripts[i] -> textureSize;
|
||||
k++;
|
||||
}
|
||||
}
|
||||
free(textures);
|
||||
free(descripts);
|
||||
free(batches);
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv) {
|
||||
char *f = argv[1];
|
||||
unsigned int bufsize = 0;
|
||||
char *buffer = loadfile(f, &bufsize);
|
||||
// unpackpld(buffer, bufsize, f);
|
||||
// unpacktextures(buffer, bufsize);
|
||||
struct TexturePack *tp = (struct TexturePack*)buffer;
|
||||
struct TextureBatch **batches = NULL;
|
||||
batches = (struct TextureBatch**)malloc(tp -> batchNumber);
|
||||
gettexturebatch(batches, buffer, bufsize);
|
||||
unpacktextures(buffer, bufsize);
|
||||
free(buffer);
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user