-
-
Save jonasbark/561e7e66671b041f0107 to your computer and use it in GitHub Desktop.
It breaks on line 61
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (BOOL)loadShaders | |
{ | |
GLuint vertShader, fragShader; | |
NSString *vertShaderPathname, *fragShaderPathname; | |
// Create shader program. | |
program = glCreateProgram(); | |
// Create and compile vertex shader. | |
vertShaderPathname = [[NSBundle mainBundle] pathForResource:@"Shader" ofType:@"vsh"]; | |
if (![self compileShader:&vertShader type:GL_VERTEX_SHADER file:vertShaderPathname]) | |
{ | |
NSLog(@"Failed to compile vertex shader"); | |
return FALSE; | |
} | |
// Create and compile fragment shader. | |
fragShaderPathname = [[NSBundle mainBundle] pathForResource:@"Shader" ofType:@"fsh"]; | |
if (![self compileShader:&fragShader type:GL_FRAGMENT_SHADER file:fragShaderPathname]) | |
{ | |
NSLog(@"Failed to compile fragment shader"); | |
return FALSE; | |
} | |
// Attach vertex shader to program. | |
glAttachShader(program, vertShader); | |
// Attach fragment shader to program. | |
glAttachShader(program, fragShader); | |
// Bind attribute locations. | |
// This needs to be done prior to linking. | |
glBindAttribLocation(program, ATTRIB_VERTEX, "position"); | |
glBindAttribLocation(program, ATTRIB_TEXTURE_COORD, "texture_coord"); | |
// Link program. | |
if (![self linkProgram:program]) | |
{ | |
NSLog(@"Failed to link program: %d", program); | |
if (vertShader) | |
{ | |
glDeleteShader(vertShader); | |
vertShader = 0; | |
} | |
if (fragShader) | |
{ | |
glDeleteShader(fragShader); | |
fragShader = 0; | |
} | |
if (program) | |
{ | |
glDeleteProgram(program); | |
program = 0; | |
} | |
return FALSE; | |
} | |
// Get uniform locations. | |
uniforms[UNIFORM_MVP_MATRIX] = glGetUniformLocation(program, "mvp_matrix"); | |
uniforms[UNIFORM_TEXTURE] = glGetUniformLocation(program, "texture"); | |
// Release vertex and fragment shaders. | |
if (vertShader) | |
glDeleteShader(vertShader); | |
if (fragShader) | |
glDeleteShader(fragShader); | |
return TRUE; | |
} | |
- (BOOL)compileShader:(GLuint *)shader type:(GLenum)type file:(NSString *)file | |
{ | |
GLint status; | |
const GLchar *source; | |
source = (GLchar *)[[NSString stringWithContentsOfFile:file encoding:NSUTF8StringEncoding error:nil] UTF8String]; | |
if (!source) | |
{ | |
NSLog(@"Failed to load vertex shader"); | |
return FALSE; | |
} | |
*shader = glCreateShader(type); | |
glShaderSource(*shader, 1, &source, NULL); | |
glCompileShader(*shader); | |
glGetShaderiv(*shader, GL_COMPILE_STATUS, &status); | |
if (status == 0) | |
{ | |
glDeleteShader(*shader); | |
return FALSE; | |
} | |
return TRUE; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
varying highp vec2 texCoordVarying; | |
uniform sampler2D texture; | |
void main() | |
{ | |
gl_FragColor = texture2D(texture, texCoordVarying); | |
gl_FragColor.a = 0.85; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
attribute vec4 position; | |
attribute vec4 texture_coord; | |
varying vec2 texCoordVarying; | |
uniform mat4 mvp_matrix; | |
void main() | |
{ | |
gl_Position = mvp_matrix * position; | |
texCoordVarying = texture_coord.st; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment