FBO Texture is black

Dear forum,

I am trying to implement Shadowmapping into my program. I just tried to implement and rendering to FBO’s at all but it does not work. I’ve read some tutorials and i copied their code
for generating FBOs. The Texture will eventually be rendered on to a Quad. Below is the Code i am currently working with.


                buffer = GL30.glGenFramebuffers();
		GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, buffer);
		int tex = GL11.glGenTextures();
		GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex);
		GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, 1024,768, 0, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, (ByteBuffer) null);
	         GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
		int depthBuffer = GL30.glGenRenderbuffers();
		GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, depthBuffer);
		GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL11.GL_DEPTH_COMPONENT, 1024,768);
		GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL30.GL_RENDERBUFFER, depthBuffer);
		GL32.glFramebufferTexture(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, tex, 0);
		GuiTexture text = new GuiTexture(tex, new Vector2f(), new Vector2f(1,1));
		System.out.println((GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER) == GL30.GL_FRAMEBUFFER_COMPLETE));
		GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);

These 2 lines are for displaying the texture.

GuiTexture text = new GuiTexture(tex, new Vector2f(), new Vector2f(1,1));

I do not want to implement Shadowmapping directly. At first i want to be able to render my scene to a texture but this is not working.
My render call looks like this:

		GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, buffer);
		EntitySystem.render(lights, c);	
		InstancedEntitySystem.render(lights, c);
		GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);

If i remove the

GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, buffer);



it renders my scene the way it should be. But with it i only see black.

I would be very happy if someone could help me solve my problem :slight_smile:
Greetings, Finn

are you actually copying the rendered image into the default framebuffer ?

when you are finished with rendering into your FBO (framebuffer object), you’re not done:
you have to copy the data from your framebuffer into the window’s framebuffer (so-called “default framebuffer”)

you call:
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);// makes OpenGL drawing into “0”, which is the default framebuffer
glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer);// makes OpenGL reading data from your “framebuffer”
// from now on all draw operations affect the default framebuffer (screen) and all read operations will get the data from your “framebuffer” …

glReadBuffer(GL_COLOR_ATTACHMENT0);// tells openGL from which attachment you want to read the data
glBlitFramebuffer(// makes OpenGL copying the framebuffer data
0, 0, framebufferwidth, framebufferheight,
0, 0, screenwidth, screenheight,
GL_COLOR_BUFFER_BIT,// you only care about the color data, not the depth data …
GL_NEAREST);// filter parameter