]> git.sesse.net Git - movit/blob - util.h
Ignore some gcov stuff.
[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 // Converts a HSV color to RGB, but keeps luminance constant
19 // (ie. color luminance is as if S=0).
20 void hsv2rgb_normalized(float h, float s, float v, float *r, float *g, float *b);
21
22 // Column major (same as OpenGL).
23 typedef double Matrix3x3[9];
24
25 // Read a file from disk and return its contents.
26 // Dies if the file does not exist.
27 std::string read_file(const std::string &filename);
28
29 // Compile the given GLSL shader (typically a vertex or fragment shader)
30 // and return the object number.
31 GLuint compile_shader(const std::string &shader_src, GLenum type);
32
33 // Compute a * b.
34 void multiply_3x3_matrices(const Matrix3x3 a, const Matrix3x3 b, Matrix3x3 result);
35
36 // Compute M * [x0 x1 x2]'.
37 void multiply_3x3_matrix_float3(const Matrix3x3 M, float x0, float x1, float x2, float *y0, float *y1, float *y2);
38
39 // Compute m^-1. Result is undefined if the matrix is singular or near-singular.
40 void invert_3x3_matrix(const Matrix3x3 m, Matrix3x3 result);
41
42 // Print a 3x3 matrix to standard output. Useful for debugging.
43 void print_3x3_matrix(const Matrix3x3 m);
44
45 #ifdef NDEBUG
46 #define check_error()
47 #else
48 #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); } }
49 #endif
50
51 #endif // !defined(_UTIL_H)