add guMakeShaderFromFile() and guMakeShader()
This commit is contained in:
parent
01f9c2e467
commit
956f249d54
@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@ -215,3 +216,51 @@ char *guGetProgramLog(GLuint id)
|
|||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GLuint guMakeShaderFromFile(GLenum shaderType, const char *fname)
|
||||||
|
{
|
||||||
|
char *source;
|
||||||
|
source = loadFile(fname);
|
||||||
|
if (source == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Error reading file '%s'\n", fname);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
GLuint id = guMakeShader(shaderType, source);
|
||||||
|
free(source);
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
GLuint guMakeShader(GLenum shaderType, const char *source)
|
||||||
|
{
|
||||||
|
GLuint id;
|
||||||
|
GLint status;
|
||||||
|
|
||||||
|
id = glCreateShader(shaderType);
|
||||||
|
if (id <= 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Error creating shader object\n");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
glShaderSource(id, 1, &source, NULL);
|
||||||
|
|
||||||
|
glCompileShader(id);
|
||||||
|
|
||||||
|
glGetShaderiv(id, GL_COMPILE_STATUS, &status);
|
||||||
|
if (status != GL_TRUE)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Error compiling shader\n");
|
||||||
|
char *log = guGetShaderLog(id);
|
||||||
|
fprintf(stderr, "Shader Log:\n%s\n", log);
|
||||||
|
free(log);
|
||||||
|
goto cleanup_shader;
|
||||||
|
}
|
||||||
|
|
||||||
|
return id;
|
||||||
|
|
||||||
|
cleanup_shader:
|
||||||
|
glDeleteShader(id);
|
||||||
|
out:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@ -32,6 +32,8 @@ void guOrtho(guMatrix4x4 *m,
|
|||||||
GLfloat near, GLfloat far);
|
GLfloat near, GLfloat far);
|
||||||
char *guGetShaderLog(GLuint id);
|
char *guGetShaderLog(GLuint id);
|
||||||
char *guGetProgramLog(GLuint id);
|
char *guGetProgramLog(GLuint id);
|
||||||
|
GLuint guMakeShaderFromFile(GLenum shaderType, const char *fname);
|
||||||
|
GLuint guMakeShader(GLenum shaderType, const char *source);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user