Guest User

Untitled

a guest
Jan 22nd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. NSError *error;
  2. NSString *vertPath = [[NSBundle mainBundle] pathForResource:@"Simple" ofType:@"vert"];
  3. NSString *vertShaderString = [NSString stringWithContentsOfFile:vertPath encoding:NSUTF8StringEncoding error:&error];
  4. const GLchar *vertShaderText = [vertShaderString UTF8String];
  5.  
  6. if (!vertShaderString) {
  7. NSLog(@"%@", [error localizedDescription]);
  8. }
  9.  
  10. vertShader = glCreateShader(GL_VERTEX_SHADER);
  11. glShaderSource(vertShader, 1, &vertShaderText, NULL);
  12.  
  13. glCompileShader(vertShader);
  14. glGetShaderiv(vertShader, GL_COMPILE_STATUS, &vertCompiled);
  15. if (!vertCompiled) {
  16.  
  17. NSLog(@"Vert shader not compiled.");
  18. }
  19.  
  20. glAttachShader(prog, vertShader);
  21.  
  22. GLfloat vertices[] = { 0.0, 0.0, 0.0, 0.5, 0.5, 0.5 };
  23. GLubyte indices[3] = { 0, 1, 2 };
  24.  
  25. // Position vertex attribute data
  26. glEnableVertexAttribArray(0);
  27. glBindAttribLocation(prog, 0, "a_position");
  28. glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, vertices);
  29.  
  30.  
  31. // Color vertex attribute data
  32. GLfloat vColors[] = {
  33. 1.0, 0.0, 0.0, 1.0,
  34. 0.0, 1.0, 0.0, 1.0,
  35. 0.0, 0.0, 1.0, 1.0 };
  36.  
  37. glEnableVertexAttribArray(1);
  38. glBindAttribLocation(prog, 1, "a_color");
  39. glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, vColors);
  40.  
  41.  
  42. glDrawElements(GL_TRIANGLES, sizeof(indices)/sizeof(GLubyte), GL_UNSIGNED_BYTE, indices);
  43.  
  44. attribute vec4 a_position;
  45. attribute vec4 a_color;
  46.  
  47. varying vec4 varColor;
  48.  
  49. void main() {
  50.  
  51. gl_Position = a_position;
  52. varColor = a_color;
  53. }
Add Comment
Please, Sign In to add comment