Subversion Repositories gelsvn

Rev

Rev 369 | Rev 502 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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