-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProgram.cpp
More file actions
70 lines (56 loc) · 1.46 KB
/
Program.cpp
File metadata and controls
70 lines (56 loc) · 1.46 KB
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
60
61
62
63
64
65
66
67
68
69
70
#include "Program.h"
#include "Application.h"
#include <iostream>
using namespace std;
Program::Program(GLuint vertex_shader, GLuint fragment_shader)
{
program = glCreateProgram();
glAttachShader(program, vertex_shader);
glAttachShader(program, fragment_shader);
glLinkProgram(program);
GLint status;
glGetProgramiv (program, GL_LINK_STATUS, &status);
if (status == GL_FALSE)
{
GLint infoLogLength;
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLogLength);
GLchar *strInfoLog = new GLchar[infoLogLength + 1];
glGetProgramInfoLog(program, infoLogLength, NULL, strInfoLog);
cout << "Program link error: " << strInfoLog;
delete[] strInfoLog;
}
proj_location = glGetUniformLocation(program, "Projection");
view_location = glGetUniformLocation(program, "View");
model_location = glGetUniformLocation(program, "Model");
}
void Program::setModelMatrix(mat4 matrix)
{
glUniformMatrix4fv(model_location, 1, GL_FALSE, (const GLfloat*) matrix);
}
void Program::begin()
{
bind();
glUniformMatrix4fv(proj_location, 1, GL_FALSE, (const GLfloat*) Application::getProjection());
glUniformMatrix4fv(view_location, 1, GL_FALSE, (const GLfloat*) Application::getView());
}
void Program::begin(mat4 model_matrix)
{
begin();
setModelMatrix(model_matrix);
}
void Program::end()
{
unbind();
}
void Program::bind()
{
glUseProgram(program);
}
void Program::unbind()
{
glUseProgram(0);
}
GLuint Program::getId()
{
return program;
}