Main Menu

FBO issue

Started by AndyGFX, November 05, 2010, 20:51:54

Previous topic - Next topic

AndyGFX

Hi, i work last few weeks on my jFinal3D graphics engine, and now i have strange problem. When i render scene to FBO, scene looks like on image



but without FBO looks OK. Where is a problem?




kappa

looks like your not setting your z-depth buffer properly or something.

AndyGFX

OK. now i have added DEPTH component to FBO, but result is black :(

...
EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, this.FBO_id);
EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, this.width, this.height);
EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 0);
	    
EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, this.texture_id, 0);
EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT, this.FBO_id);
...

Matzon

You should consider static imports :)

spasi

Your code above is wrong, it's missing a renderbuffer object. It should be like this:

this.RB_id = glGenRenderbuffersEXT();
...
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, this.RB_id);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, this.width, this.height);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
	    
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, this.texture_id, 0);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, this.RB_id);
...

AndyGFX

thx spasi, i found it a few hours ago. Here is working part of my FBO class:

....

public TF3D_FrameBufferObject2(String _name,int w, int h)
	{
		this.name = _name;
		this.width = w;
		this.height = h;
		
		// Set up the FBO and the Texture
		buffer = ByteBuffer.allocateDirect(1 * 4).order(ByteOrder.nativeOrder()).asIntBuffer(); 
		glGenFramebuffers(buffer); // generate
		this.FBO_id = buffer.get();
		
		// RENDER BUFFER
		
		buffer = BufferUtils.createIntBuffer(1); 
		glGenRenderbuffers(buffer);
		this.RBO_id = buffer.get();
		
	    glEnable(GL_TEXTURE_2D);
	    
	    // Create shared texture
	    IntBuffer texture_buffer = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
	    glGenTextures(texture_buffer);
	    this.texture_id = texture_buffer.get(0);
	    
	    glBindTexture(GL_TEXTURE_2D, this.texture_id);
	    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, BufferUtils.createIntBuffer(width * height * 4));

	    //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
	    //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
	    
	    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	    glBindFramebuffer(GL_FRAMEBUFFER, this.FBO_id);
	    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, this.texture_id, 0);
	    
	    
	    // attach renderbufferto framebufferdepth buffer
	    glBindRenderbuffer(GL_RENDERBUFFER, this.RBO_id);
	    glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT24, this.width, this.height);
	    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, this.RBO_id);
	    
	    
	    // CLOSE TETXURE and BUFFER
	    glBindFramebuffer(GL_FRAMEBUFFER, 0);	    
		glBindTexture(GL_TEXTURE_2D, 0);
	    
	}

	public int GetTexture()
	{
		return this.texture_id;
	}
	
	public void BeginRender()
	{
		
		
		glBindFramebuffer( GL_FRAMEBUFFER, this.FBO_id );
		
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		  
		glPushAttrib(GL_VIEWPORT_BIT);
		glViewport(0,0,this.width, this.height);
		
		
	}

	public void EndRender()
	{
		glPopAttrib();
		glBindFramebuffer( GL_FRAMEBUFFER, 0);
	}

...