1 #ifndef _util_h_ 2 #define _util_h_ 3 4 #include <GL/glew.h> 5 #include <GLFW/glfw3.h> 6 #include "config.h" 7 8 #define PI 3.14159265359 9 #define DEGREES(radians) ((radians) * 180 / PI) 10 #define RADIANS(degrees) ((degrees) * PI / 180) 11 #define ABS(x) ((x) < 0 ? (-(x)) : (x)) 12 #define MIN(a, b) ((a) < (b) ? (a) : (b)) 13 #define MAX(a, b) ((a) > (b) ? (a) : (b)) 14 #define SIGN(x) (((x) > 0) - ((x) < 0)) 15 16 #if DEBUG 17 #define LOG(...) printf(__VA_ARGS__) 18 #else 19 #define LOG(...) 20 #endif 21 22 typedef struct { 23 unsigned int fps; 24 unsigned int frames; 25 double since; 26 } FPS; 27 28 int rand_int(int n); 29 double rand_double(); 30 void update_fps(FPS *fps); 31 32 GLuint gen_buffer(GLsizei size, GLfloat *data); 33 void del_buffer(GLuint buffer); 34 GLfloat *malloc_faces(int components, int faces); 35 GLuint gen_faces(int components, int faces, GLfloat *data); 36 GLuint make_shader(GLenum type, const char *source); 37 GLuint load_shader(GLenum type, const char *path); 38 GLuint make_program(GLuint shader1, GLuint shader2); 39 GLuint load_program(const char *path1, const char *path2); 40 void load_png_texture(const char *file_name); 41 char *tokenize(char *str, const char *delim, char **key); 42 int char_width(char input); 43 int string_width(const char *input); 44 int wrap(const char *input, int max_width, char *output, int max_length); 45 46 #endif 47