Sign in to follow this  
BloodLust666

gl_FragData[0] not working

Recommended Posts

Ok I've been going crazy trying to figure out why my other buffers aren't being drawn to. They worked before but now they're not... My mistake I was making before was that I wasn't attaching a depth buffer so i was getting incorrect depth values because of no depth test. Now that I have a depth buffer as a surface, my attached textures aren't being written to, only my first one. I have 3 textures and 1 surface attached to my FBO, the first texture is being written to, but not the others, when I draw each to the screen, only the one that's written to gl_FragData[0] has anything. Once I comment out adding my depth buffer, the other textures have images on them, but incorrect depth values... am I missing something?

Share this post


Link to post
Share on other sites

glGenFramebuffersEXT(1, &m_frameID);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_frameID);

// this loops 3 times but for 3 different textures that I have an object for with different "m_id"s
glGenTextures(1, &m_id);
glBindTexture(GL_TEXTURE_2D, m_id);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
640, 480, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glGenerateMipmapEXT(GL_TEXTURE_2D);

// for each iteration of texture, I use GL_COLOR_ATTACHMENT0_EXT, then GL_COLOR_ATTACHMENT1_EXT, then GL_COLOR_ATTACHMENT2_EXT
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, m_id, 0);

// my depth surface
glGenRenderbuffersEXT(1, &m_bufferID);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_bufferID);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA, 640, 480);

glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
GL_RENDERBUFFER_EXT, m_bufferID);



// during rendering I simply just
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_frameID);
// then clear, and render my scene through the camera

Share this post


Link to post
Share on other sites
I think you are missing the glDrawBuffers call after binding the FBO. try something like:

GLenum buffers[] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2};

glDrawBuffers(3, buffers);

Share this post


Link to post
Share on other sites
oh yea, sorry I do have that at the end

glDrawBuffers( m_bufferList.size(), &m_bufferList[0]);
// m_bufferList has GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, and GL_DEPTH_ATTACHMENT.

Do I even need GL_DEPTH_ATTACHMENT in there since I'm not writing to it?

Share this post


Link to post
Share on other sites
GL_DEPTH_ATTACHMENT isn't a valid parameter to glDrawBuffers, and that's probably generating a GL error, and thus ignoring the glDrawBuffers call.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this