Subversion Repositories gelsvn

Rev

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