🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Why is my frambuffer binding the wrong texture? I'm super stuck/

Started by
1 comment, last by EBZ 3 years, 10 months ago

My Issue

I'm trying to create 2 framebuffers in order to ping pong between them and blur the image for post processing. The problem is that when I bind the texture when binding those framebuffers, I always get the first texture I loaded and bound since runtime. Not the scene color texture.

If I remove the portion where I'm binding the pingpong Framebuffers and pass the resolved Color buffer taken from the frame buffer that saves the scene instead: it works perfectly. So clearly I'm either:

a) Setting up the blur pingpong buffers wrong.
or b) I'm doing something wrong at the point I'm binding those pingpong frame buffers.
-------------------------------

Checking render doc, it's clear I'm getting the albedo map from the only model in my scene

This is how I'm creating the ping pong frame buffers:

glBindFramebuffer(GL_FRAMEBUFFER, 0);
glGenFramebuffers(2, buffer);
glGenTextures(2, resolvedColorBuffer);
for (unsigned int i = 0; i < 2; i += 1) {

        glBindFramebuffer(GL_FRAMEBUFFER, buffer[i]);
        glBindTexture(GL_TEXTURE_2D, resolvedColorBuffer[i]);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, frameWidth, frameHeight, 0, GL_RGBA, GL_FLOAT, NULL);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // we clamp to the edge as the blur filter would otherwise sample repeated texture values!
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, resolvedColorBuffer[i], 0); 
	
	if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
		std::cout << "Framebuffer not complete!" << std::endl;
}
		

Unbind();

And this is how I'm trying to blur everything:

horizontal = true; 
first_iteration = true;
unsigned int amount = 1;
shader->Bind();

for (unsigned int i = 0; i < amount; i += 1) {
			
	fbo.Bind(horizontal);
	
	shader->UploadInt(horizontalLocation, horizontal);
	glBindTexture(GL_TEXTURE_2D, first_iteration ? colorTexture : fbo.GetColorTexture(!horizontal));
	
	model->DrawMeshes();

	horizontal = !horizontal;
	if (first_iteration) first_iteration = false;
}
		
model->UnbindMeshes();
shader->Unbind();
Framebuffer::Unbind();

I honestly don't know what I'm doing wrong, hope this makes sense :(

Advertisement

Update: Nevermind guys, I re-wrote everything and I was missing a glActiveTexture(GL_TEXTURE0);

This topic is closed to new replies.

Advertisement