p
This commit is contained in:
parent
1a190594fe
commit
90d565ff8d
3 changed files with 67 additions and 11 deletions
35
main.c
35
main.c
|
|
@ -13,8 +13,9 @@ void checkGlError() {
|
|||
}
|
||||
}
|
||||
|
||||
/// returns 0 if failed.
|
||||
GLuint compile_shader(GLuint type, const char *src) {
|
||||
GLuint id = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
GLuint id = glCreateShader(type);
|
||||
glShaderSource(id, 1, &src, 0);
|
||||
glCompileShader(id);
|
||||
|
||||
|
|
@ -34,16 +35,19 @@ GLuint compile_shader(GLuint type, const char *src) {
|
|||
return id;
|
||||
}
|
||||
|
||||
/// returns 0 if failed.
|
||||
GLuint create_shader(const char *fragment_src) {
|
||||
GLuint program = glCreateProgram();
|
||||
GLuint fragment_shader = compile_shader(GL_FRAGMENT_SHADER, fragment_src);
|
||||
|
||||
glAttachShader(program, fragment_shader);
|
||||
glLinkProgram(program);
|
||||
glValidateProgram(program);
|
||||
glDeleteShader(fragment_shader);
|
||||
|
||||
return program;
|
||||
if (!(fragment_shader == 0)) {
|
||||
glAttachShader(program, fragment_shader);
|
||||
glLinkProgram(program);
|
||||
glValidateProgram(program);
|
||||
glDeleteShader(fragment_shader);
|
||||
return program;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
GLuint load_shader(const char *path) {
|
||||
|
|
@ -60,6 +64,21 @@ GLuint load_shader(const char *path) {
|
|||
|
||||
GLuint shader = create_shader(string);
|
||||
|
||||
if (shader == 0) {
|
||||
// print file
|
||||
int line_count = 1;
|
||||
printf("%i\t", line_count);
|
||||
line_count++;
|
||||
for (int i = 0; i < length; i++) {
|
||||
printf("%c", string[i]);
|
||||
if (string[i] == '\n') {
|
||||
printf("%i\t", line_count);
|
||||
line_count++;
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
free(string);
|
||||
return shader;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue