add jpg library, export as jpg, export animation frames, add pressure support on mac
This commit is contained in:
@@ -599,9 +599,12 @@ void ui::Canvas::export_equirectangular(std::string data_path)
|
||||
auto latlong_data = std::make_unique<uint8_t[]>(m_latlong.bytes());
|
||||
m_latlong.readTextureData(latlong_data.get());
|
||||
static char name[128];
|
||||
sprintf(name, "%s/latlong.png", data_path.c_str());
|
||||
sprintf(name, "%s/latlong.jpg", data_path.c_str());
|
||||
LOG("writing %s", name);
|
||||
int ret = stbi_write_png(name, m_latlong.getWidth(), m_latlong.getHeight(), 4, latlong_data.get(), m_latlong.stride());
|
||||
jpge::params params;
|
||||
params.m_quality = 100;
|
||||
bool saved = jpge::compress_image_to_jpeg_file(name, m_latlong.getWidth(), m_latlong.getHeight(), 4, latlong_data.get(), params);
|
||||
//int ret = stbi_write_png(name, m_latlong.getWidth(), m_latlong.getHeight(), 4, latlong_data.get(), m_latlong.stride());
|
||||
}
|
||||
|
||||
glDeleteTextures(1, &cube_id);
|
||||
@@ -626,7 +629,6 @@ void ui::Canvas::export_anim(std::string data_path)
|
||||
// prepare common states
|
||||
glViewport(0, 0, m_width, m_height);
|
||||
glDisable(GL_BLEND);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
RTT m_latlong;
|
||||
m_latlong.create(m_width * 4, m_height * 2); // NOTE: w and h must be equal to make sense
|
||||
@@ -646,19 +648,58 @@ void ui::Canvas::export_anim(std::string data_path)
|
||||
};
|
||||
for (auto layer_index : m_order)
|
||||
{
|
||||
glViewport(0, 0, m_width, m_height);
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
m_layers[layer_index].m_rtt[i].bindFramebuffer();
|
||||
m_tmp[i].bindFramebuffer();
|
||||
m_tmp[i].clear({ 1, 1, 1, 1 });
|
||||
|
||||
ui::ShaderManager::use(kShader::Checkerboard);
|
||||
ui::ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-.5f, .5f, -.5f, .5f, -1.f, 1.f));
|
||||
m_plane.draw_fill();
|
||||
|
||||
// copy to tmp2 for layer blending
|
||||
glActiveTexture(GL_TEXTURE0); // TODO: maybe remove this line
|
||||
m_tex2[i].bind();
|
||||
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, m_width, m_height);
|
||||
m_tex2[i].unbind();
|
||||
|
||||
m_layers[layer_index].m_rtt[i].bindTexture();
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
m_tex2[i].bind();
|
||||
m_sampler.bind(0);
|
||||
m_sampler_bg.bind(1);
|
||||
ShaderManager::use(ui::kShader::StrokeLayer);
|
||||
ShaderManager::u_int(kShaderUniform::TexBG, 1);
|
||||
ShaderManager::u_float(kShaderUniform::Alpha, 1);
|
||||
ShaderManager::u_int(kShaderUniform::Tex, 0);
|
||||
ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-.5f, .5f, -.5f, .5f, -1.f, 1.f));
|
||||
m_plane.draw_fill();
|
||||
m_sampler.unbind();
|
||||
m_sampler_bg.unbind();
|
||||
m_tex2[i].unbind();
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
m_layers[layer_index].m_rtt[i].unbindTexture();
|
||||
|
||||
// copy result to cubemap
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, cube_id);
|
||||
glCopyTexImage2D(faces[i], 0, GL_RGBA8, 0, 0, m_width, m_height, 0);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
|
||||
m_layers[layer_index].m_rtt[i].unbindFramebuffer();
|
||||
|
||||
m_tmp[i].unbindFramebuffer();
|
||||
|
||||
// m_layers[layer_index].m_rtt[i].bindFramebuffer();
|
||||
// // copy result to cubemap
|
||||
// glBindTexture(GL_TEXTURE_CUBE_MAP, cube_id);
|
||||
// glCopyTexImage2D(faces[i], 0, GL_RGBA8, 0, 0, m_width, m_height, 0);
|
||||
// glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
|
||||
// m_layers[layer_index].m_rtt[i].unbindFramebuffer();
|
||||
}
|
||||
|
||||
glViewport(0, 0, m_latlong.getWidth(), m_latlong.getHeight());
|
||||
m_latlong.clear({ 1, 1, 1, 1 });
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
m_latlong.bindFramebuffer();
|
||||
m_latlong.clear({ 1, 1, 1, 1 });
|
||||
ui::ShaderManager::use(kShader::Equirect);
|
||||
ui::ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-.5f, .5f, -.5f, .5f, -1.f, 1.f));
|
||||
ui::ShaderManager::u_int(kShaderUniform::Tex, 0);
|
||||
@@ -672,9 +713,12 @@ void ui::Canvas::export_anim(std::string data_path)
|
||||
auto latlong_data = std::make_unique<uint8_t[]>(m_latlong.bytes());
|
||||
m_latlong.readTextureData(latlong_data.get());
|
||||
static char name[128];
|
||||
sprintf(name, "%s/latlong-frame%02d.png", data_path.c_str(), layer_index);
|
||||
sprintf(name, "%s/latlong-frame%02d.jpg", data_path.c_str(), layer_index);
|
||||
LOG("writing %s", name);
|
||||
int ret = stbi_write_png(name, m_latlong.getWidth(), m_latlong.getHeight(), 4, latlong_data.get(), m_latlong.stride());
|
||||
//int ret = stbi_write_png(name, m_latlong.getWidth(), m_latlong.getHeight(), 4, latlong_data.get(), m_latlong.stride());
|
||||
jpge::params params;
|
||||
params.m_quality = 100;
|
||||
bool saved = jpge::compress_image_to_jpeg_file(name, m_latlong.getWidth(), m_latlong.getHeight(), 4, latlong_data.get(), params);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user