GLhandleARB read_shader(const char* filename, GLenum type)
{
- static char buf[131072];
- FILE *fp = fopen(filename, "r");
- if (fp == NULL) {
- perror(filename);
- exit(1);
- }
-
- int len = fread(buf, 1, sizeof(buf), fp);
- fclose(fp);
+ std::string shader_src = read_file(filename);
GLhandleARB obj = glCreateShaderObjectARB(type);
- const GLchar* source[] = { buf };
- const GLint length[] = { len };
+ const GLchar* source[] = { shader_src.data() };
+ const GLint length[] = { shader_src.size() };
glShaderSource(obj, 1, source, length);
glCompileShader(obj);
*g += m;
*b += m;
}
+
+std::string read_file(const std::string &filename)
+{
+ static char buf[131072];
+ FILE *fp = fopen(filename.c_str(), "r");
+ if (fp == NULL) {
+ perror(filename.c_str());
+ exit(1);
+ }
+
+ int len = fread(buf, 1, sizeof(buf), fp);
+ fclose(fp);
+
+ return std::string(buf, len);
+}
#include <stdio.h>
#include <stdlib.h>
+#include <string>
+
// assumes h in [0, 2pi> or [-pi, pi>
void hsv2rgb(float h, float s, float v, float *r, float *g, float *b);
+std::string read_file(const std::string &filename);
+
#ifdef NDEBUG
#define check_error()
#else