forked from ugocapeto/thepainter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
load_texture_arr.c
110 lines (90 loc) · 2.6 KB
/
load_texture_arr.c
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "header.h"
void load_texture_arr(
char *filename,
texture_struct **ptexture_arr,
int *ptexture_nbr
)
{
texture_struct *texture_arr;
int texture_nbr;
FILE *fp;
int line;
int temp_int;
char filename2[256];
int texture_ind;
int *opacity_image_arr;
int opacity_image_width;
int opacity_image_height;
int *bumpity_image_arr;
int bumpity_image_width;
int bumpity_image_height;
int width;
int height;
texture_struct texture_data;
int err_flag;
texture_arr= 0;
texture_nbr= 0;
fp= fopen(filename,"r");
if ( fp == NULL ) {
fprintf(stdout,"%s not found!\n",filename);
error_handler((char *)"load_texture_arr");
}
for ( line= 1 ; ; line+=2 ) {
temp_int= fscanf(fp,"%s",filename2);
if ( temp_int == EOF )
break;
fprintf(stdout,"opacity image file = %s\n",filename2);
err_flag= load_image(
filename2,
&opacity_image_arr,
&opacity_image_width,
&opacity_image_height
);
if ( err_flag == 1 ) {
fprintf(stdout,"opacity image file %s not loaded!\n",filename2);
error_handler((char *)"load_texture_arr");
}
width= opacity_image_width;
height= opacity_image_height;
temp_int= fscanf(fp,"%s",filename2);
if ( temp_int == EOF ) {
fprintf(stdout,"no entry for bumpity image file!\n");
error_handler((char *)"load_texture_arr");
}
fprintf(stdout,"bumpity file = %s\n",filename2);
err_flag= load_image(
filename2,
&bumpity_image_arr,
&bumpity_image_width,
&bumpity_image_height
);
if ( err_flag == 1 ) {
fprintf(stdout,"bumpity image file %s not loaded!\n",filename2);
error_handler((char *)"load_texture_arr");
}
if ( !(bumpity_image_width == width) ) {
fprintf(stdout,"opacity image and bumpity image must have same width!\n");
error_handler((char *)"load_texture_arr");
}
if ( !(bumpity_image_height == height) ) {
fprintf(stdout,"opacity image and bumpity image must have same height!\n");
error_handler((char *)"load_texture_arr");
}
if ( texture_nbr == 0 ) {
texture_arr= (texture_struct *)calloc((texture_nbr+1),sizeof(texture_struct));
}
else {
texture_arr= (texture_struct *)realloc(texture_arr,(texture_nbr+1)*sizeof(texture_struct));
}
texture_ind= texture_nbr;
texture_nbr++;
texture_data.opacity_image_arr= opacity_image_arr;
texture_data.bumpity_image_arr= bumpity_image_arr;
texture_data.width= width;
texture_data.height= height;
texture_arr[texture_ind]= texture_data;
}
fclose(fp);
(*ptexture_arr)= texture_arr;
(*ptexture_nbr)= texture_nbr;
}