Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: FBO Texture is black

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2016
    Posts
    8

    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.

    (JavaCode)
    Code :
     
                    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_MAG_FILTER, GL11.GL_LINEAR);
    	         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);
     
    		GL20.glDrawBuffers(GL30.GL_COLOR_ATTACHMENT0);
     
    		GuiTexture text = new GuiTexture(tex, new Vector2f(), new Vector2f(1,1));
    		GuiSystem.addGuiElement(text);
     
    		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.
    Code :
    GuiTexture text = new GuiTexture(tex, new Vector2f(), new Vector2f(1,1));
    GuiSystem.addGuiElement(text);


    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:

    Code :
     
    L11.glViewport(0,0,1024,768);
    		GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, buffer);
    		TerrainSystem.render(lights,c);
    		EntitySystem.render(lights, c);	
    		EntityNormalSystem.render(lights,c);
    		InstancedEntitySystem.render(lights, c);
    		GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
    		GL11.glViewport(0,0,1920,1080);
    		GuiSystem.render();

    If i remove the
    Code :
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, buffer);
    and
    Code :
    GuiSystem.render();
    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
    Greetings, Finn

  2. #2
    Member Regular Contributor
    Join Date
    May 2016
    Posts
    419
    are you actually copying the rendered image into the default framebuffer ?
    https://www.opengl.org/wiki/Framebuffer#Blitting

    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
    Last edited by john_connor; 09-23-2016 at 01:55 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •