FBO troubles.

I need some help with FBOs, I am trying them for the first time, and I get the swing of it but I am not succeeding in programming a class for it.

Currently this is with my FBO class:

As you can see it removes everything rendered before it, and does not render the things bound to it.

I am applying what I made this way:

public LightManager(World world) {
		try {
			fboLight = new FBO();
			logo = TextureManager.loadTexture("/revereor/logo/logo");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@Override
	public void render() {
		Point pt = GDisplay.getCamera().getFOV();
		fboLight.bind();
		glPushMatrix();
		{
			glTranslated(Game.getGame().player.x, Game.getGame().player.y, 0);
			logo.bind();
			glBegin(GL_QUADS);
			{
				glTexCoord2f(0, 0);
				glVertex2d(-(50 / 2), 50 / 2);
				glTexCoord2f(1, 0);
				glVertex2d((50 / 2), 50 / 2);
				glTexCoord2f(1, 1);
				glVertex2d((50 / 2), -50 / 2);
				glTexCoord2f(0, 1);
				glVertex2d(-(50 / 2), -50 / 2);

			}
			glEnd();
		}
		glPopMatrix();
		fboLight.release();
		fboLight.render();
	}

and I have this:

package com.revereor.game.render;

import static org.lwjgl.opengl.EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT;
import static org.lwjgl.opengl.EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT;
import static org.lwjgl.opengl.EXTFramebufferObject.GL_FRAMEBUFFER_EXT;
import static org.lwjgl.opengl.EXTFramebufferObject.GL_RENDERBUFFER_EXT;
import static org.lwjgl.opengl.EXTFramebufferObject.glBindFramebufferEXT;
import static org.lwjgl.opengl.EXTFramebufferObject.glBindRenderbufferEXT;
import static org.lwjgl.opengl.EXTFramebufferObject.glFramebufferRenderbufferEXT;
import static org.lwjgl.opengl.EXTFramebufferObject.glFramebufferTexture2DEXT;
import static org.lwjgl.opengl.EXTFramebufferObject.glGenFramebuffersEXT;
import static org.lwjgl.opengl.EXTFramebufferObject.glGenRenderbuffersEXT;
import static org.lwjgl.opengl.EXTFramebufferObject.glRenderbufferStorageEXT;
import static org.lwjgl.opengl.GL11.*;

import java.awt.Point;

import org.lwjgl.opengl.EXTFramebufferObject;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL14;
import org.lwjgl.opengl.GLContext;

import com.revereor.game.display.GDisplay;
import com.revereor.game.main.log.Logger;

public class FBO {
	
	private int framebufferID, colorTextureID, depthRenderBufferID;

	public FBO(){
		init();
	}
	
	private void init(){
		boolean FBOEnabled = GLContext.getCapabilities().GL_EXT_framebuffer_object;
		if(!FBOEnabled)
			Logger.printerr("Frame Buffer Objects not supported, this WILL cause problems.");
		
		framebufferID = glGenFramebuffersEXT();											
		colorTextureID = glGenTextures();												
		depthRenderBufferID = glGenRenderbuffersEXT();									

		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebufferID); 						

		// initialize color texture
		glBindTexture(GL_TEXTURE_2D, colorTextureID);									
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);				
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 512, 512, 0,GL_RGBA, GL_INT, (java.nio.ByteBuffer) null);	
		glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_COLOR_ATTACHMENT0_EXT,GL_TEXTURE_2D, colorTextureID, 0); 


		// initialize depth renderbuffer
		glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthRenderBufferID);				
		glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL14.GL_DEPTH_COMPONENT24, 512, 512);	
		glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,GL_DEPTH_ATTACHMENT_EXT,GL_RENDERBUFFER_EXT, depthRenderBufferID); 

		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);	
	}
	
	public void bind(){
		glViewport (0, 0, GDisplay.getCamera().getFovX(), GDisplay.getCamera().getFovY());  
		glBindTexture(GL_TEXTURE_2D, 0);                            
		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebufferID);
		glClearColor (0.0f, 0.0f, 0.0f, 1.0f);
		glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);   
		glTranslatef (0.0f, 0.0f, -6);
		
	}
	
	public void release(){
		glEnable(GL_TEXTURE_2D); 
		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);  
	}
	
	public void render(){
		glEnable(GL_TEXTURE_2D);
		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);     

		glLoadIdentity ();                                             
		glTranslatef (0.0f, 0.0f, -6);     
		glColor3f(1, 1, 1);
									
		GL11.glPushMatrix();

		   glEnable(GL_TEXTURE_2D);
		      
		   glBindTexture(GL_TEXTURE_2D, colorTextureID); 
		   glBegin(GL_QUADS);
		   glTexCoord2f(0.0f, 0.0f); glVertex2i(0,   0);  
		   glTexCoord2f(1.0f, 0.0f); glVertex2i(GDisplay.camera.getFovX(),  0); 
		   glTexCoord2f(1.0f, 1.0f); glVertex2i(GDisplay.camera.getFovX(), GDisplay.camera.getFovY()); 
		   glTexCoord2f(0.0f, 1.0f); glVertex2i(0, GDisplay.camera.getFovY());
		   glEnd();
		      
		   glPopMatrix();

		
	}
	
	
	
}

Anyone have some experience, tips, or directions to go with this?

Im doing this with LibGdx so Im not much into the way you do it.

But what I see is that you are not clearing the “default” screen to draw on it, you only glClear when drawing to the FBO.

Sorry for not being very usefull :clue:

Other thing is, I understand that “glTranslatef (0.0f, 0.0f, -6);” moves the “camera” so if it is 2D with Z = -6 you may be drawing stuff behind your camera.

This is OpenGL coordinate system.

http://www.matrix44.net/cms/wp-content/uploads/2011/03/ogl_coord_3d_cart1.png

from: http://www.matrix44.net/cms/notes/opengl-3d-graphics/coordinate-systems-in-opengl

from: http://www.falloutsoftware.com/tutorials/gl/gl0.htm

Point me if Im wrong
(for sure I am).