Advertisement
Guest User

Untitled

a guest
Dec 10th, 2012
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. GLuint texture = 0;
  2. glGenTextures(1, &texture);
  3. glBindTexture(GL_TEXTURE_2D, texture);
  4. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  5. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  6. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  7. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  8. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
  9.  
  10. glGenFramebuffers(1, &targetFBO);
  11. glBindFramebuffer(GL_FRAMEBUFFER, targetFBO);
  12. glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
  13.  
  14. - (void) draw {
  15. GLfloat textureCoordinates[] = {
  16. 0.0f, 0.0f,
  17. 1.0f, 0.0f,
  18. 0.0f, 1.0f,
  19. 1.0f, 1.0f,
  20. };
  21.  
  22. GLfloat imageVertices[] = {
  23. -1.0f, -1.0f,
  24. 1.0f, -1.0f,
  25. -1.0f, 1.0f,
  26. 1.0f, 1.0f,
  27. };
  28.  
  29. glViewport(0, 0, targetWidth, targetHeight);
  30. glBindFramebuffer(GL_FRAMEBUFFER, targetFBO);
  31. glUseProgram(program);
  32. glActiveTexture(GL_TEXTURE2);
  33. glBindTexture(GL_TEXTURE_2D, textureID);
  34. glUniform1i(inputTextureLocation, 2);
  35. glDisable(GL_BLEND);
  36.  
  37. glVertexAttribPointer(positionLocation, 2, GL_FLOAT, 0, 0, imageVertices);
  38. glVertexAttribPointer(inputTextureCoordinateLocation, 2, GL_FLOAT, 0, 0, textureCoordinates);
  39. // Clear the screen
  40. glClearColor(0.0, 0.0, 0.0, 0.0);
  41. glClear(GL_COLOR_BUFFER_BIT);
  42.  
  43. glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
  44. }
  45.  
  46. attribute vec4 position;
  47. attribute vec4 inputTextureCoordinate;
  48.  
  49. varying vec2 textureCoordinate;
  50.  
  51. void main()
  52. {
  53. gl_Position = position;
  54. textureCoordinate = inputTextureCoordinate.xy;
  55. }
  56.  
  57. varying highp vec2 textureCoordinate;
  58.  
  59. uniform sampler2D inputTexture;
  60.  
  61. void main()
  62. {
  63. gl_FragColor = texture2D(inputTexture, textureCoordinate);
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement