SHARE
TWEET

Untitled

a guest Dec 21st, 2014 146 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public void initFramebuffers() {
  2.         // Depth buffer
  3.         glBindFramebuffer(GL_FRAMEBUFFER, depthShader.fbo);
  4.         depthShader.initTexture(width, height, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT);
  5.         glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthShader.tex, 0);
  6.         glDrawBuffer(GL_NONE);
  7.         glReadBuffer(GL_NONE);
  8. }
  9.  
  10. //INSIDE DEPTHSHADER CONTAINER CLASS
  11. public void initTexture(int width, int height, int format, int internalFormat) {
  12.         tex = glGenTextures();
  13.         glBindTexture(GL_TEXTURE_2D, tex);
  14.         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  15.         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  16.         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  17.         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  18.         glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height, 0, format, GL_FLOAT, (ByteBuffer)null);
  19. }
  20.  
  21. //INSIDE BLURDEPTH CONTAINER CLASS
  22. public void blurDepthVAO() {           
  23.         float[] vertices = new float[] {
  24.                         -1.0f, 1.0f,
  25.                         -1.0f, -1.0f,
  26.                         1.0f, 1.0f,
  27.                         1.0f, -1.0f
  28.                 };
  29.                
  30.         FloatBuffer verts = BufferUtils.createFloatBuffer(vertices.length);
  31.         verts.put(vertices);
  32.         verts.flip();
  33.                
  34.         vao = glGenVertexArrays();
  35.         glBindVertexArray(vao);
  36.                
  37.         int vbo = glGenBuffers();
  38.         glBindBuffer(GL_ARRAY_BUFFER, vbo);
  39.         glBufferData(GL_ARRAY_BUFFER, verts, GL_STATIC_DRAW);
  40.                
  41.         glVertexAttribPointer(position, 2, GL_FLOAT, false, 0, 0);
  42.         glEnableVertexAttribArray(position);
  43.                
  44.         glBindBuffer(GL_ARRAY_BUFFER, 0);
  45. }
  46.  
  47. //INSIDE RUN METHOD
  48. //--------------------Particle Depth-----------------------
  49. {
  50.         glUseProgram(depthShader.program);
  51.         glBindFramebuffer(GL_FRAMEBUFFER, depthShader.fbo);
  52.  
  53.         depthShader.particleDepthVAO(points);
  54.                
  55.         RenderUtility.addMatrix(depthShader, mView, "mView");
  56.         RenderUtility.addMatrix(depthShader, projection, "projection");
  57.         RenderUtility.addVector2(depthShader, screenSize, "screenSize");
  58.         RenderUtility.addVector3(depthShader, lightPosition, "lightPos");
  59.                                
  60.         glDisable(GL_BLEND);
  61.         glEnable(GL_DEPTH_TEST);
  62.         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  63.  
  64.         // Draw VAO
  65.         glBindVertexArray(depthShader.vao);
  66.  
  67.         glDrawArrays(GL_POINTS, 0, points.size());
  68. }
  69.  
  70. //--------------------Particle Blur-----------------------
  71. {
  72.         glUseProgram(blurShader.program);
  73.         glBindFramebuffer(GL_FRAMEBUFFER, 0);
  74.                                
  75.         blurShader.blurDepthVAO();
  76.                                
  77.         glActiveTexture(GL_TEXTURE0);
  78.         glBindTexture(GL_TEXTURE_2D, depthShader.tex);
  79.         glUniform1i(blurShader.depthMap, 0);
  80.                                
  81.         RenderUtility.addMatrix(blurShader, mView, "mView");
  82.         RenderUtility.addMatrix(blurShader, projection, "projection");
  83.         RenderUtility.addVector2(blurShader, screenSize, "screenSize");
  84.                                
  85.         glEnable(GL_DEPTH_TEST);
  86.                                
  87.         glBindVertexArray(blurShader.vao);
  88.                                
  89.         glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
  90.         glViewport(0, 0, width, height);
  91. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top