13 #define BUFFER_OFFSET(i) ((char *)NULL + (i))
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);
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);
22 // Column major (same as OpenGL).
23 typedef double Matrix3x3[9];
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);
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);
34 void multiply_3x3_matrices(const Matrix3x3 a, const Matrix3x3 b, Matrix3x3 result);
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);
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);
42 // Print a 3x3 matrix to standard output. Useful for debugging.
43 void print_3x3_matrix(const Matrix3x3 m);
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); } }
51 #endif // !defined(_UTIL_H)