diff --git a/includes/utils.h b/includes/utils.h index 320fab0..f31efee 100644 --- a/includes/utils.h +++ b/includes/utils.h @@ -36,4 +36,7 @@ void loadImg(const char *filename, const GLuint texture); // Copy a texture void copyTexture(const GLuint, const GLuint); +// Get the current FBO ID +GLuint getCurrentFramebufferID(void); + #endif diff --git a/src/animations.c b/src/animations.c index b27776f..7c3cbe0 100644 --- a/src/animations.c +++ b/src/animations.c @@ -76,6 +76,7 @@ static void transition_draw(void (*a0)(int), void (*a1)(int), Uint32 t, glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, (GLint *)&_transition_tId); + GLint currentFramebufferID = getCurrentFramebufferID(); glBindFramebuffer(GL_FRAMEBUFFER, _transition_fbo[0]); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, @@ -91,7 +92,7 @@ static void transition_draw(void (*a0)(int), void (*a1)(int), Uint32 t, a1(state); } - glBindFramebuffer(GL_FRAMEBUFFER, 0); + glBindFramebuffer(GL_FRAMEBUFFER, currentFramebufferID); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _transition_tId, 0); diff --git a/src/manif.c b/src/manif.c index 2b2287e..539bffb 100644 --- a/src/manif.c +++ b/src/manif.c @@ -92,6 +92,8 @@ static void draw(void) { gl4duLookAtf(9, 6, 0, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); glCullFace(GL_FRONT); + GLint currentFramebufferID = getCurrentFramebufferID(); + glBindFramebuffer(GL_FRAMEBUFFER, _fbo); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, _shadow_map_tex, 0); @@ -100,7 +102,7 @@ static void draw(void) { for (int i = 0; i < HEROS_NUMBER; ++i) { drawManifestant(matrix_model, &_herosId[i], deplacement, GL_TRUE); } - glBindFramebuffer(GL_FRAMEBUFFER, 0); + glBindFramebuffer(GL_FRAMEBUFFER, currentFramebufferID); glCullFace(GL_BACK); glDrawBuffer(GL_COLOR_ATTACHMENT0); diff --git a/src/utils.c b/src/utils.c index 58c3245..f8535fe 100644 --- a/src/utils.c +++ b/src/utils.c @@ -88,3 +88,10 @@ void copyTexture(const GLuint src, const GLuint dst) { SDL_FreeSurface(s); glBindTexture(GL_TEXTURE_2D, 0); } + +GLuint getCurrentFramebufferID(void) { + GLint currentFramebufferID = 0; + glGetIntegerv(GL_FRAMEBUFFER_BINDING, ¤tFramebufferID); + + return currentFramebufferID; +}