Advertisement
Guest User

Untitled

a guest
Jul 7th, 2014
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.39 KB | None | 0 0
  1.     private void initFramebuffer(){
  2.         int fb = 0;
  3.         gl.glGenFramebuffers(1, ID_BUFFER);
  4.         fb = ID_BUFFER.get(0);
  5.         gl.glBindFramebuffer(GL_FRAMEBUFFER, fb);
  6.        
  7.         // The texture we're going to render to
  8.         int renderedTexture;
  9.         gl.glGenTextures(1, ID_BUFFER);
  10.         renderedTexture = ID_BUFFER.get(0);
  11.          
  12.         // "Bind" the newly created texture : all future texture functions will modify this texture
  13.         gl.glBindTexture(GL_TEXTURE_2D, renderedTexture);
  14.          
  15.         // Give an empty image to OpenGL ( the last "0" )
  16.         gl.glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, null);
  17.          
  18.         // Poor filtering. Needed !
  19.         gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  20.         gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  21.        
  22.         // The depth buffer
  23. //      int depthrenderbuffer;
  24. //      gl.glGenRenderbuffers(1, ID_BUFFER);
  25. //      depthrenderbuffer = ID_BUFFER.get(0);
  26. //      gl.glBindRenderbuffer(GL_RENDERBUFFER, depthrenderbuffer);
  27. //      gl.glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32, 512, 512);
  28. //      gl.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthrenderbuffer);
  29.        
  30.         // Set "renderedTexture" as our colour attachement #0
  31.         gl.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, renderedTexture, 0);
  32.          
  33.         // Set the list of draw buffers.
  34.         IntBuffer db = IntBuffer.allocate(1);
  35.         db.put(GL_COLOR_ATTACHMENT0);
  36.         gl.glDrawBuffers(1, db); // "1" is the size of DrawBuffers
  37.        
  38.         if(gl.glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
  39.             return;
  40.        
  41.         gl.glBindTexture(GL_TEXTURE_2D, 0);
  42.         gl.glBindFramebuffer(GL_FRAMEBUFFER, 0);
  43.        
  44.         this.frameBuffer = fb;
  45.         this.renderedTexture = renderedTexture;
  46.     }
  47.    
  48.     public void display(GLAutoDrawable drawable) {
  49.         this.gl = drawable.getGL().getGL4();
  50.         this.gl.glBindTexture(GL_TEXTURE_2D, 0);
  51.         this.gl.glBindFramebuffer(GL_FRAMEBUFFER, this.frameBuffer);
  52.         this.gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  53.        
  54.         callback.render(this); // Render Stuff, with the FrameBuffer bound (for tests I render to the left half of the screen)
  55.        
  56.         this.gl.glBindFramebuffer(GL_FRAMEBUFFER, 0);
  57.        
  58.         this.gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  59.  
  60.         callback.render(this); //Render Stuff again, this time onscreen on the left half
  61.         [...] // Render rendererdTexture to the right half of the screen
  62.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement