Initial commit
This commit is contained in:
90
application/source/engine/shader.c
Normal file
90
application/source/engine/shader.c
Normal file
@@ -0,0 +1,90 @@
|
||||
|
||||
|
||||
#include "block.h"
|
||||
|
||||
#include "member.h"
|
||||
|
||||
#include "uniform.h"
|
||||
|
||||
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
|
||||
#include <GL/glext.h>
|
||||
|
||||
#include <GL/gl.h> // GL 1.1 functions
|
||||
|
||||
#include <GL/glx.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../fileSystem.h"
|
||||
|
||||
#include "../array.h"
|
||||
|
||||
#include "../char.h"
|
||||
|
||||
#include "sampler2D.h"
|
||||
|
||||
|
||||
class attribute{
|
||||
|
||||
GLchar name[64];
|
||||
|
||||
GLint location;
|
||||
|
||||
GLenum type;
|
||||
|
||||
}
|
||||
|
||||
class shader{
|
||||
|
||||
GLuint glShader;
|
||||
|
||||
constructor( GLuint shaderType ) {
|
||||
|
||||
this->glShader = glCreateShader( shaderType );
|
||||
|
||||
}
|
||||
|
||||
loadFromFile( char * shaderPath ) {
|
||||
|
||||
text * shaderSource = filesystem->readFile( shaderPath, "utf8" );
|
||||
|
||||
glShaderSource( this->glShader, 1, &shaderSource->value, NULL );
|
||||
|
||||
glCompileShader( this->glShader );
|
||||
|
||||
this->checkShaderForErrors( this->glShader );
|
||||
|
||||
}
|
||||
|
||||
checkShaderForErrors( GLuint shader ) {
|
||||
|
||||
GLint isCompiled = 0;
|
||||
|
||||
glGetShaderiv( shader, GL_COMPILE_STATUS, &isCompiled );
|
||||
|
||||
if( isCompiled == GL_FALSE )
|
||||
{
|
||||
GLint maxLength = 0;
|
||||
|
||||
glGetShaderiv( shader, GL_INFO_LOG_LENGTH, &maxLength );
|
||||
|
||||
GLchar errorMessage[ maxLength ];
|
||||
|
||||
glGetShaderInfoLog( shader, maxLength, &maxLength, errorMessage );
|
||||
|
||||
printf("\n\n\n\n Error: %s\n\n\n\n\n\n", errorMessage);
|
||||
|
||||
|
||||
glDeleteShader( shader );
|
||||
|
||||
exit( 0 );
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user