-
Notifications
You must be signed in to change notification settings - Fork 0
/
ColorProgram.cpp
45 lines (38 loc) · 1.14 KB
/
ColorProgram.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
#include "ColorProgram.hpp"
#include "gl_compile_program.hpp"
#include "gl_errors.hpp"
Load< ColorProgram > color_program(LoadTagEarly);
ColorProgram::ColorProgram() {
//Compile vertex and fragment shaders using the convenient 'gl_compile_program' helper function:
program = gl_compile_program(
//vertex shader:
"#version 330\n"
"uniform mat4 OBJECT_TO_CLIP;\n"
"in vec4 Position;\n"
"in vec4 Color;\n"
"out vec4 color;\n"
"void main() {\n"
" gl_Position = OBJECT_TO_CLIP * Position;\n"
" color = Color;\n"
"}\n"
,
//fragment shader:
"#version 330\n"
"in vec4 color;\n"
"out vec4 fragColor;\n"
"void main() {\n"
" fragColor = color;\n"
"}\n"
);
//As you can see above, adjacent strings in C/C++ are concatenated.
// this is very useful for writing long shader programs inline.
//look up the locations of vertex attributes:
Position_vec4 = glGetAttribLocation(program, "Position");
Color_vec4 = glGetAttribLocation(program, "Color");
//look up the locations of uniforms:
OBJECT_TO_CLIP_mat4 = glGetUniformLocation(program, "OBJECT_TO_CLIP");
}
ColorProgram::~ColorProgram() {
glDeleteProgram(program);
program = 0;
}