-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphics.c
95 lines (62 loc) · 1.99 KB
/
graphics.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
#include "graphics.h"
// sets background color (deprecated)
void decaf_set_bg_color(int r, int g, int b) {
SDL_SetRenderDrawColor(decaf_get_renderer(), r, g, b, 255);
SDL_Rect rect = {0, 0, 256, 144};
SDL_RenderFillRect(decaf_get_renderer(), &rect);
SDL_SetRenderDrawColor(decaf_get_renderer(), 0, 0, 0, 255);
}
// loads bmp file from given path
SDL_Texture *decaf_graphics_load(char *path) {
// loads image onto a surface
SDL_Surface *surface = SDL_LoadBMP(path);
if (surface != NULL) {
printf("image loaded: %s\n", path);
}
// converts the surface into a texture
SDL_Texture *texture = SDL_CreateTextureFromSurface(decaf_get_renderer(), surface);
// unloads surface from earlier
SDL_FreeSurface(surface);
// returns back the texture given
return texture;
}
// draws texture
void decaf_graphics_image(SDL_Texture *texture, SDL_Rect *rect) {
// draws the texture onto the renderer
SDL_RenderCopy(decaf_get_renderer(), texture, NULL, rect);
return;
}
// draws texture with float values
void decaf_graphics_imagef(SDL_Texture *texture, SDL_FRect *rect) {
SDL_RenderCopyF(decaf_get_renderer(), texture, NULL, rect);
return;
}
// draws sprite from cell
void decaf_graphics_sprite(SDL_Texture *texture, int cell, SDL_Rect *rect) {
struct spriteData {
int x;
int y;
int w;
int h;
};
struct SDL_Rect sprite = {cell*8, 0, 8, 8};
SDL_RenderCopy(decaf_get_renderer(), texture, &sprite, rect);
return;
}
// draws sprite from cell with float values
void decaf_graphics_spritef(SDL_Texture *texture, int cell, SDL_FRect *rect) {
struct spriteData {
int x;
int y;
int w;
int h;
};
struct SDL_Rect sprite = {cell*8, 0, 8, 8};
SDL_RenderCopyF(decaf_get_renderer(), texture, &sprite, rect);
return;
}
// frees texture from memory
void destroy_texture(SDL_Texture *texture) {
SDL_DestroyTexture(texture);
return;
}