Could you please guide me as to how to use the two remembered textures?
Here is my code so far. It is nothing too fancy.
void draw_scene(GLuint fbo_handle)
{
glUseProgram(point_shader.get_program());
GLuint upside_down_white_mask_tex = 0;
GLuint upside_down_tex = 0;
GLuint reflectance_tex = 0;
GLuint regular_tex = 0;
GLuint glowmap_tex = 0;
GLuint d_tex = 0;
glGenTextures(1, &upside_down_white_mask_tex);
glBindTexture(GL_TEXTURE_2D, upside_down_white_mask_tex);
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA32F, win_x, win_y);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glGenTextures(1, &upside_down_tex);
glBindTexture(GL_TEXTURE_2D, upside_down_tex);
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA32F, win_x, win_y);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glGenTextures(1, &reflectance_tex);
glBindTexture(GL_TEXTURE_2D, reflectance_tex);
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA32F, win_x, win_y);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glGenTextures(1, ®ular_tex);
glBindTexture(GL_TEXTURE_2D, regular_tex);
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA32F, win_x, win_y);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glGenTextures(1, &d_tex);
glBindTexture(GL_TEXTURE_2D, d_tex);
glTexStorage2D(GL_TEXTURE_2D, 1, GL_DEPTH_COMPONENT32F, win_x, win_y);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glGenTextures(1, &glowmap_tex);
glBindTexture(GL_TEXTURE_2D, glowmap_tex);
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA32F, win_x, win_y);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
if (last_frame_glowmap_tex == 0)
{
glGenTextures(1, &last_frame_glowmap_tex);
glBindTexture(GL_TEXTURE_2D, last_frame_glowmap_tex);
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA32F, win_x, win_y);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
if (last_frame_glowmap_tex2 == 0)
{
glGenTextures(1, &last_frame_glowmap_tex2);
glBindTexture(GL_TEXTURE_2D, last_frame_glowmap_tex2);
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA32F, win_x, win_y);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
glReadBuffer(GL_COLOR_ATTACHMENT0);
// Upside down white mask
draw_stuff(offscreen_fbo, true, false, true, false);
glBindTexture(GL_TEXTURE_2D, upside_down_white_mask_tex);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, win_x, win_y);
//// Upside down
draw_stuff(offscreen_fbo, true, false, false, false);
glBindTexture(GL_TEXTURE_2D, upside_down_tex);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, win_x, win_y);
// Reflectance map
draw_stuff(offscreen_fbo, false, true, false, false);
glBindTexture(GL_TEXTURE_2D, reflectance_tex);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, win_x, win_y);
// Regular map
draw_stuff(offscreen_fbo, false, false, false, false);
glBindTexture(GL_TEXTURE_2D, regular_tex);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, win_x, win_y);
// Glow map
draw_stuff(offscreen_fbo, false, false, false, true);
glBindTexture(GL_TEXTURE_2D, glowmap_tex);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, win_x, win_y);
glReadBuffer(GL_DEPTH_ATTACHMENT);
glBindTexture(GL_TEXTURE_2D, d_tex);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, win_x, win_y);
// use the shader program
glUseProgram(tex_reflectance.get_program());
glUniform1i(glGetUniformLocation(tex_reflectance.get_program(), "img_width"), win_x);
glUniform1i(glGetUniformLocation(tex_reflectance.get_program(), "img_height"), win_y);
if (screenshot_mode)
glUniform1i(glGetUniformLocation(tex_reflectance.get_program(), "cam_factor"), cam_factor);
else
glUniform1i(glGetUniformLocation(tex_reflectance.get_program(), "cam_factor"), 1);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, upside_down_white_mask_tex);
glUniform1i(glGetUniformLocation(tex_reflectance.get_program(), "upside_down_white_mask_tex"), 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, upside_down_tex);
glUniform1i(glGetUniformLocation(tex_reflectance.get_program(), "upside_down_tex"), 1);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, reflectance_tex);
glUniform1i(glGetUniformLocation(tex_reflectance.get_program(), "reflectance_tex"), 2);
glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_2D, regular_tex);
glUniform1i(glGetUniformLocation(tex_reflectance.get_program(), "regular_tex"), 3);
glActiveTexture(GL_TEXTURE4);
glBindTexture(GL_TEXTURE_2D, glowmap_tex);
glUniform1i(glGetUniformLocation(tex_reflectance.get_program(), "glowmap_tex"), 4);
glActiveTexture(GL_TEXTURE5);
glBindTexture(GL_TEXTURE_2D, last_frame_glowmap_tex);
glUniform1i(glGetUniformLocation(tex_reflectance.get_program(), "last_frame_glowmap_tex"), 5);
glActiveTexture(GL_TEXTURE6);
glBindTexture(GL_TEXTURE_2D, last_frame_glowmap_tex2);
glUniform1i(glGetUniformLocation(tex_reflectance.get_program(), "last_frame_glowmap_tex2"), 6);
glActiveTexture(GL_TEXTURE7);
glBindTexture(GL_TEXTURE_2D, d_tex);
glUniform1i(glGetUniformLocation(tex_reflectance.get_program(), "depth_tex"), 7);
// vao and vbo handle
GLuint vao, vbo, ibo;
// https://raw.githubusercontent.com/progschj/OpenGL-Examples/master/03texture.cpp
// generate and bind the vao
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
// generate and bind the vertex buffer object
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
// http://www.songho.ca/opengl/gl_transform.html
// data for a fullscreen quad (this time with texture coords)
static const GLfloat vertexData[] = {
// X Y Z U V
1.0f, 1.0f, 0.0f, 1.0f, 1.0f, // vertex 0
-1.0f, 1.0f, 0.0f, 0.0f, 1.0f, // vertex 1
1.0f,-1.0f, 0.0f, 1.0f, 0.0f, // vertex 2
-1.0f,-1.0f, 0.0f, 0.0f, 0.0f, // vertex 3
}; // 4 vertices with 5 components (floats) each
// fill with data
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 4 * 5, vertexData, GL_DYNAMIC_DRAW);
// set up generic attrib pointers
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), NULL);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (char*)0 + 3 * sizeof(GLfloat));
// generate and bind the index buffer object
glGenBuffers(1, &ibo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
static const GLuint indexData[] = {
0,1,2, // first triangle
2,1,3, // second triangle
};
// fill with data
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint) * 2 * 3, indexData, GL_DYNAMIC_DRAW);
// "unbind" vao
glBindVertexArray(0);
// bind the vao
glBindVertexArray(vao);
// draw
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
glDeleteVertexArrays(1, &vao);
glDeleteBuffers(1, &vbo);
glDeleteBuffers(1, &ibo);
use_buffers(fbo_handle, d_tex, offscreen_colour_tex);
static int x = 0;
if (x % 2 == 0)
{
glCopyImageSubData(glowmap_tex, GL_TEXTURE_2D, 0, 0, 0, 0,
last_frame_glowmap_tex, GL_TEXTURE_2D, 0, 0, 0, 0,
win_x, win_y, 1);
}
else
{
glCopyImageSubData(glowmap_tex, GL_TEXTURE_2D, 0, 0, 0, 0,
last_frame_glowmap_tex2, GL_TEXTURE_2D, 0, 0, 0, 0,
win_x, win_y, 1);
}
x++;
glDeleteTextures(1, &upside_down_white_mask_tex);
glDeleteTextures(1, &upside_down_tex);
glDeleteTextures(1, &reflectance_tex);
glDeleteTextures(1, ®ular_tex);
glDeleteTextures(1, &glowmap_tex);
glDeleteTextures(1, &d_tex);
//const string s = "Paused. Press esc to continue!";
//const float font_scale = win_x / 1024.0f;
//size_t sentence_width = get_sentence_width(font_scale, mimgs, s);
//size_t window_width = win_x;
//size_t window_height = win_y;
//ortho_text.use_program();
//print_sentence(font_scale, mimgs, ortho_text.get_program(), win_x, win_y, window_width / 2 - sentence_width / 2, window_height / 3, s);
}