]> git.sesse.net Git - movit/blob - util.h
Move pixel_format out of the ImageFormat struct, since it is only relevant for FlatInput.
[movit] / util.h
1 #ifndef _UTIL_H
2 #define _UTIL_H 1
3
4 // Various utilities.
5
6 #include <stdio.h>
7 #include <stdlib.h>
8
9 #include <string>
10
11 #include "opengl.h"
12
13 #define BUFFER_OFFSET(i) ((char *)NULL + (i))
14
15 // Converts a HSV color to RGB. Assumes h in [0, 2pi> or [-pi, pi>
16 void hsv2rgb(float h, float s, float v, float *r, float *g, float *b);
17
18 // Column major (same as OpenGL).
19 typedef double Matrix3x3[9];
20
21 // Read a file from disk and return its contents.
22 // Dies if the file does not exist.
23 std::string read_file(const std::string &filename);
24
25 // Compile the given GLSL shader (typically a vertex or fragment shader)
26 // and return the object number.
27 GLuint compile_shader(const std::string &shader_src, GLenum type);
28
29 // Compute a * b.
30 void multiply_3x3_matrices(const Matrix3x3 a, const Matrix3x3 b, Matrix3x3 result);
31
32 // Compute m^-1. Result is undefined if the matrix is singular or near-singular.
33 void invert_3x3_matrix(const Matrix3x3 m, Matrix3x3 result);
34
35 // Print a 3x3 matrix to standard output. Useful for debugging.
36 void print_3x3_matrix(const Matrix3x3 m);
37
38 #ifdef NDEBUG
39 #define check_error()
40 #else
41 #define check_error() { int err = glGetError(); if (err != GL_NO_ERROR) { printf("GL error 0x%x at %s:%d\n", err, __FILE__, __LINE__); exit(1); } }
42 #endif
43
44 #endif // !defined(_UTIL_H)