-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathshader.cpp
More file actions
49 lines (38 loc) · 958 Bytes
/
shader.cpp
File metadata and controls
49 lines (38 loc) · 958 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "shader.h"
#include <fstream>
#include <string>
#include <sstream>
#include <iostream>
using namespace std;
GLuint loadShader(const char* path, GLenum shaderType)
{
ifstream in(path, ios::in);
string content;
if(!in.is_open())
{
cout << "File " << path << " not found" << endl;
return -1;
}
string line = "";
while(!in.eof()) {
getline(in, line);
content.append(line + "\n");
}
in.close();
const char* src = content.c_str();
GLuint id = glCreateShader(shaderType);
glShaderSource(id, 1, &src, NULL);
glCompileShader(id);
GLint status;
glGetShaderiv(id, GL_COMPILE_STATUS, &status);
if (status == GL_FALSE)
{
GLint infoLogLength;
glGetShaderiv(id, GL_INFO_LOG_LENGTH, &infoLogLength);
GLchar *strInfoLog = new GLchar[infoLogLength + 1];
glGetShaderInfoLog(id, infoLogLength, NULL, strInfoLog);
cout << "Shader Compile Error (" << path << "): " << strInfoLog;
delete[] strInfoLog;
}
return id;
}