#include <iostream>
#include "initialization.hpp"
#include "image_loader.hpp"
class ExamplePackedValue:public Initialization
{
public:
ExamplePackedValue(DemoRunner *runner, int argc, char **argv);
~ExamplePackedValue()
{}
virtual
void
draw_frame(void) override;
private:
};
ExamplePackedValue::
ExamplePackedValue(DemoRunner *runner, int argc, char **argv):
Initialization(runner, argc, argv)
{
ImageSourceSDL image_loader(argv[1]);
m_image = m_painter_engine_gl->image_atlas().create(image_loader.width(),
image_loader.height(),
image_loader);
}
void
ExamplePackedValue::
draw_frame(void)
{
m_surface_gl->viewport(vwp);
const unsigned int num_rects_x(8), num_rects_y(6);
unsigned int x, y;
float xpos, ypos;
float xpos_delta = window_dims.x() / static_cast<float>(num_rects_x);
float ypos_delta = window_dims.y() / static_cast<float>(num_rects_y);
float xpad = window_dims.x() / static_cast<float>(4 * num_rects_x);
float ypad = window_dims.x() / static_cast<float>(4 * num_rects_y);
0.5f * ypos_delta / image_size.y());
uint32_t time_ms;
time_ms = SDL_GetTicks() % 4000u;
for (y = 0, ypos = 0.0f; y < num_rects_y; ++y, ypos += ypos_delta)
{
for (x = 0, xpos = 0.0f; x < num_rects_x; ++x, xpos += xpos_delta)
{
m_painter->save();
m_painter->shear(shear.x(), shear.y());
m_painter->translate(image_size * 0.5f);
m_painter->rotate(
FASTUIDRAW_PI * static_cast<float>(time_ms) / 2000.0f);
m_painter->translate(-image_size * 0.5f);
m_painter->fill_rect(m_packed_brush,
.min_point(0.0f, 0.0f)
.max_point(image_size));
m_painter->restore();
}
}
fastuidraw_glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
fastuidraw_glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
m_surface_gl->blit_surface(GL_NEAREST);
}
int
main(int argc, char **argv)
{
DemoRunner demo_runner;
if (argc < 2)
{
std::cerr << "Usage: " << argv[0] << " image_file\n";
return -1;
}
return demo_runner.main<ExamplePackedValue>(argc, argv);
}