-
Notifications
You must be signed in to change notification settings - Fork 0
/
texture.c
executable file
·87 lines (81 loc) · 2.54 KB
/
texture.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* texture.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/06/06 14:34:03 by roduquen #+# #+# */
/* Updated: 2019/07/15 21:16:06 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "wolf.h"
#include <SDL.h>
static int convert_surface(t_wolf *data)
{
int i;
SDL_Surface *tmp;
i = 0;
while (i < TEXTURE_NB + SPRITE_NB + MENU_NB)
{
tmp = SDL_ConvertSurfaceFormat(data->surfaces[i]
, SDL_PIXELFORMAT_ARGB8888, 0);
SDL_FreeSurface(data->surfaces[i]);
data->surfaces[i++] = tmp;
}
i = 0;
while (i < MENU_NB)
{
if (!(data->menu[i] = SDL_CreateTextureFromSurface(data->renderer
, data->surfaces[i + TEXTURE_NB + SPRITE_NB])))
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION
, "Couldn't create texture: %s", SDL_GetError());
return (leave_sdl_and_program(data, 1));
}
i++;
}
return (0);
}
static int load_menu_textures(t_wolf *data, int i)
{
while (i < TEXTURE_NB + SPRITE_NB + MENU_NB)
{
if (!(data->surfaces[i] = SDL_LoadBMP(
data->menu_path[i - TEXTURE_NB - SPRITE_NB])))
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION
, "Couldn't load texture: %s", SDL_GetError());
return (leave_sdl_and_program(data, 1));
}
i++;
}
return (convert_surface(data));
}
int load_textures(t_wolf *data)
{
int i;
i = -1;
add_textures_path(data);
while (++i < TEXTURE_NB)
{
if (!(data->surfaces[i] = SDL_LoadBMP(data->texture_path[i])))
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION
, "Couldn't load texture: %s, %d", SDL_GetError(), i);
return (leave_sdl_and_program(data, 1));
}
}
while (i < TEXTURE_NB + SPRITE_NB)
{
if (!(data->surfaces[i] = SDL_LoadBMP(
data->sprite_path[i - TEXTURE_NB])))
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION
, "Couldn't load texture: %s", SDL_GetError());
return (leave_sdl_and_program(data, 1));
}
i++;
}
return (load_menu_textures(data, i));
}