I am trying to render into fbo and than write it to file, but sadly I only get botton half of image, … not sure what’s going on or what should be next steps.
void draw_the_thing()
{
const bool display = false;
gl::FboRef myFbo = gl::Fbo::create(1024, 1024);
myFbo->bindFramebuffer();
//<...drawing commands...>
//ci::gl::translate(0, -150);
ci::gl::clear();
ci::gl::color(0.1f, 0.9f, 0.1f);
//ci::gl::drawSolidRect(ci::Rectf(0.0f, 0, -1024.0f, height_fbo / 4), glm::vec2(-1.0, 1.0f), glm::vec2(-1.0f, 1.0f));
//ci::gl::drawSolidRect(ci::Rectf(0, 1024.0f * 0.25f, 1024.0f * 0.25f, 0));
//ci::gl::drawSolidRect()
//ci::gl::drawSolidRect(ci::Rectf(0, -1024.0f, 1024.0f * 0.25f, 1024.0f * 2.0f));
//ci::gl::drawLine(glm::vec2(0.0f, 0.0f), glm::vec2(1024.0f, 1024.0f));
ci::Rectf rect1 = ci::Rectf(0.0f, 100.0f, 500.0f, 200.0f);
ci::gl::drawSolidRect(rect1);
ci::Rectf rect2 = ci::Rectf(0.0f, 300.0f, 500.0f, 400.0f);
ci::gl::drawSolidRect(rect2);
ci::Rectf rect3 = ci::Rectf(0.0f, -300.0f, 500.0f, -400.0f);
ci::gl::drawSolidRect(rect3);
ci::Rectf rect4= ci::Rectf(0.0f, -400.0f, 500.0f, -300.0f);
ci::gl::drawSolidRect(rect4);
for (int i = 0; i < 100; i++)
{
float offset_x = 512.0f;
float offset_y = 100.0f;
float x1 = offset_x + 100.0f * sinf(i * 0.01f * 3.1415f * 2.0f);
float y1 = offset_y + 100.0f * cosf(i * 0.01f * 3.1415f * 2.0f);
float x2 = offset_x + 0.0f;
float y2 = offset_y + 0.0f;
ci::gl::drawLine(glm::vec2(x1, y1), glm::vec2(x2, y2));
}
for (int i = 0; i < 100; i++)
{
float offset_x = 512.0f;
float offset_y = 0.0f;
float x1 = offset_x + 100.0f * sinf(i * 0.01f * 3.1415f * 2.0f);
float y1 = offset_y + 100.0f * cosf(i * 0.01f * 3.1415f * 2.0f);
float x2 = offset_x + 0.0f;
float y2 = offset_y + 0.0f;
ci::gl::drawLine(glm::vec2(x1, y1), glm::vec2(x2, y2));
}
for (int i = 0; i < 100; i++)
{
float offset_x = 512.0f;
float offset_y = -100.0f;
float x1 = offset_x + 100.0f * sinf(i * 0.01f * 3.1415f * 2.0f);
float y1 = offset_y + 100.0f * cosf(i * 0.01f * 3.1415f * 2.0f);
float x2 = offset_x + 0.0f;
float y2 = offset_y + 0.0f;
ci::gl::drawLine(glm::vec2(x1, y1), glm::vec2(x2, y2));
}
ci::gl::drawLine(glm::vec2(0.0f, 0.0f), glm::vec2(1024.0f, 0.0f));
ci::gl::drawLine(glm::vec2(0.0f, 10.0f), glm::vec2(1024.0f * 2.0f, 10.0f));
myFbo->unbindFramebuffer();
//Display
if (display)
{
gl::draw(myFbo->getColorTexture());
}
std::filesystem::path path = "C:\\Users\\<the_user>\\Desktop\\test\\fbo_out.png";
static bool to_save = true;
if (to_save)
{
to_save = false;
ci::writeImage(path, myFbo->getColorTexture()->createSource());
}
}