forked from BSVino/docs.gl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshader_compile.htm
50 lines (43 loc) · 1.85 KB
/
shader_compile.htm
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
GLuint vshader = {%glCreateShader}(GL_VERTEX_SHADER);
{%glShaderSource}(vshader, 1, &vertex_shader_source, NULL); // vertex_shader_source is a GLchar* containing glsl shader source code
{%glCompileShader}(vshader);
GLint vertex_compiled;
{%glGetShaderiv}(vshader, GL_COMPILE_STATUS, &vertex_compiled);
if (vertex_compiled != GL_TRUE)
{
GLsizei log_length = 0;
GLchar message[1024];
{%glGetShaderInfoLog}(vshader, 1024, &log_length, message);
// Write the error to a log
}
GLuint fshader = {%glCreateShader}(GL_FRAGMENT_SHADER);
{%glShaderSource}(fshader, 1, &fragment_shader_source, NULL); // fragment_shader_source is a GLchar* containing glsl shader source code
{%glCompileShader}(fshader);
GLint fragment_compiled;
{%glGetShaderiv}(fshader, GL_COMPILE_STATUS, &fragment_compiled);
if (fragment_compiled != GL_TRUE)
{
GLsizei log_length = 0;
GLchar message[1024];
{%glGetShaderInfoLog}(fshader, 1024, &log_length, message);
// Write the error to a log
}
GLuint program = {%glCreateProgram}();
// This step is unnecessary if you use the location specifier in your shader
// e.g. layout (location = 0) in vec3 position;
{%glBindAttribLocation}(program, 0, "position"); // The index passed into {%glBindAttribLocation} is
{%glBindAttribLocation}(program, 1, "texcoord"); // used by {%glEnableVertexAttribArray}. "position"
{%glBindAttribLocation}(program, 2, "normal"); // "texcoord" "normal" and "color" are the names of the
{%glBindAttribLocation}(program, 3, "color"); // respective inputs in your fragment shader.
{%glAttachShader}(program, vshader);
{%glAttachShader}(program, fshader);
{%glLinkProgram}(program);
GLint program_linked;
{%glGetProgramiv}(program, GL_LINK_STATUS, &program_linked);
if (program_linked != GL_TRUE)
{
GLsizei log_length = 0;
GLchar message[1024];
{%glGetProgramInfoLog}(program, 1024, &log_length, message);
// Write the error to a log
}