Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NSError *error;
- NSString *vertPath = [[NSBundle mainBundle] pathForResource:@"Simple" ofType:@"vert"];
- NSString *vertShaderString = [NSString stringWithContentsOfFile:vertPath encoding:NSUTF8StringEncoding error:&error];
- const GLchar *vertShaderText = [vertShaderString UTF8String];
- if (!vertShaderString) {
- NSLog(@"%@", [error localizedDescription]);
- }
- vertShader = glCreateShader(GL_VERTEX_SHADER);
- glShaderSource(vertShader, 1, &vertShaderText, NULL);
- glCompileShader(vertShader);
- glGetShaderiv(vertShader, GL_COMPILE_STATUS, &vertCompiled);
- if (!vertCompiled) {
- NSLog(@"Vert shader not compiled.");
- }
- glAttachShader(prog, vertShader);
- GLfloat vertices[] = { 0.0, 0.0, 0.0, 0.5, 0.5, 0.5 };
- GLubyte indices[3] = { 0, 1, 2 };
- // Position vertex attribute data
- glEnableVertexAttribArray(0);
- glBindAttribLocation(prog, 0, "a_position");
- glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, vertices);
- // Color vertex attribute data
- GLfloat vColors[] = {
- 1.0, 0.0, 0.0, 1.0,
- 0.0, 1.0, 0.0, 1.0,
- 0.0, 0.0, 1.0, 1.0 };
- glEnableVertexAttribArray(1);
- glBindAttribLocation(prog, 1, "a_color");
- glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, vColors);
- glDrawElements(GL_TRIANGLES, sizeof(indices)/sizeof(GLubyte), GL_UNSIGNED_BYTE, indices);
- attribute vec4 a_position;
- attribute vec4 a_color;
- varying vec4 varColor;
- void main() {
- gl_Position = a_position;
- varColor = a_color;
- }
Add Comment
Please, Sign In to add comment