]> git.sesse.net Git - movit/blobdiff - util.cpp
Add lift/gamma/gain GLSL code. Completely black output, due to lack of uniform setting.
[movit] / util.cpp
index 592e4d56b47f842a6bb6493e634992bb9cfe0ec5..c18f00949d1e2d1bca75bd3945ac2fcbc82e6811 100644 (file)
--- a/util.cpp
+++ b/util.cpp
@@ -1,5 +1,12 @@
-#include <math.h>
+#define GL_GLEXT_PROTOTYPES 1
+
+#include <stdio.h>
+#include <assert.h>
+
+#include <GL/gl.h>
+#include <GL/glext.h>
 
+#include <math.h>
 #include "util.h"
 
 void hsv2rgb(float h, float s, float v, float *r, float *g, float *b)
@@ -42,3 +49,42 @@ void hsv2rgb(float h, float s, float v, float *r, float *g, float *b)
        *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);
+}
+
+GLhandleARB compile_shader(const std::string &shader_src, GLenum type)
+{
+       GLhandleARB obj = glCreateShaderObjectARB(type);
+       const GLchar* source[] = { shader_src.data() };
+       const GLint length[] = { shader_src.size() };
+       glShaderSource(obj, 1, source, length);
+       glCompileShader(obj);
+
+       GLchar info_log[4096];
+       GLsizei log_length = sizeof(info_log) - 1;
+       glGetShaderInfoLog(obj, log_length, &log_length, info_log);
+       info_log[log_length] = 0; 
+       printf("shader compile log: %s\n", info_log);
+
+       GLint status;
+       glGetShaderiv(obj, GL_COMPILE_STATUS, &status);
+       if (status == GL_FALSE) {
+               exit(1);
+       }
+
+       return obj;
+}
+