Jump to content
  • Advertisement
Sign in to follow this  

FBO only renders to the first target

This topic is 1246 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I'm trying to render to multiple targets using a frame buffer object, but as of now only the first target is being rendered to. If I render either of the other two buffers to the screen it's a white wash.


It does work for the first and as far as I can tell I'm not treating the other two targets any differently, so I'm having a bit of trouble deciphering where the root of this problem is. If anyone could point me in the right direction that would be great!


Oh and I'm using the fixed function pipeline as a placeholder to draw the texture since it was a quick solution.



public class DeferredRenderer {

    public static final int POSITION_BUFFER_BINDING = 0;
    public static final int NORMAL_BUFFER_BINDING = 1;
    public static final int DIFFUSE_BUFFER_BINDING = 2;
    public static final int SCREEN_BUFFER_BINDING = 3;

    private final Texture positionBuffer;
    private final Texture normalBuffer;
    private final Texture diffuseBuffer;

    private final Texture screenTexture;

    private final FBO fbo;
    private final RBO fboDepthBuffer;

    public DeferredRenderer(final int width, final int height) throws GraphicsException{


        positionBuffer = new Texture(width, height, POSITION_BUFFER_BINDING, OGLColorType.RGBA16F);
        normalBuffer = new Texture(width, height, NORMAL_BUFFER_BINDING, OGLColorType.RGBA16F);
        diffuseBuffer = new Texture(width, height, DIFFUSE_BUFFER_BINDING, OGLColorType.RGBA16F);

        screenTexture = new Texture(width, height, SCREEN_BUFFER_BINDING, OGLColorType.RGBA8);

        fbo = new FBO();
        fboDepthBuffer = new RBO(width, height, AttachmentType.DEPTH_ATTACHMENT);



        final IntBuffer buffer = BufferUtils.createIntBuffer(3);
        buffer.put(0, AttachmentType.COLOR_ATTACHMENT0.ID);
        buffer.put(1, AttachmentType.COLOR_ATTACHMENT1.ID);
        buffer.put(2, AttachmentType.COLOR_ATTACHMENT2.ID);

        // Creates an array of buffers that the fragment shader will output to

        if(!fbo.checkForErrors()) {
            throw new GraphicsException("Could not compile FBO");


    public void beginDrawing() {




    public void endDrawing() {



        GL11.glTexCoord2f(0.0f, 0.0f);
        GL11.glVertex3f(-1.0f, -1.0f, 0.0f); // The bottom left corner

        GL11.glTexCoord2f(0.0f, 1.0f);
        GL11.glVertex3f(-1.0f, 1.0f, 0.0f); // The top left corner

        GL11.glTexCoord2f(1.0f, 1.0f);
        GL11.glVertex3f(1.0f, 1.0f, 0.0f); // The top right corner

        GL11.glTexCoord2f(1.0f, 0.0f);
        GL11.glVertex3f(1.0f, -1.0f, 0.0f); // The bottom right corner



    public void destroy() {


Vertex shader:

#version 330 core
uniform mat4 u_projectionMatrix;
uniform mat4 u_viewMatrix;
uniform mat4 u_modelMatrix;

in vec4 in_Position;
in vec3 in_Normal;
in vec2 in_TextureCoord;

out vec4 pass_Position;
out vec4 pass_Normal;
out vec2 pass_TextureCoord;

void main(void) {

    mat4 mvp = u_projectionMatrix * u_viewMatrix * u_modelMatrix;

    pass_Position = mvp * in_Position;
    pass_Normal = vec4(normalize(mat3(mvp) * in_Normal), 1);

	pass_TextureCoord = in_TextureCoord;

	gl_Position = mvp * in_Position;

Fragment shader:


(I know I'm not passing the correct values, I just want to fix this problem and pass data through all the buffers before continuing on)

#version 330 core

uniform sampler2D texture_diffuse;

in vec4 pass_Position;
in vec4 pass_Normal;
in vec2 pass_TextureCoord;

void main(void) {

	vec4 texel = texture(texture_diffuse, pass_TextureCoord);

	gl_FragData[0] = texel;
	gl_FragData[1] = pass_Normal;
	gl_FragData[2] = texel;
Edited by GameGeezer

Share this post

Link to post
Share on other sites

Figured it out, In a tutorial I used the author treated the attachment Ids like they were relative: COLOR_ATTACHMENT1 = COLOR_ATTACHMENT0 + 1. They aren't relative to each other for some reason in lwjgl so I just had to change the Id's.

Edited by GameGeezer

Share this post

Link to post
Share on other sites

. They aren't relative to each other for some reason in lwjgl 
They do are from what I've used in LWJGL 2.9.2 and LWJGL 3. They take the values directly from OGL headers.


This is from LWJGL 3:

GL_COLOR_ATTACHMENT0        = 0x8CE0, // Thats 36064
GL_COLOR_ATTACHMENT1        = 0x8CE1, // 36065
GL_COLOR_ATTACHMENT2        = 0x8CE2, // 36066
... etc

Share this post

Link to post
Share on other sites

Oh I just assumed since incrementing from ATTACHMENT0 was the root of my error that they couldn't be. Must have been another small bug that accidently got tossed out along with that code.

Edited by GameGeezer

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!