Repository navigation
Expand file tree
/
Copy pathtextotexture.cpp
More file actions
94 lines (82 loc) · 1.7 KB
/
Copy pathtextotexture.cpp
File metadata and controls
94 lines (82 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <stdio.h>
unsigned char* TexTo2DTexture(char *filename, int *width, int *height) {
FILE *fp;
unsigned char *texture, *tp;
int s, t, nums, numt;
fopen_s(&fp, filename, "rb");
if (fp == NULL) {
fprintf(stderr, "Cannot open Tex file '%s'\n", filename);
return NULL;
}
nums = fgetc(fp);
fgetc(fp);
fgetc(fp);
fgetc(fp);
numt = fgetc(fp);
fgetc(fp);
fgetc(fp);
fgetc(fp);
texture = new unsigned char[4 * nums * numt];
if (texture == NULL)
{
fprintf(stderr, "Cannot allocate the texture array!\b");
return NULL;
}
for (t = 0, tp = texture; t < numt; t++)
{
for (s = 0; s < nums; s++, tp += 4)
{
*(tp + 0) = fgetc(fp);
*(tp + 1) = fgetc(fp);
*(tp + 2) = fgetc(fp);
*(tp + 3) = fgetc(fp);
}
}
fclose(fp);
*width = nums;
*height = numt;
return texture;
}
unsigned char* TexTo3DTexture(char *filename, int *width, int *height, int *depth) {
FILE *fp;
unsigned char *texture, *tp;
int s, t, p, nums, numt, nump;
fopen_s(&fp, filename, "rb");
if (fp == NULL) {
fprintf(stderr, "Cannot open Tex file '%s'\n", filename);
return NULL;
}
nums = fgetc(fp);
fgetc(fp);
fgetc(fp);
fgetc(fp);
numt = fgetc(fp);
fgetc(fp);
fgetc(fp);
fgetc(fp);
nump = fgetc(fp);
fgetc(fp);
fgetc(fp);
fgetc(fp);
texture = new unsigned char[4 * nums * numt * nump];
if (texture == NULL)
{
fprintf(stderr, "Cannot allocate the texture array!\b");
return NULL;
}
for (p = 0, tp = texture; p < nump; p++) {
for (t = 0; t < numt; t++) {
for (s = 0; s < nums; s++, tp += 4) {
*(tp + 0) = fgetc(fp);
*(tp + 1) = fgetc(fp);
*(tp + 2) = fgetc(fp);
*(tp + 3) = fgetc(fp);
}
}
}
fclose(fp);
*width = nums;
*height = numt;
*depth = nump;
return texture;
}