-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcelumato.h
84 lines (71 loc) · 1.83 KB
/
celumato.h
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
#ifndef CELUMATO_H_
#define CELUMATO_H_
#include <SDL2/SDL.h>
int scc(int code) {
if(code < 0) {
fprintf(stderr, "SDL ERROR: %s\n", SDL_GetError());
exit(1);
}
return code;
}
void *scp(void *ptr) {
if(ptr == NULL) {
fprintf(stderr, "SDL ERROR: %s\n", SDL_GetError());
exit(1);
}
return ptr;
}
#define SCREEN_WIDTH 1024
#define SCREEN_HEIGHT 768
#define BACKGROUND_COLOR 0x181818ff
#define HEX_COLOR_UNPACK(color) \
((color >> (8 * 3)) & 0xFF), \
((color >> (8 * 2)) & 0xFF), \
((color >> (8 * 1)) & 0xFF), \
((color >> (8 * 0)) & 0xFF)
#define ROWS 100
#define COLS 100
#define CELL_WIDTH ((float) SCREEN_WIDTH / (float) COLS)
#define CELL_HEIGHT ((float) SCREEN_HEIGHT / (float)ROWS)
/*
*
return scp(SDL_CreateWindow(
"Celumato",
0,0,
SCREEN_WIDTH, SCREEN_HEIGHT,
SDL_WINDOW_RESIZABLE));
* */
SDL_Window *celumato_create_window(void) {
return scp(SDL_CreateWindow(
"Celumato",
SCREEN_WIDTH, SCREEN_HEIGHT,
0,0,
SDL_WINDOW_RESIZABLE
));
}
SDL_Renderer *celumato_create_renderer(SDL_Window * window) {
SDL_Renderer *renderer =
scp(SDL_CreateRenderer(window,
-1,
SDL_RENDERER_ACCELERATED));
scc(SDL_RenderSetLogicalSize(renderer,
SCREEN_WIDTH,
SCREEN_HEIGHT));
return renderer;
}
void celumato_fill_rect(SDL_Renderer *renderer, float x, float y, float w, float h, Uint32 color) {
SDL_Rect rect = {
.x = (int) floorf(x),
.y = (int) floorf(y),
.w = (int) floorf(w),
.h = (int) floorf(h),
};
scc(SDL_SetRenderDrawColor(
renderer,
HEX_COLOR_UNPACK(color)));
scc(SDL_RenderFillRect(renderer, &rect));
}
int mod(int a, int b) {
return (a % b + b) % b;
}
#endif