-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtility.c
More file actions
30 lines (26 loc) · 813 Bytes
/
Utility.c
File metadata and controls
30 lines (26 loc) · 813 Bytes
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
#include "Utility.h"
#include "debugmalloc.h"
SDL_Surface *get_rgba_surface(int w, int h) {
SDL_Surface *surface = SDL_CreateRGBSurfaceWithFormat(0, w, h, 32, SDL_PIXELFORMAT_ABGR32);
return surface;
}
char *file_from_path(char *path) {
size_t last = 0;
for (int i = 0; path[i] != '\0'; i++) {
if (path[i] == '\\' || path[i] == '/')
last = i;
}
return path + last + 1;
}
void log_error_base(const char *file, int line, const char *fmt, ...) {
va_list valist;
va_start(valist, fmt);
SDL_LogMessageV(SDL_LOG_CATEGORY_ERROR, SDL_LOG_PRIORITY_CRITICAL, fmt, valist);
va_end(valist);
}
SDL_Texture *load_texture(const char *path, SDL_Renderer *renderer) {
SDL_Surface *surf = IMG_Load(path);
SDL_Texture *tex = SDL_CreateTextureFromSurface(renderer, surf);
SDL_FreeSurface(surf);
return tex;
}