]> git.sesse.net Git - movit/blobdiff - util.cpp
Start actually piecing together the GLSL shaders from the effect chain.
[movit] / util.cpp
index b427625219964924db9a88a4f9336523abee7ac8..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)
@@ -57,3 +64,27 @@ std::string read_file(const std::string &filename)
 
        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;
+}
+