-
Notifications
You must be signed in to change notification settings - Fork 0
/
spirala.cpp
60 lines (51 loc) · 1.61 KB
/
spirala.cpp
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
50
51
52
53
54
55
56
57
58
59
#include "spirala.h"
unsigned int CompileShader(unsigned int type, const std::string& source)
{
unsigned int id = glCreateShader(type);
const char* src = source.c_str();
glShaderSource(id, 1, &src, nullptr);
glCompileShader(id);
int result;
glGetShaderiv(id, GL_COMPILE_STATUS, &result);
if (result == GL_FALSE)
{
int length;
glGetShaderiv(id, GL_INFO_LOG_LENGTH, &length);
std::vector<char> message(length);
glGetShaderInfoLog(id, length, &length, &message[0]);
std::cout << "Nie udało się skompilować shadera" << std::endl;
std::cout << &message[0] << std::endl;
glDeleteShader(id);
return 0;
}
return id;
}
std::string LoadShader(const std::string& filepath)
{
std::string shader_code;
std::ifstream shaderStream(filepath, std::ios::in);
if (shaderStream.is_open()) {
std::stringstream sstr;
sstr << shaderStream.rdbuf();
shader_code = sstr.str();
shaderStream.close();
}
else {
std::cout << "Faild to open" << filepath << std::endl;
return "";
}
return shader_code;
}
unsigned int CreateShader(const std::string& vertexShader, const std::string& fragmentShader)
{
unsigned int program = glCreateProgram();
unsigned int vs = CompileShader(GL_VERTEX_SHADER, vertexShader);
unsigned int fs = CompileShader(GL_FRAGMENT_SHADER, fragmentShader);
glAttachShader(program, vs);
glAttachShader(program, fs);
glLinkProgram(program);
glValidateProgram(program);
glDeleteShader(vs);
glDeleteShader(fs);
return program;
}