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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
GLuint compiler_shader()
{
static const GLchar * vertex_shader_source[] =
{
"#version 400 core \n",
" \n",
"layout (location = 0) in vec3 position; \n",
" \n",
"layout (location = 1) in vec4 color; \n",
"out vec4 FS_color; \n",
" \n",
"void main(void) \n",
"{ \n",
" \n",
" FS_color = color; \n",
" gl_Position = vec4(position.x, position.y, position.z, 1.0f); \n",
" \n",
"} \n"
};
static const GLchar * fragment_shader_source[] =
{
"#version 400 core \n",
" \n",
"in vec4 FS_color; \n",
"out vec4 color_output; \n",
" \n",
"void main(void) \n",
"{ \n",
" color_output = FS_color; \n",
" \n",
" \n",
"} \n"
};
GLuint vertex_shader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertex_shader, 1, vertex_shader_source, nullptr);
glCompileShader(vertex_shader);
GLuint fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragment_shader, 1, fragment_shader_source, nullptr);
glCompileShader(fragment_shader);
GLint success1;
GLchar info1[512];
glGetShaderiv(vertex_shader, GL_COMPILE_STATUS, &success1);
if(!success1)
{
glGetShaderInfoLog(vertex_shader, 512, nullptr, info1);
for(int i = 0; i < 512; i++)
cout << info1;
}
GLint success2;
GLchar info2[512];
glGetShaderiv(fragment_shader, GL_COMPILE_STATUS, &success2);
if(!success2)
{
glGetShaderInfoLog(fragment_shader, 512, nullptr, info2);
for(int i = 0; i < 512; i++)
cout << info2;
}
GLuint shaderProgram = glCreateProgram();
glAttachShader(shaderProgram, vertex_shader);
glAttachShader(shaderProgram, fragment_shader);
glLinkProgram(shaderProgram);
GLint success3;
GLchar info3[512];
glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success3);
if(!success3)
{
glGetProgramInfoLog(shaderProgram, 512, nullptr, info3);
cout << "Error, Program linkage" << endl;
for(int i = 0; i < 512; i++)
cout << info3 ;
}
glDetachShader(shaderProgram, vertex_shader);
glDetachShader(shaderProgram, fragment_shader);
glDeleteShader(vertex_shader);
glDeleteShader(fragment_shader);
return shaderProgram;
}
|