When I draw to the texture for my FBO, it won’t show textures behind the top texture. I read that GL_DEPTH_TEST is related to this. I tried that, but then I only was drawing the clear bit. I’ve actually already done a lot of research on this, and I’m still not finding the answer.
FBO setup:
public void createMiniMap()
{
final int WIDTH = 1600;
final int HEIGHT = 900;
//frame buffer
int fbo;
int depthbuffer;
//frame buffer
fbo = glGenFramebuffersEXT();
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
//depth buffer
depthbuffer = glGenRenderbuffersEXT();
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthbuffer);
//allocate space for the renderbuffer
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, WIDTH, HEIGHT);
//attach depth buffer to fbo
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthbuffer);
//create texture to render to
miniMapTexture = glGenTextures();
glBindTexture(GL_TEXTURE_2D, miniMapTexture);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, WIDTH, HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, (java.nio.ByteBuffer)null);
//attach texture to the fbo
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, miniMapTexture, 0);
//check completeness
if(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) == GL_FRAMEBUFFER_COMPLETE_EXT){
System.out.println("Frame buffer created sucessfully.");
}
else
System.out.println("An error occured creating the frame buffer.");
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
drawMM();
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
}
draw call:
public void drawMM()
{
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
<a bunch of draw calls not likely the issue>
}
This same drawCall in regular drawing works just fine. Blending is happy. On the FBO it will only ever draw the top texture. Can anyone help?
Other resources I found interesting FWIW:
Fixing saturation with additive blending by faking HDR
glBlendFunc
FBO and Blending