public void initRenderTargets(int[] attachments) {
        if (attachments == null)
            return;

        int[] drawBuffers = new int[id.length];
        boolean hasDepth = false;

        for (int i = 0; i < id.length; i++) {
            if (attachments[i] == GL_DEPTH_ATTACHMENT) {
                drawBuffers[i] = GL_NONE;
                hasDepth = true;
            } else
                drawBuffers[i] = attachments[i];

            if (attachments[i] == GL_NONE)
                continue;

            if (frameBuffer == 0) {
                frameBuffer = glGenFramebuffers();
                glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBuffer);
            }

            glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, attachments[i], textureTarget, id[i], 0);
        }
        if (frameBuffer == 0) {
            return;
        }
        if (!hasDepth) {
            renderBuffer = glGenRenderbuffers();
            glBindRenderbuffer(GL_RENDERBUFFER, renderBuffer);
            glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height);
            glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_FRAMEBUFFER, renderBuffer);
        }

        glDrawBuffers(Util.createIntBuffer(drawBuffers.length).put(drawBuffers));

        if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
            Util.err("Framebuffer creation failed!");
            System.exit(-1);
        }

        glBindFramebuffer(GL_FRAMEBUFFER, 0);
    }