Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void initFramebuffer(){
- int fb = 0;
- gl.glGenFramebuffers(1, ID_BUFFER);
- fb = ID_BUFFER.get(0);
- gl.glBindFramebuffer(GL_FRAMEBUFFER, fb);
- // The texture we're going to render to
- int renderedTexture;
- gl.glGenTextures(1, ID_BUFFER);
- renderedTexture = ID_BUFFER.get(0);
- // "Bind" the newly created texture : all future texture functions will modify this texture
- gl.glBindTexture(GL_TEXTURE_2D, renderedTexture);
- // Give an empty image to OpenGL ( the last "0" )
- gl.glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, null);
- // Poor filtering. Needed !
- gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- // The depth buffer
- // int depthrenderbuffer;
- // gl.glGenRenderbuffers(1, ID_BUFFER);
- // depthrenderbuffer = ID_BUFFER.get(0);
- // gl.glBindRenderbuffer(GL_RENDERBUFFER, depthrenderbuffer);
- // gl.glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32, 512, 512);
- // gl.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthrenderbuffer);
- // Set "renderedTexture" as our colour attachement #0
- gl.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, renderedTexture, 0);
- // Set the list of draw buffers.
- IntBuffer db = IntBuffer.allocate(1);
- db.put(GL_COLOR_ATTACHMENT0);
- gl.glDrawBuffers(1, db); // "1" is the size of DrawBuffers
- if(gl.glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
- return;
- gl.glBindTexture(GL_TEXTURE_2D, 0);
- gl.glBindFramebuffer(GL_FRAMEBUFFER, 0);
- this.frameBuffer = fb;
- this.renderedTexture = renderedTexture;
- }
- public void display(GLAutoDrawable drawable) {
- this.gl = drawable.getGL().getGL4();
- this.gl.glBindTexture(GL_TEXTURE_2D, 0);
- this.gl.glBindFramebuffer(GL_FRAMEBUFFER, this.frameBuffer);
- this.gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- callback.render(this); // Render Stuff, with the FrameBuffer bound (for tests I render to the left half of the screen)
- this.gl.glBindFramebuffer(GL_FRAMEBUFFER, 0);
- this.gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- callback.render(this); //Render Stuff again, this time onscreen on the left half
- [...] // Render rendererdTexture to the right half of the screen
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement