14 #define BUFFER_OFFSET(i) ((char *)NULL + (i))
16 // Converts a HSV color to RGB. Assumes h in [0, 2pi> or [-pi, pi>
17 void hsv2rgb(float h, float s, float v, float *r, float *g, float *b);
19 // Converts a HSV color to RGB, but keeps luminance constant
20 // (ie. color luminance is as if S=0).
21 void hsv2rgb_normalized(float h, float s, float v, float *r, float *g, float *b);
23 // Read a file from disk and return its contents.
24 // Dies if the file does not exist.
25 std::string read_file(const std::string &filename);
27 // Compile the given GLSL shader (typically a vertex or fragment shader)
28 // and return the object number.
29 GLuint compile_shader(const std::string &shader_src, GLenum type);
31 // Print a 3x3 matrix to standard output. Useful for debugging.
32 void print_3x3_matrix(const Eigen::Matrix3d &m);
34 // Output a GLSL 3x3 matrix declaration.
35 std::string output_glsl_mat3(const std::string &name, const Eigen::Matrix3d &m);
37 // Calculate where to sample, and with what weight, if one wants to use
38 // the GPU's bilinear hardware to sample w1 * x[0] + w2 * x[1].
39 static inline void combine_two_samples(float w1, float w2, float *offset, float *total_weight)
41 assert(w1 * w2 >= 0.0f); // Should not have differing signs.
42 if (fabs(w1 + w2) < 1e-6) {
46 *offset = w2 / (w1 + w2);
47 *total_weight = w1 + w2;
49 assert(*offset >= 0.0f);
50 assert(*offset <= 1.0f);
56 #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); } }
59 #endif // !defined(_UTIL_H)