-
Notifications
You must be signed in to change notification settings - Fork 0
/
shader.c
43 lines (30 loc) · 946 Bytes
/
shader.c
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
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <glisy/gl.h>
#include <glisy/shader.h>
GLboolean
glisyShaderInit(GlisyShader *shader, GLuint type, const char *source) {
GLint isCompiled = 0;
if (shader == NULL) return GL_FALSE;
shader->id = glCreateShader(type);
if (shader->id == 0) return GL_FALSE;
shader->type = type;
shader->source = strdup(source);
glShaderSource(shader->id, 1, &source, 0);
glCompileShader(shader->id);
glGetShaderiv(shader->id, GL_COMPILE_STATUS, &isCompiled);
if (!isCompiled) {
GLint infoLen = 0;
glGetShaderiv(shader->id, GL_INFO_LOG_LENGTH, &infoLen);
if (infoLen > 1) {
char *infoLog = malloc(sizeof (char) * infoLen);
glGetShaderInfoLog(shader->id, infoLen, NULL, infoLog);
printf("Error compiling shader:\n%s\n", infoLog);
free(infoLog);
}
glDeleteShader(shader->id);
return GL_FALSE;
}
return GL_TRUE;
}