X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=util.cpp;h=c18f00949d1e2d1bca75bd3945ac2fcbc82e6811;hp=592e4d56b47f842a6bb6493e634992bb9cfe0ec5;hb=f6c44598c9dad9ddd024c5f8f010d179a6d971fd;hpb=02d19b8323a1b626acd9d3b4f08bb63f51149cf3 diff --git a/util.cpp b/util.cpp index 592e4d5..c18f009 100644 --- a/util.cpp +++ b/util.cpp @@ -1,5 +1,12 @@ -#include +#define GL_GLEXT_PROTOTYPES 1 + +#include +#include + +#include +#include +#include #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; +} +