Drawing multiple textures on a fbo texture

Started by
0 comments, last by ak09 10 years, 11 months ago

Imagine 3 different balls, each one stored on three different textures. There is no background, so I can draw and overlay (on the front buffer) all of them.
The problem is: how can I make this draw on a fourth texture, keeping the NO background?

I'm dealing with multiple layers and want to save all of them in a single png file. Saving what's in the GL_COLOR_ATTACHMENT0 buffer won't work great, because it'll only save what's being seen. Instead, there is a need of saving huge images, which can't be seen (in it's original scale) at one time.


    Layer fourthLayer(0, 0, w, h, 1.0f); // creates a Layer object, which contains a fbo and a texture
    glBindFramebuffer(GL_FRAMEBUFFER, fourthLayer.fbo); // selects the fourth layer's fbo
    render(layers, n);                                 // draw all the three textures
    glBindFramebuffer(GL_FRAMEBUFFER, 0);

    std::vector<unsigned char> pixels(4 * w * h);
    glBindTexture(GL_TEXTURE_2D, fourthLayer.texId); // selects the fourth layer's texture, so I can read it's bytes
    glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0]); 
    glBindTexture(GL_TEXTURE_2D, 0);

    lodepng::encode(filename.append(".png").data(), pixels, w, h); // save
 

Advertisement

My bad. I was missing to glEnable(GL_BLEND) before those draws.

This topic is closed to new replies.

Advertisement