-
Notifications
You must be signed in to change notification settings - Fork 26
/
shader.c
62 lines (50 loc) · 1.49 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2017 OpenSWE1R Maintainers
// Licensed under GPLv2 or any later version
// Refer to the included LICENSE.txt file.
#include <stdlib.h>
#include <stdio.h>
#include "shader.h"
void PrintShaderLog(GLuint shader) {
int infologLength = 0;
int charsWritten = 0;
char *infoLog;
glGetShaderiv(shader, GL_INFO_LOG_LENGTH,&infologLength);
if (infologLength > 0) {
infoLog = (char *)malloc(infologLength);
glGetShaderInfoLog(shader, infologLength, &charsWritten, infoLog);
printf("%s\n",infoLog);
free(infoLog);
}
return;
}
void PrintShaderProgramLog(GLuint program) {
int infologLength = 0;
int charsWritten = 0;
char *infoLog;
glGetProgramiv(program, GL_INFO_LOG_LENGTH,&infologLength);
if (infologLength > 0) {
infoLog = (char *)malloc(infologLength);
glGetProgramInfoLog(program, infologLength, &charsWritten, infoLog);
printf("%s\n",infoLog);
free(infoLog);
}
return;
}
GLuint CreateShaderProgram(GLuint vertexShader, GLuint fragmentShader) {
GLuint program = glCreateProgram();
glAttachShader(program, vertexShader);
glAttachShader(program, fragmentShader);
return program;
}
bool LinkShaderProgram(GLuint program) {
glLinkProgram(program);
GLint isLinked = 0;
glGetProgramiv(program, GL_LINK_STATUS, &isLinked);
return isLinked != GL_FALSE;
}
GLuint CreateShader(const char* source, GLuint type) {
GLuint shader = glCreateShader(type);
glShaderSource(shader, 1, &source,NULL);
glCompileShader(shader);
return shader;
}