-/* Global */
-GLuint fbo, fbo_texture, rbo_depth;
-//GLuint vbo_fbo_vertices;
-
-static void
-gl_offscreenInit(
- int screen_width,
- int screen_height)
-{
- /* init_resources */
- /* Create back-buffer, used for post-processing */
-
- /* Texture */
- GLCHECK(glActiveTexture(GL_TEXTURE0));
- glGenTextures(1, &fbo_texture);
- glBindTexture(GL_TEXTURE_2D, fbo_texture);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, screen_width, screen_height, 0,
- GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- glBindTexture(GL_TEXTURE_2D, 0);
-
- /* Depth buffer */
- GLCHECK(glGenRenderbuffers(1, &rbo_depth));
- glBindRenderbuffer(GL_RENDERBUFFER, rbo_depth);
- glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, screen_width,
- screen_height);
- glBindRenderbuffer(GL_RENDERBUFFER, 0);
-
- /* Framebuffer to link everything together */
- GLCHECK(glGenFramebuffers(1, &fbo));
- glBindFramebuffer(GL_FRAMEBUFFER, fbo);
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
- fbo_texture, 0);
- glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
- GL_RENDERBUFFER, rbo_depth);
-
- GLenum status;
- if ((status = glCheckFramebufferStatus(GL_FRAMEBUFFER))
- != GL_FRAMEBUFFER_COMPLETE) {
- fprintf(stderr, "glCheckFramebufferStatus: error %d", (int)status);
- return ;
- }
-#if 0
- // Set the list of draw buffers.
- GLenum DrawBuffers[2] = {GL_COLOR_ATTACHMENT0};
- glDrawBuffers(1, DrawBuffers); // "1" is the size of DrawBuffers
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
-#endif
-}
-
-void
-gl_offscreenReshape(
- int screen_width,
- int screen_height)
-{
-// Rescale FBO and RBO as well
- glBindTexture(GL_TEXTURE_2D, fbo_texture);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, screen_width, screen_height, 0,
- GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- glBindTexture(GL_TEXTURE_2D, 0);
-
- glBindRenderbuffer(GL_RENDERBUFFER, rbo_depth);
- glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, screen_width,
- screen_height);
- glBindRenderbuffer(GL_RENDERBUFFER, 0);
-}
-
-void gl_offscreenFree()
-{
- /* free_resources */
- glDeleteRenderbuffers(1, &rbo_depth);
- glDeleteTextures(1, &fbo_texture);
- glDeleteFramebuffers(1, &fbo);
-}