Subversion Repositories gelsvn

Rev

Rev 502 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
369 jab 1
#include <iostream>
2
#include <fstream>
3
#include <string>
4
#include <GL/glew.h>
5
#include <GLGraphics/gel_glu.h>
6
using namespace std;
7
 
8
void print_glsl_program_log(GLuint obj)
9
{
10
	GLint infologLength = 0;
11
	glGetProgramiv(obj, GL_INFO_LOG_LENGTH, &infologLength);
12
	if (infologLength > 0)
13
	{
14
		char* infoLog = new char[infologLength];
15
		glGetProgramInfoLog(obj, infologLength, 0, infoLog);
16
		cout << "InfoLog:\n%s\n\n" << infoLog << endl;
17
		delete infoLog;
18
	}
19
}
20
 
21
const std::string read_glsl_source(const std::string& path, const std::string& file)
22
{
23
	string fullpath = path + "/" + file;
24
	ifstream is(fullpath.c_str(), ios::binary);
25
	string str, contents;
26
	while(getline(is,str)) 
27
	{
28
		contents += str;
29
		contents += "\n";
30
	}
31
	return contents;
32
}
33
 
34
GLuint create_glsl_shader(GLuint stype, const std::string& src)
35
{
36
	GLuint S = glCreateShader(stype);
37
	const GLchar* src_cstr = src.c_str();
38
	glShaderSource(S, 1, &src_cstr, 0);
39
	glCompileShader(S);
40
 
41
	GLint status;
42
	glGetShaderiv(S,GL_COMPILE_STATUS, &status);
43
	if (status == 0) 
44
	{
45
		GLint infologLength = 0;
46
		glGetShaderiv(S, GL_INFO_LOG_LENGTH, &infologLength);
47
		if (infologLength > 0)
48
		{
49
			char* infoLog = new char[infologLength];
50
			glGetShaderInfoLog(S, infologLength, 0, infoLog);
51
			cout << "InfoLog: " << infoLog << endl;
52
			delete infoLog;
53
		}
54
		return 0;
55
	}
56
	return S;
57
}
58
 
59
GLuint create_glsl_shader(GLuint stype, const std::string& path, const std::string& file)
60
{
61
	string str = read_glsl_source(path, file);
62
	if(str != "")
63
		return create_glsl_shader(stype, str);
64
	return 0;
65
}
66